/* =============================================================================
   SEAL — AI 경리 · 혁신법 연구비
   App styling layered on top of Montage (Wanted) tokens (lib/montage.css).
   Aesthetic: flat · minimal · 여백 충분 · 친절. No big shadows / gradients.
   ========================================================================== */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-family-wanted-sans);
  background: var(--semantic-background-normal-alternative);
  color: var(--semantic-label-normal);
  -webkit-font-smoothing: antialiased;
}
:root { --nav-h: 60px; --rail-w: 248px; --maxw: 1080px; }

.tnum { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--atomic-blue-90); }

/* ---------- App layout shell ------------------------------------------- */
.app { min-height: 100vh; }

.topnav {
  position: sticky; top: 0; z-index: 50;
  height: var(--nav-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--semantic-line-normal-neutral);
}
.brand { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--semantic-primary-normal);
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 2px 8px -2px rgba(0,102,255,0.5);
}
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.brand-name b { color: var(--semantic-primary-normal); }

.proj-select {
  display: flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 12px 0 14px;
  border: 1px solid var(--semantic-line-normal-normal);
  border-radius: 10px; background: #fff;
  font-size: 14px; font-weight: 600; cursor: pointer;
  color: var(--semantic-label-neutral);
  max-width: 360px;
}
.proj-select:hover { background: var(--semantic-fill-alternative); }
.proj-select .ptitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--semantic-label-normal); }
.proj-select .pmeta { color: var(--semantic-label-alternative); font-weight: 500; font-size: 12px; flex-shrink: 0; }

.nav-spacer { flex: 1; }
.nav-chat-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  height: 38px; padding: 0 16px;
  border-radius: var(--radius-pill);
  background: var(--semantic-primary-normal); color: #fff;
  font-size: 14px; font-weight: 600; cursor: pointer; border: none; white-space: nowrap;
  transition: background .15s;
}
.nav-chat-toggle:hover { background: var(--semantic-primary-strong); }
.nav-chat-toggle.on { background: var(--atomic-blue-40); }

.shell { display: flex; align-items: flex-start; }

/* ---------- Left rail --------------------------------------------------- */
.rail {
  position: sticky; top: var(--nav-h);
  width: var(--rail-w); flex-shrink: 0;
  height: calc(100vh - var(--nav-h));
  overflow-y: auto;
  padding: 20px 14px 32px;
  border-right: 1px solid var(--semantic-line-normal-neutral);
  background: #fff;
}
.rail-group { margin-bottom: 22px; }
.rail-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--semantic-label-assistive); text-transform: uppercase;
  padding: 0 12px 8px;
}
.rail-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 9px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  color: var(--semantic-label-neutral);
  margin-bottom: 2px; position: relative; white-space: nowrap;
  transition: background .12s, color .12s;
}
.rail-item .ico { flex-shrink: 0; color: var(--semantic-label-alternative); display: grid; place-items: center; }
.rail-item:hover { background: var(--semantic-fill-alternative); }
.rail-item.active { background: var(--semantic-primary-soft, var(--atomic-blue-95)); color: var(--semantic-primary-normal); }
.rail-item.active .ico { color: var(--semantic-primary-normal); }
.rail-item .num { margin-left: auto; font-size: 11px; color: var(--semantic-label-assistive); font-weight: 600; flex-shrink: 0; }
.rail-item .pip { margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--semantic-status-negative); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center; }

/* ---------- Main column ------------------------------------------------- */
.main { flex: 1; min-width: 0; }
.page { max-width: var(--maxw); margin: 0 auto; padding: 36px 40px 96px; }
.page-head { margin-bottom: 28px; }
.page-eyebrow { font-size: 13px; font-weight: 700; color: var(--semantic-primary-normal); margin-bottom: 8px; letter-spacing: 0.01em; }
.page-title { font-size: 28px; font-weight: 700; letter-spacing: -0.025em; margin: 0; line-height: 1.25; text-wrap: balance; }
.page-sub { margin: 10px 0 0; font-size: 15px; color: var(--semantic-label-alternative); line-height: 1.55; max-width: 640px; }

/* ---------- Cards ------------------------------------------------------- */
.card {
  background: #fff; border: 1px solid var(--semantic-line-normal-neutral);
  border-radius: var(--radius-16); padding: 24px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.card-sub { font-size: 13px; color: var(--semantic-label-alternative); margin: 4px 0 0; }
.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; }
.grid { display: grid; }

/* ---------- Buttons ----------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; cursor: pointer; white-space: nowrap;
  font-weight: 600; border-radius: var(--radius-10);
  transition: background .14s, box-shadow .14s, transform .04s;
  font-family: inherit;
}
.btn:active { transform: translateY(0.5px); }
.btn-lg { height: 48px; padding: 0 24px; font-size: 16px; border-radius: var(--radius-12); }
.btn-md { height: 42px; padding: 0 18px; font-size: 15px; }
.btn-sm { height: 34px; padding: 0 13px; font-size: 13px; border-radius: var(--radius-8); }
.btn-primary { background: var(--semantic-primary-normal); color: #fff; }
.btn-primary:hover { background: var(--semantic-primary-strong); }
.btn-soft { background: var(--atomic-blue-95); color: var(--semantic-primary-normal); }
.btn-soft:hover { background: var(--atomic-blue-90); }
.btn-ghost { background: var(--semantic-fill-normal); color: var(--semantic-label-neutral); }
.btn-ghost:hover { background: var(--semantic-fill-strong); }
.btn-outline { background: #fff; color: var(--semantic-label-normal); box-shadow: inset 0 0 0 1px var(--semantic-line-normal-normal); }
.btn-outline:hover { background: var(--semantic-fill-alternative); }
.btn-block { width: 100%; }
.btn[disabled] { background: var(--semantic-interaction-disable); color: var(--semantic-label-assistive); cursor: default; box-shadow: none; }

/* ---------- Badges / chips --------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 24px; padding: 0 9px; border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap;
}
.badge-blue   { background: var(--atomic-blue-95);  color: var(--semantic-primary-normal); }
.badge-green  { background: var(--atomic-green-95);  color: var(--atomic-green-40); }
.badge-orange { background: var(--atomic-orange-95); color: var(--atomic-orange-39); }
.badge-red    { background: var(--atomic-red-95);    color: var(--atomic-red-40); }
.badge-gray   { background: var(--semantic-fill-normal); color: var(--semantic-label-alternative); }
.badge-violet { background: #efeafe; color: var(--atomic-violet-45); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px; border-radius: var(--radius-pill);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  background: var(--semantic-fill-normal); color: var(--semantic-label-neutral);
  border: 1px solid transparent;
}
.chip.need { background: var(--atomic-blue-95); color: var(--semantic-primary-normal); }

/* ---------- KPI --------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.kpi { background: #fff; border: 1px solid var(--semantic-line-normal-neutral); border-radius: var(--radius-16); padding: 22px 24px; }
.kpi-label { font-size: 13px; font-weight: 600; color: var(--semantic-label-alternative); margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.kpi-value .won { font-size: 17px; font-weight: 600; color: var(--semantic-label-alternative); margin-left: 2px; }
.kpi-foot { margin-top: 10px; font-size: 12.5px; color: var(--semantic-label-alternative); }
.kpi.accent { background: var(--atomic-blue-99); border-color: var(--atomic-blue-90); }
.kpi.accent .kpi-value { color: var(--semantic-primary-normal); }

/* ---------- Budget bars ------------------------------------------------- */
.barlist { display: flex; flex-direction: column; gap: 18px; }
.barrow.muted { opacity: 0.66; }
.barrow-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.barrow-name { font-size: 14.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; min-width: 0; }
.barrow-group { font-size: 12px; font-weight: 600; color: var(--semantic-label-assistive); }
.barrow-figs { font-size: 13px; color: var(--semantic-label-alternative); font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.barrow-figs b { color: var(--semantic-label-normal); }
.bartrack { height: 10px; border-radius: 6px; background: var(--semantic-fill-strong); overflow: hidden; }
.barfill { height: 100%; border-radius: 6px; background: var(--semantic-primary-normal); transition: width .6s cubic-bezier(.4,0,.2,1); }
.barfill.near { background: var(--semantic-status-cautionary); }
.barfill.over { background: var(--semantic-status-negative); }
.barrow-foot { margin-top: 7px; font-size: 12.5px; color: var(--semantic-label-alternative); }
.barrow-foot b { color: var(--semantic-label-normal); font-weight: 700; }

/* ---------- Tables ------------------------------------------------------ */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; font-weight: 700; color: var(--semantic-label-alternative);
  padding: 12px 16px; border-bottom: 1px solid var(--semantic-line-normal-normal); background: var(--semantic-fill-alternative); }
.tbl td { padding: 14px 16px; border-bottom: 1px solid var(--semantic-line-normal-alternative); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr.muted td { color: var(--semantic-label-alternative); }

/* ---------- List rows --------------------------------------------------- */
.lrow { display: flex; align-items: center; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--semantic-line-normal-alternative); }
.lrow:last-child { border-bottom: none; }
.lrow-icon { width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0; display: grid; place-items: center;
  background: var(--semantic-fill-normal); color: var(--semantic-label-neutral); }
.lrow-icon.blue { background: var(--atomic-blue-95); color: var(--semantic-primary-normal); }
.lrow-body { flex: 1; min-width: 0; }
.lrow-title { font-size: 14.5px; font-weight: 600; }
.lrow-meta { font-size: 12.5px; color: var(--semantic-label-alternative); margin-top: 3px; }
.lrow-right { text-align: right; flex-shrink: 0; }

/* ---------- Accordion --------------------------------------------------- */
.acc-item { border: 1px solid var(--semantic-line-normal-neutral); border-radius: var(--radius-12); margin-bottom: 10px; overflow: hidden; background: #fff; }
.acc-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; cursor: pointer; }
.acc-head:hover { background: var(--semantic-fill-alternative); }
.acc-head .acc-t { font-size: 15px; font-weight: 700; flex: 1; }
.acc-body { padding: 0 18px 18px; font-size: 14px; color: var(--semantic-label-neutral); line-height: 1.65; }
.acc-chev { transition: transform .2s; color: var(--semantic-label-alternative); }
.acc-item.open .acc-chev { transform: rotate(180deg); }

/* ---------- Section header ---------------------------------------------- */
.sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sec-title { font-size: 18px; font-weight: 700; letter-spacing: -0.015em; white-space: nowrap; }
.sec-link { font-size: 13px; font-weight: 600; color: var(--semantic-primary-normal); cursor: pointer; display: inline-flex; align-items: center; gap: 3px; }

/* ---------- Empty / skeleton ------------------------------------------- */
.empty { text-align: center; padding: 56px 24px; color: var(--semantic-label-alternative); }
.empty-ico { width: 56px; height: 56px; border-radius: 16px; background: var(--semantic-fill-normal); display: grid; place-items: center; margin: 0 auto 16px; color: var(--semantic-label-assistive); }
.empty h3 { font-size: 16px; font-weight: 700; color: var(--semantic-label-normal); margin: 0 0 6px; }
.empty p { font-size: 14px; margin: 0; }

.skel { background: linear-gradient(90deg, var(--semantic-fill-alternative) 25%, var(--semantic-fill-normal) 37%, var(--semantic-fill-alternative) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------- Toast ------------------------------------------------------- */
.toast-wrap { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--semantic-inverse-background); color: #fff;
  padding: 13px 18px; border-radius: var(--radius-12); font-size: 14px; font-weight: 600; box-shadow: var(--semantic-shadow-large);
  animation: toastin .26s cubic-bezier(.2,.8,.2,1); }
.toast .tc { display: grid; place-items: center; }
.toast.ok .tc { color: var(--atomic-green-60); }
@keyframes toastin { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Misc -------------------------------------------------------- */
.divline { height: 1px; background: var(--semantic-line-normal-alternative); margin: 20px 0; }
.muted-text { color: var(--semantic-label-alternative); }
.mono-won { font-variant-numeric: tabular-nums; font-weight: 700; }
.verdict { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; }

/* fade-in for page transitions — TRANSFORM ONLY (never hide via opacity, so
   content stays visible in capture/print/reduced-motion contexts where rAF
   may not advance the animation). */
.fade-in { animation: fadein .3s cubic-bezier(.2,.8,.2,1); }
@keyframes fadein { from { transform: translateY(7px); } to { transform: none; } }

/* ---------- Chatbot ----------------------------------------------------- */
.chat-panel {
  position: fixed; top: var(--nav-h); right: 0; bottom: 0; width: 400px; z-index: 60;
  background: #fff; border-left: 1px solid var(--semantic-line-normal-normal);
  display: flex; flex-direction: column;
  box-shadow: -12px 0 40px -16px rgba(23,23,23,0.14);
  animation: slidein .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--semantic-line-normal-neutral); }
.chat-ava { width: 34px; height: 34px; border-radius: 50%; background: var(--atomic-blue-95); display: grid; place-items: center; color: var(--semantic-primary-normal); font-weight: 800; }
.chat-name { font-size: 15px; font-weight: 700; }
.chat-status { font-size: 12px; color: var(--atomic-green-40); font-weight: 600; display: flex; align-items: center; gap: 5px; }
.chat-status .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--atomic-green-50); }
.chat-x { margin-left: auto; width: 32px; height: 32px; border-radius: 8px; border: none; background: transparent; cursor: pointer; display: grid; place-items: center; color: var(--semantic-label-alternative); }
.chat-x:hover { background: var(--semantic-fill-normal); }
.chat-log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; background: var(--semantic-background-normal-alternative); }
.msg { max-width: 82%; padding: 11px 14px; border-radius: 14px; font-size: 14px; line-height: 1.55; }
.msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--semantic-line-normal-neutral); border-top-left-radius: 4px; }
.msg.me { align-self: flex-end; background: var(--semantic-primary-normal); color: #fff; border-top-right-radius: 4px; }
.msg .ref { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--semantic-line-normal-alternative); font-size: 12px; color: var(--semantic-label-alternative); }
.chat-sugg { display: flex; flex-wrap: wrap; gap: 7px; padding: 10px 14px 0; }
.chat-sugg .s { font-size: 12.5px; font-weight: 600; padding: 7px 11px; border-radius: var(--radius-pill); background: #fff; border: 1px solid var(--semantic-line-normal-normal); cursor: pointer; color: var(--semantic-label-neutral); }
.chat-sugg .s:hover { background: var(--atomic-blue-95); color: var(--semantic-primary-normal); border-color: transparent; }
.chat-input { display: flex; gap: 8px; padding: 14px; border-top: 1px solid var(--semantic-line-normal-neutral); background: #fff; }
.chat-input input { flex: 1; height: 42px; border: 1px solid var(--semantic-line-normal-normal); border-radius: var(--radius-pill); padding: 0 16px; font-size: 14px; font-family: inherit; outline: none; }
.chat-input input:focus { border-color: var(--semantic-primary-normal); }
.chat-send { width: 42px; height: 42px; border-radius: 50%; border: none; background: var(--semantic-primary-normal); color: #fff; cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.chat-typing { display: flex; gap: 4px; padding: 4px 2px; }
.chat-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--semantic-label-assistive); animation: blink 1.2s infinite; }
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity: .3; } 30% { opacity: 1; } }

/* form controls */
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 7px; color: var(--semantic-label-neutral); }
.field input, .field textarea { width: 100%; border: 1px solid var(--semantic-line-normal-normal); border-radius: var(--radius-10); padding: 12px 14px; font-size: 14px; font-family: inherit; outline: none; background: #fff; }
.field input:focus, .field textarea:focus { border-color: var(--semantic-primary-normal); box-shadow: 0 0 0 3px var(--atomic-blue-95); }
.field .hint { font-size: 12px; color: var(--semantic-label-alternative); margin-top: 6px; }

/* responsive: collapse rail under md */
@media (max-width: 980px) {
  .rail { display: none; }
  .page { padding: 24px 20px 80px; }
  .kpis { grid-template-columns: 1fr; }
  .chat-panel { width: 100%; }
}
