/* KB Digital Ops: dye-house palette, quiet chrome, the production line is the signature element. */
:root {
  --page: #F3F5F4;
  --surface: #FFFFFF;
  --sunken: #EBEFEE;
  --ink: #16213A;
  --ink-2: #4A5468;
  --ink-3: #7B8496;
  --line: #D9DFE3;
  --line-2: #E8ECEE;
  --indigo: #2B3FA8;
  --indigo-ink: #1E2E80;
  --indigo-wash: #E7EAF8;
  --turmeric: #C98A0B;
  --turmeric-wash: #FBF1DB;
  --kumkum: #B3261E;
  --kumkum-wash: #F8E3E1;
  --leaf: #2F7D5B;
  --leaf-wash: #E0F0E8;
  --slate-wash: #E9EDF2;
  --r-sm: 4px;
  --r-md: 7px;
  --r-lg: 12px;
  --font: ui-sans-serif, "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Nirmala UI", "Noto Sans Tamil", "Latha", sans-serif;
  --rail: 232px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 var(--font); color: var(--ink); background: var(--page); font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
a { color: var(--indigo); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.55rem; font-weight: 650; }
h2 { font-size: 1.15rem; font-weight: 620; }
h3 { font-size: 0.98rem; font-weight: 620; }
p { margin: 0 0 0.6em; max-width: 72ch; }
small, .muted { color: var(--ink-3); }
code, pre { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.85em; }
pre { white-space: pre-wrap; background: var(--sunken); padding: 10px 12px; border-radius: var(--r-md); margin: 0; max-height: 360px; overflow: auto; }
:focus-visible { outline: 2px solid var(--indigo); outline-offset: 2px; }
.boot { padding: 40px; color: var(--ink-3); }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }
.rail { background: var(--ink); color: #C9D0DE; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 10px; color: #fff; font-weight: 650; }
.brand img { width: 28px; height: 28px; }
.brand span { font-size: 0.95rem; line-height: 1.2; }
.brand small { display: block; color: #8E97AB; font-weight: 450; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-group { color: #7F89A0; font-size: 0.78rem; padding: 12px 10px 4px; }
.nav a { color: #C9D0DE; padding: 7px 10px; border-radius: var(--r-sm); display: flex; justify-content: space-between; align-items: center; font-size: 0.93rem; }
.nav a:hover { background: #22304F; text-decoration: none; color: #fff; }
.nav a.active { background: #2B3A61; color: #fff; }
.nav .count { font-size: 0.75rem; background: var(--turmeric); color: #1d1500; border-radius: 9px; padding: 0 7px; min-width: 20px; text-align: center; font-weight: 650; }
.nav .count.crit { background: #E25A50; color: #fff; }
.rail-foot { margin-top: auto; font-size: 0.82rem; color: #8E97AB; padding: 8px; border-top: 1px solid #2A3654; }
.rail-foot button.link { color: #E3E8F2; text-decoration: underline; margin-top: 4px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 28px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.page { padding: 24px 28px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }

/* ---------- Controls ---------- */
button, .btn { font: inherit; font-size: 0.9rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 6px 12px; border-radius: var(--r-sm); cursor: pointer; line-height: 1.35; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover { border-color: #B8C1CA; }
button.primary { background: var(--indigo); border-color: var(--indigo); color: #fff; }
button.primary:hover { background: var(--indigo-ink); }
button.good { background: var(--leaf); border-color: var(--leaf); color: #fff; }
button.warn { border-color: #E3C27A; background: var(--turmeric-wash); color: #6B4700; }
button.danger { border-color: #E5B1AC; color: var(--kumkum); }
button.link { border: 0; background: none; padding: 0; color: var(--indigo); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
input, select, textarea { font: inherit; font-size: 0.92rem; color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 6px 9px; background: #fff; max-width: 100%; }
textarea { width: 100%; min-height: 80px; resize: vertical; }
label { display: block; font-size: 0.85rem; color: var(--ink-2); margin-bottom: 10px; }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--indigo-wash); color: var(--indigo-ink); font-weight: 600; }

/* ---------- Panels & tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; margin-bottom: 16px; }
.panel > h2, .panel > h3 { margin-bottom: 10px; }
.panel h4 { font-size: 0.9rem; font-weight: 620; margin: 16px 0 6px; color: var(--ink-2); }
details.panel summary { cursor: pointer; font-weight: 600; }
details.panel[open] summary { margin-bottom: 12px; }
fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: 6px 10px; margin: 0 0 10px; }
fieldset label { margin-bottom: 2px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 0.82rem; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #F7F9FC; }
td.num, th.num { text-align: right; }
.empty { padding: 28px 16px; text-align: center; color: var(--ink-3); }
.empty strong { display: block; color: var(--ink-2); margin-bottom: 4px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 0.9rem; }
dl.kv dt { color: var(--ink-3); }
dl.kv dd { margin: 0; }

/* ---------- Status language ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 0.78rem; padding: 1px 8px; border-radius: 10px; background: var(--slate-wash); color: var(--ink-2); white-space: nowrap; font-weight: 550; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.7; }
.chip.plain::before { display: none; }
.s-wait { background: var(--turmeric-wash); color: #7A5200; }
.s-work { background: var(--indigo-wash); color: var(--indigo-ink); }
.s-done { background: var(--leaf-wash); color: #1F5C41; }
.s-bad { background: var(--kumkum-wash); color: var(--kumkum); }
.s-idle { background: var(--slate-wash); color: var(--ink-2); }
.mock { background: #EFE7FB; color: #5B3B98; }
.overdue { color: var(--kumkum); font-weight: 600; }
.fmt { font-size: 0.75rem; color: var(--ink-3); border: 1px solid var(--line); border-radius: 3px; padding: 0 5px; }

/* ---------- Production line (signature) ---------- */
.lines { display: flex; flex-direction: column; gap: 10px; }
.line { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px; display: grid; grid-template-columns: minmax(180px, 230px) 1fr minmax(150px, 190px); gap: 18px; align-items: center; cursor: pointer; }
.line:hover { border-color: #B8C1CA; }
.line .who h3 { font-size: 1rem; }
.line .who small { display: block; }
.stages { display: grid; grid-template-columns: repeat(7, minmax(64px, 1fr)); position: relative; }
.stages::before { content: ""; position: absolute; left: 6%; right: 6%; top: 15px; height: 2px; background: var(--line); }
.stage { position: relative; text-align: center; padding: 0 2px; }
.stage b { position: relative; display: inline-flex; align-items: center; justify-content: center; min-width: 32px; height: 32px; border-radius: 16px; background: var(--surface); border: 2px solid var(--line); font-size: 0.9rem; font-weight: 650; padding: 0 6px; color: var(--ink-3); }
.stage.has b { border-color: var(--indigo); color: var(--indigo-ink); }
.stage.hot b { border-color: var(--turmeric); background: var(--turmeric-wash); color: #6B4700; }
.stage.bad b { border-color: var(--kumkum); background: var(--kumkum-wash); color: var(--kumkum); }
.stage.ok b { border-color: var(--leaf); color: #1F5C41; }
.stage span { display: block; font-size: 0.74rem; color: var(--ink-3); margin-top: 4px; line-height: 1.2; }
.month-progress { font-size: 0.85rem; }
.month-progress svg { display: block; width: 100%; height: 8px; margin: 6px 0; }
.spark { display: block; width: 100%; height: 34px; }

/* ---------- Calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--line); gap: 1px; }
.cal .dow { background: var(--sunken); font-size: 0.78rem; color: var(--ink-2); padding: 6px 8px; font-weight: 600; }
.cal .day { background: var(--surface); min-height: 110px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.cal .day.out { background: #F8F9FA; }
.cal .day.today .dnum { background: var(--indigo); color: #fff; border-radius: 10px; padding: 0 7px; }
.cal .dnum { font-size: 0.8rem; color: var(--ink-3); align-self: flex-start; }
.cal .item { font-size: 0.78rem; padding: 3px 6px; border-radius: var(--r-sm); cursor: pointer; border-left: 3px solid currentColor; text-align: left; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cal-list { display: none; }

/* ---------- Pipeline ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--sunken); border-radius: var(--r-lg); padding: 10px; min-height: 140px; }
.col h3 { font-size: 0.86rem; display: flex; justify-content: space-between; margin: 2px 4px 10px; color: var(--ink-2); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 9px 10px; margin-bottom: 8px; cursor: pointer; font-size: 0.88rem; }
.card:hover { border-color: #AEB8C4; }
.card .t { font-weight: 560; margin-bottom: 4px; }
.card .m { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 0.78rem; color: var(--ink-3); }

/* ---------- Sheet (content detail) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(22, 33, 58, 0.32); z-index: 20; }
.sheet { position: fixed; top: 0; right: 0; bottom: 0; width: min(880px, 100vw); background: var(--page); z-index: 21; display: flex; flex-direction: column; box-shadow: -12px 0 32px rgba(22, 33, 58, 0.18); }
.sheet-head { background: var(--surface); border-bottom: 1px solid var(--line); padding: 16px 20px; display: flex; gap: 14px; align-items: flex-start; }
.sheet-head .grow h2 { font-size: 1.2rem; margin-bottom: 6px; }
.sheet-body { overflow-y: auto; padding: 16px 20px 60px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--ink-2); }
.tabs button.on { border-bottom-color: var(--indigo); color: var(--ink); font-weight: 600; }
.scene { display: grid; grid-template-columns: 46px 1fr 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-2); font-size: 0.9rem; }
.scene .n { color: var(--ink-3); font-size: 0.8rem; }
.hook-list { margin: 0; padding-left: 18px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0 6px 16px; border-left: 2px solid var(--line); position: relative; font-size: 0.88rem; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--indigo); }
.prompt-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 12px; margin-bottom: 10px; }

/* ---------- Report markdown ---------- */
.md h1 { font-size: 1.3rem; margin: 6px 0 10px; }
.md h2 { font-size: 1.05rem; margin: 18px 0 8px; }
.md h3 { margin: 14px 0 6px; }
.md table { margin: 8px 0 14px; }
.md ul { padding-left: 20px; }
.md .banner { background: #EFE7FB; color: #5B3B98; padding: 8px 12px; border-radius: var(--r-md); font-weight: 600; margin-bottom: 10px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--ink); }
.login form { background: var(--surface); width: min(400px, 100%); padding: 28px; border-radius: var(--r-lg); }
.login h1 { margin-bottom: 4px; }
.login p { color: var(--ink-2); margin-bottom: 18px; }
.err { color: var(--kumkum); font-size: 0.88rem; min-height: 1.3em; }

/* ---------- Toast ---------- */
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 16px; border-radius: var(--r-md); font-size: 0.9rem; z-index: 40; opacity: 0; pointer-events: none; transition: opacity 0.18s; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.bad { background: var(--kumkum); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .line { grid-template-columns: 1fr; gap: 12px; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform 0.2s; }
  .shell.nav-open .rail { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .page { padding: 16px 16px 60px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stages { grid-template-columns: repeat(7, minmax(44px, 1fr)); }
  .stage span { font-size: 0.68rem; }
  .cal { display: none; }
  .cal-list { display: block; }
  .scene { grid-template-columns: 1fr; gap: 4px; }
  .sheet-head, .sheet-body, .actions { padding-left: 16px; padding-right: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
