/* ============ Atelier IA — design tokens ============ */
:root{
  --navy-900:#0F2240; --navy-800:#16325C; --navy-700:#1E4278; --navy-100:#E6EDF7; --navy-50:#F2F6FB;
  --green-700:#17673F; --green-600:#1F7A4D; --green-100:#E3F3EA;
  --orange-700:#9A4A06; --orange-500:#E07B12; --orange-100:#FDF0E1;
  --red-700:#A61B1B; --red-100:#FBE7E7;
  --gray-900:#1B2430; --gray-700:#3D4756; --gray-600:#566070; --gray-400:#9AA3AF; --gray-200:#E3E7EC; --gray-100:#EEF1F4; --gray-50:#F7F8FA;
  --white:#fff;
  --radius:14px; --radius-sm:10px;
  --shadow-sm:0 1px 2px rgba(15,34,64,.06),0 1px 3px rgba(15,34,64,.08);
  --shadow-md:0 4px 16px rgba(15,34,64,.08);
  --font: system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  --header-h:64px; --bottom-h:64px;
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0;font-family:var(--font);font-size:16px;line-height:1.55;color:var(--gray-900);background:var(--gray-50)}
img,svg{display:block}
h1,h2,h3{line-height:1.25;margin:0 0 .4em;color:var(--navy-900)}
h1{font-size:clamp(1.5rem,2.6vw,2rem)} h2{font-size:1.25rem} h3{font-size:1.05rem}
p{margin:0 0 1em}
a{color:var(--navy-700)}
:focus-visible{outline:3px solid var(--orange-500);outline-offset:2px;border-radius:6px}
[tabindex="-1"]:focus{outline:none}
[hidden]{display:none!important}
.sr-only{position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}
.skip-link{position:absolute;left:12px;top:-60px;background:var(--navy-800);color:#fff;padding:10px 16px;border-radius:8px;z-index:100;text-decoration:none}
.skip-link:focus{top:12px}
@media (prefers-reduced-motion:reduce){*{animation:none!important;transition:none!important;scroll-behavior:auto!important}}

/* ============ Shell ============ */
.app-header{position:sticky;top:0;z-index:20;height:var(--header-h);background:var(--white);border-bottom:1px solid var(--gray-200);display:flex;align-items:center;gap:24px;padding:0 24px}
.brand{display:flex;align-items:center;gap:10px;font-weight:700;font-size:1.1rem;color:var(--navy-900);text-decoration:none}
.brand-logo{width:34px;height:34px;border-radius:9px}
.top-nav{display:flex;gap:4px;margin-left:12px}
.nav-link{display:flex;align-items:center;gap:8px;padding:8px 14px;border-radius:999px;color:var(--gray-700);text-decoration:none;font-weight:500}
.nav-link:hover{background:var(--gray-100)}
.nav-link[aria-current="page"]{background:var(--navy-100);color:var(--navy-800)}
.header-actions{margin-left:auto;display:flex;gap:8px;align-items:center}
.bottom-nav{display:none}
main{max-width:1180px;margin:0 auto;padding:28px 24px 48px;min-height:calc(100vh - var(--header-h))}
main:focus{outline:none}
.offline-banner{background:var(--orange-100);color:var(--orange-700);border-bottom:1px solid #F4D3AE;padding:8px 24px;font-size:.92rem;display:flex;gap:8px;align-items:center}
@media (max-width:820px){
  .top-nav{display:none}
  .app-header{padding:0 16px;gap:12px}
  main{padding:20px 16px calc(var(--bottom-h) + 32px)}
  .bottom-nav{display:flex;position:fixed;bottom:0;left:0;right:0;height:calc(var(--bottom-h) + env(safe-area-inset-bottom));padding-bottom:env(safe-area-inset-bottom);background:var(--white);border-top:1px solid var(--gray-200);z-index:30}
  .bottom-nav a{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;font-size:.75rem;color:var(--gray-600);text-decoration:none;font-weight:500}
  .bottom-nav a[aria-current="page"]{color:var(--navy-800)}
  .bottom-nav a[aria-current="page"] svg{stroke:var(--navy-800)}
}

/* ============ Buttons ============ */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:44px;padding:10px 18px;border-radius:var(--radius-sm);border:1px solid transparent;font:inherit;font-weight:600;cursor:pointer;text-decoration:none;transition:background .15s,box-shadow .15s,transform .05s;white-space:nowrap}
.btn:active{transform:translateY(1px)}
.btn[disabled]{opacity:.5;cursor:not-allowed}
.btn-primary{background:var(--navy-800);color:#fff}
.btn-primary:hover:not([disabled]){background:var(--navy-900)}
.btn-success{background:var(--green-600);color:#fff}
.btn-success:hover:not([disabled]){background:var(--green-700)}
.btn-secondary{background:var(--white);color:var(--navy-800);border-color:var(--gray-200)}
.btn-secondary:hover:not([disabled]){background:var(--gray-100)}
.btn-ghost{background:transparent;color:var(--gray-700)}
.btn-ghost:hover{background:var(--gray-100)}
.btn-danger{background:var(--white);color:var(--red-700);border-color:#F1C4C4}
.btn-danger:hover{background:var(--red-100)}
.btn-sm{min-height:36px;padding:6px 12px;font-size:.9rem}
.btn-lg{min-height:52px;padding:12px 24px;font-size:1.05rem}
.icon-btn{display:inline-flex;align-items:center;justify-content:center;width:40px;height:40px;border-radius:10px;border:none;background:transparent;color:var(--gray-700);cursor:pointer}
.icon-btn:hover{background:var(--gray-100)}

/* ============ Generic ============ */
.card{background:var(--white);border:1px solid var(--gray-200);border-radius:var(--radius);box-shadow:var(--shadow-sm)}
.card-body{padding:20px}
.muted{color:var(--gray-600)}
.small{font-size:.9rem}
.stack{display:flex;flex-direction:column;gap:16px}
.row{display:flex;gap:12px;align-items:center;flex-wrap:wrap}
.spacer{flex:1}
.section{margin-top:40px}
.section-head{display:flex;align-items:flex-end;justify-content:space-between;gap:16px;margin-bottom:16px;flex-wrap:wrap}
.section-head p{margin:0}
.badge{display:inline-flex;align-items:center;gap:6px;padding:3px 10px;border-radius:999px;font-size:.8rem;font-weight:600;background:var(--gray-100);color:var(--gray-700)}
.badge-green{background:var(--green-100);color:var(--green-700)}
.badge-orange{background:var(--orange-100);color:var(--orange-700)}
.badge-red{background:var(--red-100);color:var(--red-700)}
.badge-navy{background:var(--navy-100);color:var(--navy-800)}
.dot{width:8px;height:8px;border-radius:50%;background:currentColor}
.notice{display:flex;gap:12px;align-items:flex-start;padding:14px 16px;border-radius:var(--radius-sm);font-size:.93rem}
.notice svg{flex:none;margin-top:2px}
.notice-info{background:var(--navy-50);color:var(--navy-800);border:1px solid var(--navy-100)}
.notice-warn{background:var(--orange-100);color:var(--orange-700);border:1px solid #F4D3AE}
.notice-ok{background:var(--green-100);color:var(--green-700);border:1px solid #BFE3CE}
.empty{text-align:center;padding:40px 20px;border:2px dashed var(--gray-200);border-radius:var(--radius);color:var(--gray-600);background:var(--white)}

/* ============ Home ============ */
.hero{display:grid;grid-template-columns:1.3fr 1fr;gap:32px;align-items:center;background:var(--navy-800);color:#fff;border-radius:20px;padding:36px 40px}
.hero h1{color:#fff;font-size:clamp(1.6rem,3vw,2.3rem)}
.hero p{color:#D6E0EE;font-size:1.08rem;max-width:56ch}
.hero .btn-secondary{border-color:transparent}
.hero-steps{list-style:none;margin:0;padding:0;display:grid;gap:10px}
.hero-steps li{display:flex;gap:12px;align-items:center;background:rgba(255,255,255,.08);padding:12px 14px;border-radius:12px}
.hero-steps .num{width:30px;height:30px;border-radius:50%;background:#fff;color:var(--navy-800);display:grid;place-items:center;font-weight:700;flex:none}
@media (max-width:820px){.hero{grid-template-columns:1fr;padding:24px}}
.tabs{display:inline-flex;background:var(--gray-100);padding:4px;border-radius:12px;gap:4px}
.tab{border:none;background:transparent;padding:8px 16px;border-radius:9px;font:inherit;font-weight:600;color:var(--gray-700);cursor:pointer;display:flex;gap:8px;align-items:center;min-height:40px}
.tab[aria-selected="true"]{background:var(--white);color:var(--navy-800);box-shadow:var(--shadow-sm)}
.grid-cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:18px}
.tpl-card{display:flex;flex-direction:column;padding:22px;gap:12px;transition:box-shadow .15s,border-color .15s}
.tpl-card:hover{box-shadow:var(--shadow-md);border-color:var(--navy-100)}
.tpl-icon{flex:none;width:52px;height:52px;border-radius:14px;display:grid;place-items:center;background:var(--navy-50);color:var(--navy-800)}
.tpl-card h3{margin:0}
.tpl-card p{margin:0;color:var(--gray-600);font-size:.95rem}
.tpl-card ul{margin:0;padding-left:18px;color:var(--gray-700);font-size:.9rem}
.tpl-card .btn{margin-top:auto}
.agent-card{padding:18px;display:flex;flex-direction:column;gap:12px}
.agent-card-head{display:flex;gap:12px;align-items:center}
.agent-card-head .tpl-icon{width:44px;height:44px}
.agent-card h3{margin:0;font-size:1rem}
.agent-meta{display:flex;gap:8px;flex-wrap:wrap;align-items:center;font-size:.85rem;color:var(--gray-600)}

/* ============ Wizard ============ */
.wizard{max-width:820px;margin:0 auto}
.stepper{list-style:none;display:flex;gap:8px;padding:0;margin:20px 0 28px}
.stepper li{flex:1;display:flex;flex-direction:column;gap:8px;font-size:.88rem;font-weight:600;color:var(--gray-600)}
.stepper .bar{height:6px;border-radius:999px;background:var(--gray-200);overflow:hidden}
.stepper .bar span{display:block;height:100%;width:0;background:var(--green-600);transition:width .3s}
.stepper li.done .bar span,.stepper li.current .bar span{width:100%}
.stepper li.current .bar span{background:var(--navy-800)}
.stepper li.current{color:var(--navy-800)}
.stepper li.done{color:var(--green-700)}
.field{display:flex;flex-direction:column;gap:6px}
.field label,.field legend{font-weight:600;color:var(--gray-900)}
.field .hint{font-size:.88rem;color:var(--gray-600)}
.input,textarea.input,select.input{font:inherit;padding:12px 14px;border:1.5px solid var(--gray-200);border-radius:var(--radius-sm);background:var(--white);color:var(--gray-900);min-height:48px;width:100%}
textarea.input{min-height:110px;resize:vertical}
.input:focus{border-color:var(--navy-700);outline:3px solid var(--navy-100);outline-offset:0}
.input[aria-invalid="true"]{border-color:var(--red-700)}
.error-text{color:var(--red-700);font-size:.88rem}
fieldset{border:none;padding:0;margin:0}
.choice-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:10px;margin-top:6px}
.choice{position:relative}
.choice input{position:absolute;opacity:0;inset:0;cursor:pointer}
.choice span{display:flex;flex-direction:column;gap:2px;padding:14px;border:1.5px solid var(--gray-200);border-radius:var(--radius-sm);background:var(--white);height:100%}
.choice span b{color:var(--gray-900)}
.choice span small{color:var(--gray-600)}
.choice input:checked+span{border-color:var(--navy-800);background:var(--navy-50);box-shadow:inset 0 0 0 1px var(--navy-800)}
.choice input:focus-visible+span{outline:3px solid var(--orange-500);outline-offset:2px}
.dropzone{border:2px dashed var(--gray-400);border-radius:var(--radius);padding:28px;text-align:center;background:var(--white);transition:background .15s,border-color .15s}
.dropzone.drag{background:var(--navy-50);border-color:var(--navy-700)}
.doc-list{list-style:none;padding:0;margin:12px 0 0;display:flex;flex-direction:column;gap:8px}
.doc-list li{display:flex;align-items:center;gap:12px;padding:10px 12px;border:1px solid var(--gray-200);border-radius:var(--radius-sm);background:var(--white)}
.doc-list .doc-name{font-weight:600;word-break:break-word}
.wizard-footer{display:flex;justify-content:space-between;gap:12px;margin-top:28px;padding-top:20px;border-top:1px solid var(--gray-200)}
.summary dl{display:grid;grid-template-columns:200px 1fr;gap:10px 16px;margin:0}
.summary dt{color:var(--gray-600)} .summary dd{margin:0;font-weight:500;white-space:pre-wrap}
@media (max-width:600px){.summary dl{grid-template-columns:1fr}.summary dd{margin-bottom:8px}.wizard-footer .btn{flex:1}}
.building{text-align:center;padding:48px 20px}
.building ol{list-style:none;padding:0;margin:24px auto 0;max-width:360px;text-align:left;display:grid;gap:12px}
.building li{display:flex;gap:10px;align-items:center;color:var(--gray-600)}
.building li.done{color:var(--green-700)} .building li.active{color:var(--navy-800);font-weight:600}
.spinner{width:20px;height:20px;border-radius:50%;border:3px solid var(--navy-100);border-top-color:var(--navy-800);animation:spin .8s linear infinite;flex:none}
@keyframes spin{to{transform:rotate(360deg)}}
.progress{height:10px;border-radius:999px;background:var(--gray-200);overflow:hidden;max-width:360px;margin:16px auto 0}
.progress span{display:block;height:100%;background:var(--green-600);transition:width .4s}

/* ============ Chat ============ */
.chat-layout{display:grid;grid-template-columns:280px 1fr;gap:20px;height:calc(100vh - var(--header-h) - 56px)}
.chat-side{display:flex;flex-direction:column;overflow:hidden}
.chat-side .card-body{display:flex;flex-direction:column;gap:12px;overflow:auto}
.conv-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:4px}
.conv-list a{display:block;padding:10px 12px;border-radius:10px;text-decoration:none;color:var(--gray-700);font-size:.93rem}
.conv-list a:hover{background:var(--gray-100)}
.conv-list a[aria-current="true"]{background:var(--navy-100);color:var(--navy-900);font-weight:600}
.conv-list small{display:block;color:var(--gray-600);font-weight:400;font-size:.78rem}
.chat-main{display:flex;flex-direction:column;overflow:hidden}
.chat-head{display:flex;align-items:center;gap:12px;padding:14px 18px;border-bottom:1px solid var(--gray-200);flex-wrap:wrap}
.chat-head .tpl-icon{width:42px;height:42px}
.chat-head h1{font-size:1.1rem;margin:0}
.chat-scroll{flex:1;overflow:auto;padding:20px;display:flex;flex-direction:column;gap:14px;background:var(--gray-50)}
.msg{max-width:min(720px,88%);padding:12px 16px;border-radius:16px;box-shadow:var(--shadow-sm);word-wrap:break-word}
.msg p:last-child,.msg ul:last-child,.msg ol:last-child{margin-bottom:0}
.msg ul,.msg ol{padding-left:20px;margin:0 0 .8em}
.msg-user{align-self:flex-end;background:var(--navy-800);color:#fff;border-bottom-right-radius:4px}
.msg-agent{align-self:flex-start;background:var(--white);border:1px solid var(--gray-200);border-bottom-left-radius:4px}
.msg-agent .doc{background:var(--gray-50);border:1px solid var(--gray-200);border-radius:10px;padding:14px;font-family:Georgia,"Times New Roman",serif;white-space:pre-wrap;font-size:.95rem;margin:8px 0}
.msg-merchant{border-left:3px solid var(--green-600)}
.msg-from{display:flex;align-items:center;gap:4px;font-size:.8rem;font-weight:600;color:var(--green-700);margin-bottom:4px}
.pub-bar{display:flex;align-items:center;gap:8px;padding:8px 16px;background:var(--navy-50);border-top:1px solid var(--gray-200);font-size:.875rem;color:var(--gray-700);flex-wrap:wrap}
.msg-actions{display:flex;gap:6px;margin-top:8px;flex-wrap:wrap}
.review-note{display:flex;gap:8px;align-items:flex-start;margin-top:10px;padding:10px 12px;border-radius:10px;background:var(--orange-100);color:var(--orange-700);font-size:.86rem;font-weight:500}
.typing{display:flex;gap:4px;padding:16px}
.typing i{width:8px;height:8px;border-radius:50%;background:var(--gray-400);animation:blink 1.2s infinite}
.typing i:nth-child(2){animation-delay:.2s}.typing i:nth-child(3){animation-delay:.4s}
@keyframes blink{0%,80%,100%{opacity:.3}40%{opacity:1}}
.suggestions{display:flex;flex-direction:column;gap:10px;align-items:center;text-align:center;margin:auto 0;padding:20px}
.suggestions .chips{display:flex;flex-wrap:wrap;gap:8px;justify-content:center;max-width:720px}
.chip{border:1.5px solid var(--navy-100);background:var(--white);color:var(--navy-800);padding:10px 14px;border-radius:999px;font:inherit;font-size:.92rem;cursor:pointer;text-align:left}
.chip:hover{background:var(--navy-50);border-color:var(--navy-700)}
.composer{display:flex;gap:10px;padding:14px;border-top:1px solid var(--gray-200);background:var(--white);align-items:flex-end}
.composer textarea{flex:1;min-height:48px;max-height:180px;resize:none}
.privacy-line{font-size:.78rem;color:var(--gray-600);padding:0 16px 10px;background:var(--white);display:flex;gap:6px;align-items:center}
@media (max-width:900px){
  .chat-layout{grid-template-columns:1fr;height:calc(100dvh - var(--header-h) - var(--bottom-h) - 16px)}
  .chat-side{display:none}
  .chat-side.open{display:flex;position:fixed;inset:var(--header-h) 0 var(--bottom-h) 0;z-index:25;border-radius:0}
}

/* ============ Dashboard ============ */
.stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:14px}
.stat{padding:18px}
.stat b{display:block;font-size:1.8rem;color:var(--navy-900);line-height:1.1}
.stat span{color:var(--gray-600);font-size:.9rem}
.table{width:100%;border-collapse:collapse}
.table th{text-align:left;font-size:.82rem;text-transform:uppercase;letter-spacing:.03em;color:var(--gray-600);padding:10px 14px;border-bottom:1px solid var(--gray-200)}
.table td{padding:14px;border-bottom:1px solid var(--gray-100);vertical-align:middle}
.table tr:last-child td{border-bottom:none}
.table .agent-cell{display:flex;gap:12px;align-items:center}
.table .agent-cell .tpl-icon{width:38px;height:38px;border-radius:10px}
@media (max-width:720px){
  .table thead{display:none}
  .table tr{display:grid;grid-template-columns:1fr auto;padding:12px 0;border-bottom:1px solid var(--gray-100)}
  .table td{border:none;padding:4px 14px}
  .table td.actions{grid-column:1/-1}
}
.dash-grid{display:grid;grid-template-columns:1.4fr 1fr;gap:20px;align-items:start}
@media (max-width:980px){.dash-grid{grid-template-columns:1fr}}

/* ============ Calendar ============ */
.cal-head{display:flex;align-items:center;gap:8px;margin-bottom:12px}
.cal-head h3{margin:0;flex:1;text-transform:capitalize}
.cal{display:grid;grid-template-columns:repeat(7,1fr);gap:4px}
.cal .dow{font-size:.75rem;font-weight:700;color:var(--gray-600);text-align:center;padding:4px 0;text-transform:uppercase}
.cal .day{aspect-ratio:1/1;min-height:38px;border-radius:10px;border:1px solid transparent;background:var(--gray-50);font:inherit;font-size:.9rem;color:var(--gray-700);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;cursor:pointer;padding:2px}
.cal .day.out{opacity:.4}
.cal .day.today{border-color:var(--navy-700);font-weight:700;color:var(--navy-900)}
.cal .day.has{background:var(--orange-100);color:var(--orange-700);font-weight:700}
.cal .day.has.ok{background:var(--navy-100);color:var(--navy-800)}
.cal .day[aria-pressed="true"]{outline:2px solid var(--navy-800)}
.cal .day .dots{display:flex;gap:2px}
.cal .day .dots i{width:5px;height:5px;border-radius:50%;background:currentColor}
.deadline-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px}
.deadline{display:flex;gap:14px;padding:12px 14px;border:1px solid var(--gray-200);border-left:4px solid var(--navy-700);border-radius:10px;background:var(--white)}
.deadline.soon{border-left-color:var(--orange-500)}
.deadline.late{border-left-color:var(--red-700)}
.deadline.done{opacity:.6;border-left-color:var(--green-600)}
.deadline .date{flex:none;width:56px;text-align:center;line-height:1.1}
.deadline .date b{display:block;font-size:1.4rem;color:var(--navy-900)}
.deadline .date span{font-size:.75rem;text-transform:uppercase;color:var(--gray-600)}
.deadline h4{margin:0 0 2px;font-size:.98rem}
.deadline p{margin:0;font-size:.85rem;color:var(--gray-600)}

/* ============ Toast / dialog ============ */
.toast-zone{position:fixed;bottom:24px;left:50%;transform:translateX(-50%);z-index:50;display:flex;flex-direction:column;gap:8px;align-items:center}
@media (max-width:820px){.toast-zone{bottom:calc(var(--bottom-h) + 16px)}}
.toast{background:var(--gray-900);color:#fff;padding:12px 18px;border-radius:12px;box-shadow:var(--shadow-md);font-size:.93rem;animation:up .25s}
@keyframes up{from{opacity:0;transform:translateY(8px)}}
dialog{border:none;border-radius:var(--radius);padding:0;max-width:520px;width:calc(100% - 32px);box-shadow:0 20px 60px rgba(0,0,0,.25)}
dialog::backdrop{background:rgba(15,34,64,.45)}
dialog .card-body{padding:24px}
@media (max-width:600px){.send-label{display:none}.chat-head .btn-sm{padding:6px 10px}}

.cal-split{display:grid;grid-template-columns:minmax(280px,380px) 1fr;gap:24px;align-items:start}
@media (max-width:820px){.cal-split{grid-template-columns:1fr}}

.brand span{white-space:nowrap}
@media (max-width:820px){
  .hide-sm{display:none}
  .header-actions .btn{min-width:40px;padding:6px 10px}
  .bottom-nav a.nav-link{padding:4px 2px;border-radius:0;background:none;white-space:nowrap;font-size:.72rem}
  .chat-head{padding:10px 12px;gap:8px;flex-wrap:nowrap}
  .chat-head h1{font-size:1rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .chat-head .tpl-icon{width:36px;height:36px}
  .chat-sub{display:none}
  .chat-scroll{padding:12px}
  .msg{max-width:94%}
  main:has(.chat-layout){padding-left:8px;padding-right:8px;padding-top:8px}
  .offline-banner{padding:8px 16px;font-size:.85rem}
}

.logged-out .auth-only,.logged-out .top-nav,.logged-out .bottom-nav{display:none!important}
.logged-out main{padding-bottom:24px}
