/* NOCTURNE Owner Console design system (M18 design 2.1 to 2.8).
   Self-hosted only: Pretendard Variable (SIL OFL 1.1) from /static/fonts, no remote URL, no
   inline style needed, no gradient, no glow, no drop shadow (1 px hairlines only). */

@font-face {
  font-family: "Pretendard Variable";
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  src: url("/static/fonts/PretendardVariable.woff2") format("woff2-variations");
}

/* ---- tokens (design 2.2) --------------------------------------------------------------- */

:root {
  color-scheme: light dark;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #efefec;
  --line: #e1e1dc;
  --line-strong: #cbcbc4;
  --control: #80848b;
  --text: #1b1c1f;
  --text-2: #43464c;
  --muted: #696c73;
  --accent: #24508f;
  --accent-weak: #e7edf6;
  --on-accent: #ffffff;
  --ok: #1d6e40;
  --ok-bg: #e5f2ea;
  --warn: #8a5300;
  --warn-bg: #faefd9;
  --danger: #a8261b;
  --danger-bg: #fbe8e6;
  --info: #1f579e;
  --info-bg: #e6eef9;
  --neutral: #4b4e56;
  --neutral-bg: #ecece9;
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --r-control: 6px;
  --r-card: 8px;
  --sidebar-w: 240px;
  --chat-w: 360px;
  --topbar-h: 56px;
  --font: "Pretendard Variable", Pretendard, system-ui, -apple-system, "Segoe UI",
    "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214;
    --surface: #17181b;
    --surface-2: #1f2125;
    --line: #2b2e34;
    --line-strong: #3a3e46;
    --control: #70747d;
    --text: #ecedef;
    --text-2: #bcc0c7;
    --muted: #8f939b;
    --accent: #8caee6;
    --accent-weak: #1c2a40;
    --on-accent: #0d1522;
    --ok: #7fd3a0;
    --ok-bg: #16301f;
    --warn: #f0c46a;
    --warn-bg: #36290f;
    --danger: #f29b92;
    --danger-bg: #3a1a17;
    --info: #93b8ee;
    --info-bg: #18273d;
    --neutral: #c3c6cd;
    --neutral-bg: #25272c;
  }
}

:root[data-theme="dark"] {
  --bg: #111214;
  --surface: #17181b;
  --surface-2: #1f2125;
  --line: #2b2e34;
  --line-strong: #3a3e46;
  --control: #70747d;
  --text: #ecedef;
  --text-2: #bcc0c7;
  --muted: #8f939b;
  --accent: #8caee6;
  --accent-weak: #1c2a40;
  --on-accent: #0d1522;
  --ok: #7fd3a0;
  --ok-bg: #16301f;
  --warn: #f0c46a;
  --warn-bg: #36290f;
  --danger: #f29b92;
  --danger-bg: #3a1a17;
  --info: #93b8ee;
  --info-bg: #18273d;
  --neutral: #c3c6cd;
  --neutral-bg: #25272c;
}

/* ---- base ------------------------------------------------------------------------------ */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.6 var(--font);
  word-break: keep-all;
  overflow-wrap: break-word;
  line-break: strict;
}

h1, h2, h3, h4 { margin: 0; color: var(--text); font-weight: 700; }
h1 { font-size: 22px; line-height: 1.35; }
h2 { font-size: 18px; line-height: 1.4; font-weight: 600; }
h3 { font-size: 16px; line-height: 1.5; font-weight: 600; }
p { margin: 0 0 var(--s3); }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
code, kbd, samp, .mono { font-family: var(--mono); font-size: 0.86em; }
small, .xs { font-size: 12px; line-height: 1.5; }
.sm { font-size: 13px; line-height: 1.5; }
.muted { color: var(--muted); }
.num, .tabular, time, td.num, th.num { font-variant-numeric: tabular-nums; }
.num { text-align: right; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip-link {
  position: absolute; left: var(--s2); top: -48px; z-index: 100;
  padding: var(--s2) var(--s3); background: var(--surface); border: 1px solid var(--control);
  border-radius: var(--r-control);
}
.skip-link:focus { top: var(--s2); }

/* ---- controls -------------------------------------------------------------------------- */

input, select, textarea, button { font: inherit; color: inherit; }

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--control); border-radius: var(--r-control);
}
textarea { min-height: 96px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 40px; padding: 8px 16px; border-radius: var(--r-control);
  border: 1px solid var(--control); background: var(--surface); color: var(--text);
  font-weight: 500; font-size: 14px; line-height: 1.4; text-decoration: none;
  white-space: nowrap; cursor: pointer;
  transition: background-color 120ms, border-color 120ms;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-danger-outline { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn-danger-outline:hover { background: var(--danger-bg); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; position: relative;
  width: 36px; height: 36px; padding: 0; border-radius: var(--r-control);
  border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon { width: 16px; height: 16px; flex: none; }
.icon-btn .icon { width: 18px; height: 18px; }

/* ---- forms (design 2.4) ---------------------------------------------------------------- */

.field { display: grid; gap: var(--s1); margin-bottom: var(--s4); }
.field > label, .field-label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field .required { margin-left: var(--s1); font-size: 12px; font-weight: 400; color: var(--muted); }
.field .help { font-size: 12px; color: var(--muted); }
.field .error { font-size: 12px; color: var(--danger); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s4); }
fieldset { border: 1px solid var(--line); border-radius: var(--r-card); padding: var(--s4); margin: 0 0 var(--s4); }
legend { padding: 0 var(--s2); font-weight: 600; }

/* ---- status: badge, dot, chip (design 2.4) --------------------------------------------- */

.t-ok { --tone: var(--ok); --tone-bg: var(--ok-bg); }
.t-warn { --tone: var(--warn); --tone-bg: var(--warn-bg); }
.t-danger { --tone: var(--danger); --tone-bg: var(--danger-bg); }
.t-info { --tone: var(--info); --tone-bg: var(--info-bg); }
.t-neutral { --tone: var(--neutral); --tone-bg: var(--neutral-bg); }

.badge, .chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 1px 10px; border-radius: 999px; flex-shrink: 0; white-space: nowrap;
  font-size: 13px; line-height: 20px; font-weight: 500;
  background: var(--tone-bg, var(--neutral-bg)); color: var(--tone, var(--neutral));
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none;
}
.chip { text-decoration: none; }
.dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--tone, var(--neutral));
}
.is-pulse::before, .dot.is-pulse { animation: nocturne-pulse 1.6s ease-in-out infinite; }
@keyframes nocturne-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.count {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); font-size: 12px; line-height: 20px;
  text-align: center; font-variant-numeric: tabular-nums;
}
.count.t-warn, .count.alert { background: var(--warn-bg); color: var(--warn); }

/* ---- layout shell (design 2.4, 2.8, MA-16) --------------------------------------------- */

.app {
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh;
}
.app.chat-open { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--chat-w); }
.app > .freeze-banner { grid-column: 1 / -1; }

.sidebar {
  position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto;
  padding: var(--s4) var(--s3) var(--s5); background: var(--surface);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: var(--s2); padding: 0 var(--s2) var(--s4); }
.wordmark { font-weight: 700; font-size: 16px; letter-spacing: 0.08em; color: var(--text); text-decoration: none; }
.env-tag { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }

.nav-group { margin: 0; }
.nav-top { padding-left: calc(var(--s2) - 2px); font-weight: 600; }
.nav-group > summary {
  display: flex; align-items: center; justify-content: space-between; list-style: none;
  padding: 6px var(--s2); border-radius: var(--r-control); cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--text-2);
}
.nav-group > summary > span:first-child { flex: 1; }
.nav-group > summary .count { margin-right: var(--s2); }
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary::after {
  content: ""; width: 6px; height: 6px; margin-right: 4px;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg); transition: transform 120ms;
}
.nav-group[open] > summary::after { transform: rotate(-135deg); }
.nav-group > summary:hover { background: var(--surface-2); }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-link {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  min-height: 36px; padding: 6px var(--s2) 6px var(--s3); border-left: 2px solid transparent;
  border-radius: 0 var(--r-control) var(--r-control) 0; color: var(--text-2);
  font-size: 14px; text-decoration: none;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link[aria-current="page"] {
  background: var(--accent-weak); border-left-color: var(--accent); color: var(--text); font-weight: 600;
}

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--s3);
  min-height: var(--topbar-h); padding: 0 var(--s5);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar-title { margin: 0; flex: 1; min-width: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: var(--s2); }
.menu-btn { display: none; }
.topbar-brand { display: none; font-weight: 700; letter-spacing: 0.08em; color: var(--text); text-decoration: none; }
.decision-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-size: 13px; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.decision-badge b { font-variant-numeric: tabular-nums; }
.decision-badge.has-items { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.bell-count {
  position: absolute; top: 0; right: 0; min-width: 16px; padding: 0 4px; border-radius: 999px;
  background: var(--danger); color: var(--surface); font-size: 11px; line-height: 16px; text-align: center;
}
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: inline; }
:root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: inline; }
  :root:not([data-theme="light"]) .i-moon { display: none; }
}
.user-menu { position: relative; }
.user-menu > summary { list-style: none; cursor: pointer; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu-body {
  position: absolute; right: 0; top: 40px; z-index: 30; min-width: 160px; padding: var(--s2);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-card);
}

.freeze-banner {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: var(--s3);
  padding: var(--s2) var(--s4); background: var(--danger-bg); color: var(--danger);
  border-bottom: 1px solid var(--danger); font-weight: 500;
}
.freeze-banner p { margin: 0; }

.content { width: 100%; max-width: 1160px; margin: 0 auto; padding: var(--s5) var(--s5) var(--s7); }

/* docked chat panel slot (U7 fills `_chat_panel.html`; MA-36) */
.chat-panel {
  position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--line);
}
.chat-panel[hidden] { display: none; }

.tabbar { display: none; }
.scrim { display: none; }
.toast-region {
  position: fixed; right: var(--s4); bottom: var(--s4); z-index: 60; display: grid; gap: var(--s2);
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) var(--s4);
  background: var(--surface); color: var(--text); border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent); border-radius: var(--r-card); font-size: 14px;
}
.toast p { margin: 0; flex: 1; }

/* ---- page parts (design 4.1) ----------------------------------------------------------- */

.page-header {
  display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap;
  gap: var(--s3) var(--s4); margin-bottom: var(--s5);
}
.page-header .context { margin: var(--s1) 0 0; font-size: 13px; color: var(--muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.breadcrumb { margin: 0 0 var(--s2); font-size: 13px; color: var(--muted); }
.section { margin-bottom: var(--s6); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.section-head .count { margin-left: var(--s2); }

.card {
  padding: var(--s4); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card);
}
.card + .card { margin-top: var(--s3); }
.card-grid { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.kpi-grid {
  display: grid; gap: var(--s3); margin-bottom: var(--s6);
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.kpi { display: block; padding: var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); color: inherit; text-decoration: none; }
a.kpi:hover { border-color: var(--control); }
.kpi-label { display: flex; align-items: center; gap: var(--s2); font-size: 13px; color: var(--muted); }
.kpi-value { display: block; margin: var(--s1) 0; font-size: 28px; line-height: 1.2; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-unit { margin-left: var(--s1); font-size: 14px; font-weight: 500; color: var(--text-2); }
.kpi-context { display: block; font-size: 12px; color: var(--muted); }
meter, progress { width: 100%; height: 6px; margin-top: var(--s2); accent-color: var(--accent); }

.decision-card {
  display: grid; gap: var(--s1); padding: var(--s3) var(--s4); background: var(--surface);
  border: 1px solid var(--tone, var(--neutral)); border-radius: var(--r-card);
}
.decision-card + .decision-card { margin-top: var(--s2); }
.decision-card h3 { margin: 0; }
.decision-card .fact { margin: 0; font-size: 14px; color: var(--text-2); }
.decision-card .deadline { margin: 0; font-size: 12px; color: var(--muted); }
.decision-card .actions { margin-top: var(--s2); }

.empty { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s3); min-height: 48px; max-height: 64px; padding: var(--s3) var(--s4); color: var(--muted); font-size: 14px; border: 1px dashed var(--line-strong); border-radius: var(--r-card); }
.empty p { margin: 0; }
.error-state { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s4); color: var(--danger); background: var(--danger-bg); border: 1px solid var(--danger); border-radius: var(--r-card); font-size: 14px; }
.error-state p { margin: 0; }

.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s1) var(--s4); margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.callout { padding: var(--s3) var(--s4); border-radius: var(--r-card); background: var(--tone-bg, var(--neutral-bg)); color: var(--text); border-left: 3px solid var(--tone, var(--neutral)); margin-bottom: var(--s4); }
.callout p:last-child { margin-bottom: 0; }

details.more { margin-top: var(--s4); border-top: 1px solid var(--line); padding-top: var(--s3); }
details.more > summary { cursor: pointer; font-size: 13px; color: var(--text-2); }

.confirm { max-width: 640px; }
.confirm ul { margin: var(--s2) 0 0; padding-left: var(--s5); }
.confirm ul + .facts { margin-top: var(--s3); }

.skeleton { display: grid; gap: var(--s2); }
.skeleton span { display: block; height: 12px; border-radius: 4px; background: var(--surface-2); animation: nocturne-pulse 1.6s ease-in-out infinite; }
.skeleton span:nth-child(2) { width: 80%; }
.skeleton span:nth-child(3) { width: 55%; }

/* ---- data table (design 2.4) ----------------------------------------------------------- */

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table caption { text-align: left; padding: var(--s3) var(--s4); font-weight: 600; }
.table th, .table td { padding: 8px var(--s4); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.table th { position: sticky; top: 0; background: var(--surface-2); color: var(--text-2); font-size: 13px; font-weight: 600; white-space: nowrap; }
.table th.num, .table td.num { text-align: right; }
.table tbody tr:hover { background: var(--surface-2); }
.cell-trunc { display: inline-block; max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

/* ---- login / error (bare layout) ------------------------------------------------------- */

.bare { min-height: 100vh; display: grid; place-items: center; padding: var(--s5) var(--s4); }
.bare-card { width: 100%; max-width: 440px; padding: var(--s5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); }
.bare-card h1 { margin-bottom: var(--s3); }
.bare-brand { display: block; margin-bottom: var(--s4); font-weight: 700; letter-spacing: 0.08em; font-size: 14px; color: var(--muted); }

/* ---- chat primitives (U7 fills the panel; shared look) --------------------------------- */

.chat-message { max-width: 85%; padding: var(--s2) var(--s3); border-radius: var(--r-card); background: var(--surface-2); }
.chat-message.is-owner { margin-left: auto; background: var(--accent-weak); }
.chat-composer { display: flex; gap: var(--s2); padding: var(--s3); border-top: 1px solid var(--line); }

/* ---- responsive (design 2.8) ----------------------------------------------------------- */

@media (max-width: 1279px) {
  .app.chat-open { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .chat-panel:not([hidden]) {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: min(var(--chat-w), 100vw);
    height: 100vh;
  }
}

@media (max-width: 1023px) {
  .app, .app.chat-open { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; width: min(300px, 86vw);
    height: 100vh; transform: translateX(-102%); transition: transform 150ms;
  }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.4); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { padding: 0 var(--s4); }
  .content { padding: var(--s4) var(--s4) var(--s7); }
}

@media (max-width: 599px) {
  body { padding-bottom: 64px; }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; display: grid;
    grid-template-columns: repeat(5, 1fr); min-height: 56px;
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .tabbar-link {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    position: relative; min-height: 56px; padding: 4px 0; border: 0; background: transparent;
    color: var(--muted); font-size: 11px; text-decoration: none; cursor: pointer;
  }
  .tabbar-link[aria-current="page"] { color: var(--accent); font-weight: 600; }
  .tabbar-link .count { position: absolute; top: 4px; left: calc(50% + 6px); }
  .topbar-actions .decision-badge, .topbar-actions .theme-btn { display: none; }
  .topbar-title { display: none; }
  .topbar-brand { display: block; flex: 1; }
  .kpi-value { font-size: 24px; }
  .page-header { margin-bottom: var(--s4); }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: var(--s2) var(--s4); border-bottom: 1px solid var(--line); }
  .table td { display: flex; justify-content: space-between; gap: var(--s3); padding: 4px 0; border: 0; }
  .table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 13px; flex: none; }
  .toast-region { left: 50%; right: auto; bottom: 72px; transform: translateX(-50%); width: calc(100vw - 32px); }
  .facts { grid-template-columns: minmax(0, 1fr); }
  .facts dt { margin-top: var(--s2); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- W2 extension points (MA-U-4: each unit appends only inside its own block) --------- */

/* ==== U5 (home, decisions, 업무 pages) ===================================================== */

.table-wrap + .section, .card + .section, p + .section, .rows + .section { margin-top: var(--s5); }

/* header actions: badges keep their own height next to buttons */
.page-actions { align-items: center; }

/* Home hero */
.hero { margin-bottom: var(--s5); }
.hero-greet { margin: 0 0 var(--s1); font-size: 13px; color: var(--muted); }
.hero h1 { font-size: 28px; line-height: 1.3; letter-spacing: -0.01em; }
.hero h1 strong { color: var(--accent); font-weight: 700; }
.hero-line { margin: var(--s2) 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); color: var(--text-2); }

/* decision cards: a tone border (from .decision-card) plus a top row and a calm grid */
.decision-grid { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.decision-grid .decision-card + .decision-card { margin-top: 0; }
.decision-card { align-content: start; }
.decision-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); flex-wrap: wrap; }
.decision-top .deadline { margin: 0; font-size: 12px; color: var(--muted); }
.decision-top .deadline.is-urgent { color: var(--warn); font-weight: 600; }
.more-line { margin: var(--s2) 0 0; }

/* two-column body below the fold */
.two-col { display: grid; gap: var(--s5); grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); }
.rows .row { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2) var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.rows .row:last-child, .rows > li:last-child { border-bottom: 0; }
.rows > li.muted { padding: var(--s3) var(--s4); }
.rows .row.stack { display: grid; gap: var(--s1); align-items: start; }
.row-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.row-title { flex: 1 1 8em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows meter { margin-top: 0; }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s2); }
.report-card .report-text { font-size: 16px; line-height: 1.6; margin-bottom: var(--s2); }
.chip-text { display: inline-block; margin: 0 var(--s1) var(--s1) 0; padding: 0 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: 12px; line-height: 20px; }

/* meter + figure on one line (mission lists) */
.progress-line { display: inline-flex; align-items: center; gap: var(--s2); min-width: 140px; }
.progress-line meter { margin-top: 0; width: 80px; flex: none; }

/* status tabs (tasks) */
.seg { display: flex; flex-wrap: wrap; gap: var(--s1); margin: 0 0 var(--s4); padding: var(--s1); width: fit-content; max-width: 100%; background: var(--surface-2); border-radius: var(--r-control); }
.seg a { padding: 4px 12px; border-radius: 4px; color: var(--text-2); font-size: 13px; text-decoration: none; white-space: nowrap; }
.seg a:hover { color: var(--text); }
.seg a[aria-current="page"] { background: var(--surface); color: var(--text); font-weight: 600; outline: 1px solid var(--line-strong); }

/* mission picker and capability cards */
.pick { display: grid; gap: var(--s2); color: inherit; text-decoration: none; }
.pick:hover { border-color: var(--control); }
.pick-title { font-weight: 600; }
.pick-meta { display: flex; align-items: center; gap: var(--s2); font-size: 13px; }
.card-grid .card + .card { margin-top: 0; }
.capability { display: grid; gap: var(--s2); align-content: start; border-left: 3px solid var(--tone, var(--neutral)); }
.capability p { margin: 0; }
.capability-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2); }

/* notices, identifiers, inert text, forms in cards */
.notice { margin: 0 0 var(--s3); padding: var(--s2) var(--s3); border-left: 3px solid var(--warn); background: var(--warn-bg); border-radius: var(--r-control); font-size: 14px; }
.ident { overflow-wrap: break-word; }
.digest { overflow-wrap: break-word; }
.facts dd, .facts dd code { overflow-wrap: break-word; min-width: 0; }
pre.inert { margin: 0; padding: var(--s3) var(--s4); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-card); white-space: pre-wrap; overflow-wrap: break-word; font: 400 13px/1.6 var(--mono); max-height: 480px; overflow: auto; }
pre.inert.quote { font: 400 15px/1.7 var(--font); border-left: 3px solid var(--line-strong); }
.row-corrupt td, .row-corrupt { background: var(--danger-bg); }
.inline-form { display: inline-flex; margin: 0; }
.choice { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); }
.radio { display: inline-flex; align-items: center; gap: var(--s2); font-weight: 500; }
.panel { padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); }
.panel > summary { cursor: pointer; font-weight: 600; }
.actions-card { display: grid; gap: var(--s4); }
.links { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.table td, .table th { word-break: keep-all; }
.table td.num .btn { white-space: nowrap; }
.card.action .field:last-of-type { margin-bottom: 0; }

/* calm progress bars: one accent for every meter value */
.rows meter, .progress-line meter, .kpi meter { height: 8px; border: 0; border-radius: 4px; background: var(--surface-2); }
meter::-webkit-meter-bar { background: var(--surface-2); border: 0; border-radius: 4px; height: 8px; }
meter::-webkit-meter-optimum-value, meter::-webkit-meter-suboptimum-value, meter::-webkit-meter-even-less-good-value { background: var(--accent); border-radius: 4px; }
meter::-moz-meter-bar { background: var(--accent); border-radius: 4px; }

@media (max-width: 1023px) {
  .two-col { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 599px) {
  .hero h1 { font-size: 24px; }
  .decision-grid { grid-template-columns: minmax(0, 1fr); }
  .progress-line { min-width: 0; }
  .table td.num { justify-content: flex-end; }
  .seg { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
}

/* ==== U6 (조직, 지식, 시스템, 기록 pages) =================================================== */

/* Shared helpers of the 조직·지식·시스템·기록 pages. */
.sub-head { margin: var(--s5) 0 var(--s3); font-size: 15px; }
.inline-form { display: inline-flex; align-items: center; gap: var(--s2); margin: 0; }
.field-inline { display: flex; align-items: center; gap: var(--s2); margin-bottom: 0; }
.field-inline > label { white-space: nowrap; }
.field-inline select { width: auto; min-width: 140px; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); margin-bottom: var(--s4); }
.table td.wrap, .table td .wrap { white-space: normal; overflow-wrap: break-word; word-break: normal; min-width: 14ch; }
.table td, .table th { overflow-wrap: normal; word-break: keep-all; }
.table td .mono, .table td code { overflow-wrap: break-word; }
.row-corrupt { color: var(--text-2); }
.inert { margin: 0; padding: var(--s3); max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: break-word; font: 13px/1.6 var(--mono); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-control); }
.digest { overflow-wrap: break-word; word-break: break-all; }
.chips { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); }
.lineage { margin: var(--s3) 0 0; padding-left: var(--s5); font-size: 14px; }
.card.t-ok, .card.t-warn, .card.t-danger, .card.t-info { border: 1px solid var(--tone); }
.decision-forms { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-top: var(--s3); align-items: start; }
.decision-forms .card + .card { margin-top: 0; }
.card.action h3 { margin-bottom: var(--s3); }
.card + .section, .card + .sub-head { margin-top: var(--s6); }
.card + details.more { margin-top: var(--s4); }
.action .form-actions { margin-top: var(--s3); }

/* Tabs (anchor jumps, no script) and filter chips. */
.tabs { display: flex; gap: var(--s1); margin-bottom: var(--s5); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { display: inline-flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s4); color: var(--text-2); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s4); }
.filter-chip { padding: 4px 14px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text-2); }
.filter-chip:hover { background: var(--surface-2); color: var(--text); }
.filter-chip.is-active { background: var(--accent-weak); border-color: var(--accent); color: var(--text); font-weight: 600; }

/* Agent cards grouped by role (design 4.4). */
.agent-groups { display: grid; gap: var(--s5) var(--s4); grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); align-items: start; }
.agent-group { min-width: 0; }
.agent-group-head { display: flex; align-items: center; gap: var(--s2); margin: 0 0 var(--s2); font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.agent-stack { display: grid; gap: var(--s3); }
.agent-card { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); min-width: 0; }
.agent-card.is-missing { border-color: var(--danger); }
.owner-card { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.owner-card p { margin: 0; }
.agent-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.agent-head h3 { margin: 0; min-width: 0; overflow-wrap: break-word; }
.agent-facts { display: grid; gap: var(--s2); margin: 0; font-size: 14px; }
.agent-fact { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: var(--s3); align-items: baseline; }
.agent-fact dt { color: var(--muted); font-size: 13px; }
.agent-fact dd { margin: 0; min-width: 0; }
.agent-trust strong { font-size: 18px; }
.trend { font-size: 13px; font-weight: 600; white-space: nowrap; color: var(--tone, var(--neutral)); }
.agent-foot { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s2); margin-top: auto; }
.agent-more { width: 100%; margin-top: 0; }

/* System probes (design 4.6). */
.probe-grid { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.probe-card { padding: var(--s4); background: var(--surface); border: 1px solid var(--tone, var(--neutral)); border-radius: var(--r-card); min-width: 0; }
.probe-card p { margin: 0 0 var(--s2); }
.probe-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s2); }
.probe-head h3 { margin: 0; font-size: 15px; }
.control-state { margin-bottom: var(--s4); max-width: 640px; }
.confirm-flow { max-width: 640px; margin-bottom: var(--s6); display: grid; gap: var(--s3); }
.confirm-flow .card + .card { margin-top: 0; }
.finding { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }

/* HR proposal cards. */
.proposal-grid { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.proposal-card { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4); background: var(--surface); border: 1px solid var(--tone, var(--neutral)); border-radius: var(--r-card); min-width: 0; }
.proposal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.proposal-head h3 { margin: 0; font-size: 15px; }
.proposal-foot { margin-top: auto; }

/* Scorecard trend. */
.trust-card .sparkline { display: block; width: 100%; max-width: 480px; height: 56px; margin-bottom: var(--s2); }
.trust-card .sparkline path { stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.trust-card .sparkline circle { fill: var(--accent); }

/* Readiness (design 4.5). */
.readiness-grid { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.readiness-card { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4); background: var(--surface); border: 1px solid var(--tone, var(--neutral)); border-radius: var(--r-card); min-width: 0; }
.readiness-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.readiness-head h3 { margin: 0; }
.readiness-meter meter { margin-top: var(--s1); }

/* /records timeline (design 4.7, MA-24). */
.timeline { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); }
.timeline-row { display: grid; grid-template-columns: 112px 96px minmax(0, 1fr); gap: var(--s3); align-items: baseline; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.timeline-row:last-child { border-bottom: 0; }
.timeline-time { color: var(--muted); white-space: nowrap; }
.timeline-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.timeline-title { font-weight: 500; overflow-wrap: break-word; }
.timeline-detail { display: inline-flex; align-items: center; gap: var(--s2); }

@media (max-width: 599px) {
  .agent-groups, .proposal-grid, .probe-grid, .readiness-grid { grid-template-columns: minmax(0, 1fr); }
  .agent-fact { grid-template-columns: 84px minmax(0, 1fr); gap: var(--s2); }
  .timeline-row { grid-template-columns: minmax(0, 1fr) auto; gap: var(--s1) var(--s3); }
  .timeline-body { grid-column: 1 / -1; }
  .decision-forms { grid-template-columns: minmax(0, 1fr); }
  .filter-bar, .field-inline { align-items: stretch; flex-direction: column; }
  .field-inline select { width: 100%; }
  .page-actions .inline-form { width: 100%; }
}







/* ==== U7 (chat) ============================================================================ */

/* page: session rail + conversation */
.chat-page { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--s4); align-items: start; }
.chat-rail { position: sticky; top: calc(var(--topbar-h) + var(--s4)); display: grid; gap: var(--s3); }
.chat-rail-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.chat-rail-head h2 { margin: 0; font-size: 15px; }
.chat-threads { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s1); }
.chat-thread { display: grid; gap: 2px; padding: var(--s2) var(--s3); border-radius: var(--r-control); text-decoration: none; color: var(--text); border: 1px solid transparent; }
.chat-thread:hover { background: var(--surface-2); }
.chat-thread.is-current { background: var(--accent-weak); border-color: var(--accent); }
.chat-thread-title { overflow-wrap: break-word; font-weight: 500; }
.chat-thread-empty { padding: var(--s2) var(--s3); }
.chat-main { display: grid; gap: var(--s3); min-width: 0; align-content: start; }
.chat-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.chat-header-text { min-width: 0; flex: 1 1 280px; }
.chat-header h1 { margin: 0 0 var(--s1); font-size: 20px; overflow-wrap: break-word; }
.chat-model { margin: 0; font-size: 13px; color: var(--text-2); display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }

/* the private-thread switch (a button with role=switch; works as a plain form) */
.chat-switch { margin: 0; }
.switch { display: inline-flex; align-items: center; gap: var(--s2); min-height: 36px; padding: 0 var(--s2); border: 1px solid var(--control); border-radius: 999px; background: transparent; color: var(--text); cursor: pointer; }
.switch:hover { background: var(--surface-2); }
.switch-track { position: relative; width: 36px; height: 20px; border-radius: 999px; background: var(--control); flex: none; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); }
.switch.is-on .switch-track { background: var(--ok); }
.switch.is-on .switch-thumb { left: 18px; }
.switch-text { font-size: 13px; }

/* the message stream */
.chat-stream { display: grid; gap: var(--s3); align-content: start; padding: 0 var(--s4); border: 1px solid var(--line); border-radius: var(--r-card); background: var(--surface); overflow-y: auto; min-height: 240px; scroll-snap-type: y proximity; scroll-padding: var(--s4) 0; }
/* solid sticky bars with a 1px rule: messages scroll under them, never mid-line against the border */
.chat-edge { position: sticky; z-index: 1; height: var(--s4); margin-inline: calc(-1 * var(--s4)); background: var(--surface); }
.chat-edge-top { top: 0; margin-bottom: calc(-1 * var(--s3)); border-bottom: 1px solid var(--line); }
.chat-edge-bottom { bottom: 0; margin-top: calc(-1 * var(--s3)); border-top: 1px solid var(--line); }
.chat-row { scroll-snap-align: start; }
.chat-stream-panel { flex: 1 1 auto; border-left: 0; border-right: 0; border-radius: 0; max-height: none; min-height: 0; }
.chat-row { display: flex; min-width: 0; }
.chat-row.is-owner { justify-content: flex-end; }
.chat-row.wide { display: block; }
.chat-message { min-width: 0; overflow-wrap: break-word; }
.chat-message.is-notice { background: var(--neutral-bg); color: var(--text); }
.chat-text { margin: 0; white-space: pre-wrap; overflow-wrap: break-word; }
.chat-time { display: block; margin-top: var(--s1); font-size: 12px; color: var(--muted); }
.chat-flag { margin: var(--s1) 0 0; }
.chat-system { margin: 0; font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: var(--s1); }
.chat-chips { list-style: none; margin: var(--s2) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s1); }
.chat-chips .chip { white-space: normal; text-align: left; }
.chat-objects { margin: var(--s2) 0 0; padding-left: var(--s4); }
.chat-empty { display: grid; gap: var(--s3); color: var(--text-2); }
.chat-empty p { margin: 0; }
.chat-suggest { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chat-suggest form { margin: 0; }
.chat-suggest-chip { border: 1px solid var(--info); cursor: pointer; min-height: 32px; }

/* typed cards */
.chat-card { padding: var(--s3) var(--s4); border: 1px solid var(--tone, var(--line-strong)); border-radius: var(--r-card); background: var(--surface); display: grid; gap: var(--s2); min-width: 0; }
.chat-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.chat-card h4 { margin: 0 0 var(--s1); font-size: 13px; color: var(--muted); font-weight: 600; }

.chat-pinned { border-color: var(--info); background: var(--info-bg); padding: var(--s2) var(--s4); gap: var(--s1); }
.proposal-part, .proposal-approvals { display: grid; gap: var(--s1); }
.proposal-title { margin: 0; font-weight: 600; overflow-wrap: break-word; }
.proposal-intent { margin: 0; white-space: pre-wrap; overflow-wrap: break-word; }
.proposal-tasks { margin: 0; padding-left: var(--s5); display: grid; gap: var(--s2); }
.proposal-tasks p { margin: 0; }
.proposal-approvals ul { margin: 0; padding-left: var(--s4); }
.proposal-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.proposal-actions form { margin: 0; }
.chat-progress { display: flex; align-items: center; gap: var(--s2); }
.chat-progress progress { flex: 1 1 auto; height: 10px; accent-color: var(--accent); }
.chat-edit { display: grid; gap: var(--s2); }
.chat-edit textarea { min-height: 72px; }

/* the pending-turn pill (skeleton bars while NOCTURNE works) */
.chat-turn { display: grid; gap: var(--s2); padding: var(--s2) var(--s3); border-radius: var(--r-card); background: var(--info-bg); color: var(--info); }
.chat-turn[hidden] { display: none; }
.chat-turn-phase { font-size: 13px; font-weight: 600; }

/* composer */
.chat-composer { display: grid; gap: var(--s2); padding: var(--s3); border-top: 1px solid var(--line); background: var(--surface); }
.chat-main > .chat-composer { border: 1px solid var(--line); border-radius: var(--r-card); }
.chat-composer textarea { min-height: 64px; max-height: 200px; }
.chat-composer-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2); }
.chat-composer .btn { gap: var(--s1); }
.model-choice { margin-block: var(--s4); padding-bottom: var(--s4); border-bottom: 1px solid var(--line); }
.model-choice h4 { margin: 0 0 var(--s2); font-size: 15px; }
.model-choice .token-form { margin-top: var(--s3); }
.chat-hint { display: none; margin-top: calc(var(--s1) * -1); }
@media (pointer: fine) { .chat-hint { display: block; } }
@media (pointer: coarse) { .chat-composer .btn { min-height: 44px; min-width: 96px; } }
.chat-sensitive { display: inline-flex; align-items: center; gap: var(--s2); font-size: 13px; color: var(--text-2); }

/* attachments (M20 U5b): composer block, chips, and cards in the stream. Fixed thumbnail size. */
.chat-attach { display: grid; gap: var(--s2); }
.chat-attach-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.chat-composer.is-drag { outline: 2px dashed var(--accent); outline-offset: -4px; }
.attach-chips, .attach-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.attach-chips:empty { display: none; }
.attach-chip { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--s1) var(--s2); padding: var(--s2) var(--s3); border: 1px solid var(--line); border-radius: var(--r-control); background: var(--surface); font-size: 13px; }
.attach-chip[data-state="failed"] { border-color: var(--danger); }
.attach-chip .attach-name { font-weight: 600; max-width: 100%; min-width: 0; overflow-wrap: break-word; }
.attach-status { color: var(--text-2); }
.attach-chip[data-state="failed"] .attach-status { color: var(--danger); }
.attach-progress { width: 96px; height: 8px; accent-color: var(--accent); }
.attach-sensitive { display: inline-flex; align-items: center; gap: var(--s1); color: var(--text-2); }
.attach-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s1) var(--s2); min-width: 0; }
.attach-opts { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); }
.attach-opts .attach-progress[hidden] { display: none; }
.attach-error { margin: 0; color: var(--danger); font-size: 13px; }
.attach-cards { margin-top: var(--s2); }
.attach-card { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); font-size: 13px; }
.attach-card.is-purged { color: var(--muted); }
.attach-thumb { display: inline-block; line-height: 0; border: 1px solid var(--line); border-radius: var(--r-control); overflow: hidden; }
.attach-thumb img { width: 160px; height: 120px; max-width: 100%; object-fit: cover; background: var(--surface); }
.attach-file { display: inline-flex; align-items: center; gap: var(--s1); }
.attach-file .icon { width: 16px; height: 16px; }
.attach-manage { flex-basis: 100%; }
.attach-manage > summary { display: inline-flex; list-style: none; cursor: pointer; }
.attach-manage > summary::-webkit-details-marker { display: none; }
.attach-manage-body { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-top: var(--s2); padding: var(--s2) var(--s3); border: 1px solid var(--line); border-radius: var(--r-control); background: var(--surface); }
.attach-manage-body form { margin: 0; }
.attach-manage-body p { margin: 0; flex-basis: 100%; }
@media (pointer: coarse) { .chat-attach .btn, .attach-remove { min-height: 44px; min-width: 44px; } }

/* docked panel */
.chat-panel:not([hidden]) { display: flex; flex-direction: column; }
.chat-panel-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.chat-panel-head h2 { margin: 0 auto 0 0; font-size: 16px; }
.chat-panel .chat-model { padding: var(--s2) var(--s4); border-bottom: 1px solid var(--line); }
.chat-panel .chat-turn { margin: 0 var(--s3); }

@media (min-width: 1024px) {
  /* the conversation fills the viewport: the stream scrolls, the composer stays in sight */
  .chat-main { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h) - var(--s5) - var(--s7)); min-height: 520px; }
  .chat-main .chat-stream { flex: 1 1 auto; min-height: 160px; }
  .chat-main > * { flex: none; }
  .chat-main > .chat-stream { flex: 1 1 auto; }
}

@media (max-width: 1023px) {
  .chat-page { grid-template-columns: minmax(0, 1fr); }
  .chat-rail { position: static; }
  .chat-threads { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s2); }
  .chat-stream { max-height: none; overflow-y: visible; }
}

@media (max-width: 599px) {
  .chat-message { max-width: 94%; }
  .chat-header h1 { font-size: 18px; }
  .chat-stream { min-height: 200px; }
}

/* ==== U8 (notifications) =================================================================== */

.notice-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.notice-item { padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); }
.notice-item.is-unread { border-color: var(--accent); }
.notice-item p { margin: var(--s1) 0 var(--s2); color: var(--text-2); }
.notice-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2); }
.notice-head .muted { margin-left: auto; }
.notice-actions { display: flex; align-items: center; gap: var(--s2); }
.channels { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-items: start; }
.channel { display: grid; gap: var(--s3); }
.channel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.inline-form { display: grid; gap: var(--s2); }
.inline-form .form-actions { margin-top: 0; align-items: center; }
.push-box { display: grid; gap: var(--s2); justify-items: start; }
.sub-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s1); }
.sub-list li { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); font-size: 14px; }
.toggles td.center, .toggles th.center { text-align: center; }
.toggles input.narrow { width: 88px; text-align: right; }
.quiet-grid { display: grid; gap: var(--s3) var(--s4); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; margin-bottom: var(--s3); }
.check { display: flex; align-items: center; gap: var(--s2); min-height: 40px; font-size: 14px; }
@media (max-width: 599px) {
  .toggles td.center { justify-content: space-between; }
  .toggles input.narrow { width: 96px; }
  .notice-head .muted { margin-left: 0; }
}
.channels > .card { margin-top: 0; }
.notice-list.compact .notice-item { padding: var(--s2) var(--s4); }
.notice-list.compact .notice-head .muted { margin-left: 0; }
.notice-list.compact .grow { flex: 1 1 200px; min-width: 0; }
.quiet-grid .check { align-self: end; }
.inline-form + .inline-form, .card + .inline-form { margin-top: var(--s3); }
@media (max-width: 599px) {
  .table caption:not(.sr-only) { display: block; width: 100%; }
  .toggles td[data-label="이벤트"] { display: block; }
}

/* ==== M17 owner authentication on the M18 design (login, setup, reauth, account) ============ */

.bare-card.auth-wide { max-width: 760px; }
.bare-card h1 { font-size: 24px; }

.auth-brand { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s1) var(--s3); margin-bottom: var(--s5); padding-bottom: var(--s4); border-bottom: 1px solid var(--line); }
.auth-wordmark { font-size: 16px; font-weight: 700; letter-spacing: 0.16em; color: var(--text); }
.auth-sub { font-size: 13px; color: var(--muted); }
.auth-env { margin-left: auto; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; line-height: 20px; color: var(--text-2); }

.auth-head { margin-bottom: var(--s4); }
.auth-lead { margin: var(--s2) 0 0; color: var(--text-2); font-size: 14px; line-height: 1.7; }
.auth-head + .auth-alert, .auth-head + .auth-form, .auth-head + .auth-notice { margin-top: var(--s4); }
p.auth-lead:first-child { margin-top: 0; }

.auth-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); margin: 0 0 var(--s5); padding: 0; list-style: none; }
.auth-steps li { padding-top: var(--s2); border-top: 3px solid var(--line-strong); font-size: 12px; line-height: 1.4; color: var(--muted); }
.auth-steps li.is-done { border-top-color: var(--accent); }
.auth-steps li.is-current { border-top-color: var(--accent); color: var(--text); font-weight: 600; }
.auth-step-no { display: inline-block; min-width: 1.2em; font-variant-numeric: tabular-nums; }

.auth-alert, .auth-notice { margin: 0 0 var(--s4); }
.auth-alert { align-items: flex-start; }
.auth-alert .icon { margin-top: 3px; }

.auth-form .field { margin-bottom: var(--s4); }
.auth-form .field > label { font-size: 14px; color: var(--text); }
.bare-card input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) { min-height: 44px; font-size: 16px; }
.auth-actions { margin-top: var(--s5); }
.auth-actions .btn { width: 100%; min-height: 44px; font-size: 15px; }

.auth-check { display: flex; align-items: center; gap: var(--s3); min-height: 44px; padding: 0 var(--s3); border: 1px solid var(--line-strong); border-radius: var(--r-control); background: var(--surface-2); cursor: pointer; }
.auth-check input[type="checkbox"] { width: 20px; height: 20px; flex: none; }

.auth-foot { margin: var(--s5) 0 0; text-align: center; font-size: 14px; }
.auth-foot a, .auth-back a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s3); }
.auth-back { margin: calc(var(--s2) * -1) 0 var(--s3) calc(var(--s3) * -1); font-size: 14px; }

.auth-qr { display: grid; place-items: center; width: fit-content; max-width: 100%; margin: 0 auto var(--s4); padding: var(--s3); background: #ffffff; border: 1px solid var(--line-strong); border-radius: var(--r-card); }
.auth-qr svg { display: block; width: 100%; max-width: 240px; height: auto; aspect-ratio: 1; }
.auth-manual { margin: 0 0 var(--s2); text-align: center; font-size: 13px; color: var(--muted); }
.auth-secret { margin: 0 0 var(--s5); text-align: center; }
.auth-secret code { display: inline-block; max-width: 100%; padding: var(--s2) var(--s3); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-control); font-size: 16px; letter-spacing: 0.06em; overflow-wrap: break-word; user-select: all; }
.auth-again { margin-top: var(--s6); padding-top: var(--s5); border-top: 1px solid var(--line); }
.auth-again h2 { margin-bottom: var(--s1); }

.auth-codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); margin: 0 0 var(--s5); padding: 0; list-style: none; counter-reset: code; }
.auth-codes li { display: flex; align-items: center; min-height: 44px; padding: 0 var(--s3); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-control); counter-increment: code; }
.auth-codes li::before { content: counter(code); width: 1.6em; flex: none; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.auth-codes code { font-size: 15px; letter-spacing: 0.04em; overflow-wrap: break-word; user-select: all; }

.auth-section { margin-bottom: var(--s5); }
.auth-section h2 { margin-bottom: var(--s3); }
.bare-card .table-wrap { background: transparent; }
.bare-card .table { table-layout: fixed; }
.bare-card .table th, .bare-card .table td { white-space: normal; overflow-wrap: break-word; }
.auth-account-actions { display: flex; flex-wrap: wrap; gap: var(--s3); padding-top: var(--s4); border-top: 1px solid var(--line); }
.auth-account-actions .btn { min-height: 44px; white-space: normal; }

@media (max-width: 599px) {
  .bare { place-items: start center; padding: var(--s4) var(--s3); }
  .bare-card { padding: var(--s4); }
  .auth-codes { grid-template-columns: minmax(0, 1fr); }
  .auth-account-actions { flex-direction: column; }
  .auth-account-actions .btn { width: 100%; }
  .bare-card .table tr { padding: var(--s3) 0; }
  .bare-card .table td { flex-wrap: wrap; }
}
.bare-card .btn { min-height: 44px; }

/* ==== M19 U6 (settings, decision controls, mobile approval, review fixes) ============== */

/* settings sub navigation */
.subtabs { display: flex; flex-wrap: wrap; gap: var(--s1); margin: 0 0 var(--s4); border-bottom: 1px solid var(--line); }
.subtabs a {
  padding: var(--s2) var(--s3); margin-bottom: -1px; border-bottom: 2px solid transparent;
  color: var(--text-2); text-decoration: none; font-weight: 500; font-size: 14px;
}
.subtabs a:hover { color: var(--text); }
.subtabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* policy: one row per family, a segmented control on the right */
.policy-lead { margin: 0 0 var(--s3); }
.policy-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.policy-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
  padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card);
}
.policy-info { min-width: 0; }
.policy-info h3 { margin: 0; font-size: 15px; }
.policy-info p { margin: 2px 0 0; }
.policy-when { margin-top: var(--s1); }
.seg { display: inline-flex; flex: none; border: 1px solid var(--control); border-radius: 999px; overflow: hidden; }
.seg-form { display: contents; margin: 0; }
.seg-btn {
  min-height: 36px; min-width: 76px; padding: 0 var(--s3); border: 0; background: transparent;
  color: var(--text-2); font: inherit; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
}
.seg > :not(:first-child) { border-left: 1px solid var(--line-strong); }
.seg-form > .seg-btn { height: 100%; }
button.seg-btn:hover { background: var(--surface-2); color: var(--text); }
.seg-btn.is-current { font-weight: 700; cursor: default; }
.seg-btn.is-current.t-ok { background: var(--ok-bg); color: var(--ok); }
.seg-btn.is-current.t-warn { background: var(--warn-bg); color: var(--warn); }
.seg-btn.is-current.t-danger { background: var(--danger-bg); color: var(--danger); }
.guard-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.guard { display: grid; gap: 2px; margin: 0 !important; }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }

/* shortcut confirmation, result lines */
.shortcut-confirm { display: grid; gap: var(--s3); max-width: 640px; }
.shortcut-sentence { font-size: 17px; font-weight: 600; margin: 0; }
.shortcut-family { margin: 0; }
.form-actions-wide .btn { min-height: 44px; min-width: 140px; }
.result-lines { list-style: none; margin: var(--s3) 0; padding: 0; display: grid; gap: var(--s2); }
.result-line { display: flex; align-items: center; gap: var(--s3); margin: 0 !important; }

/* external model / login cards */
.model-card, .login-card { display: grid; gap: var(--s3); max-width: 760px; }
.model-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.model-head h3 { margin: 0; }
.model-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.token-form { padding-top: var(--s3); border-top: 1px solid var(--line); }
.token-form input { max-width: 100%; }

/* decision box: filter chips, richer cards, controls */
.filter-chips { display: flex; flex-wrap: wrap; gap: var(--s2); margin: 0 0 var(--s4); }
.filter-chips .chip { padding: 6px 14px; min-height: 36px; align-items: center; display: inline-flex; gap: 6px; background: var(--surface); border: 1px solid var(--line-strong); color: var(--text-2); }
.filter-chips .chip.is-active { background: var(--accent-weak); border-color: var(--accent); color: var(--text); font-weight: 600; }
.decision-stack { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.card-controls { display: grid; gap: var(--s2); margin-top: var(--s2); }
.control-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.once-form { margin: 0; }
.always-row { padding-top: var(--s2); border-top: 1px dashed var(--line); }
.always-pair { margin-top: var(--s4); padding-top: var(--s3); border-top: 1px dashed var(--line); }
.decisions-foot { margin-top: var(--s5); }
.reason-form summary { cursor: pointer; font-weight: 600; margin-bottom: var(--s2); }

/* the one-handed decision dock (approval detail; big 2x2 on phones) */
.decision-dock { margin: var(--s4) 0; padding: var(--s4); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-card); }
.dock-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s2); }
.dock-grid .once-form, .dock-grid .once-form .btn { width: 100%; }
.btn-big { min-height: 56px; width: 100%; font-size: 16px; font-weight: 600; justify-content: center; }
.dock-note { margin: var(--s2) 0 0; }

/* daily report as a list */
.report-title { margin: 0 0 var(--s2); font-size: 13px; color: var(--muted); }
.report-list { list-style: none; margin: 0 0 var(--s2); padding: 0; display: grid; gap: var(--s1); }
.report-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s2); padding: 6px 0; border-bottom: 1px solid var(--line); }
.report-row:last-child { border-bottom: 0; }
.report-label { flex: none; min-width: 6em; font-size: 13px; color: var(--muted); }
.report-value { font-weight: 600; }
.report-row.t-ok .report-value { color: var(--ok); }
.report-row.t-warn .report-value { color: var(--warn); }
.report-row.t-danger .report-value { color: var(--danger); }
.report-detail { flex-basis: 100%; padding-left: calc(6em + var(--s2)); }

/* notifications: the whole card opens (X6) */
.notice-item { position: relative; }
.notice-link { color: var(--text); text-decoration: none; }
.notice-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--r-card); }
.notice-actions { position: relative; z-index: 1; }

/* X7: KPI tiles fill the row */
.kpi-grid { grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); }

/* X8: the pending turn is one calm line */
.chat-turn { display: flex; align-items: center; gap: var(--s2); padding: var(--s1) var(--s3); }
.chat-turn[hidden] { display: none; }
.chat-turn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: nocturne-pulse 1.6s ease-in-out infinite; }

/* X4: the phone chat shows the list or one conversation */
.chat-back { display: none; }

@media (max-width: 1023px) {
  .policy-row { flex-direction: column; align-items: stretch; }
  .seg { width: 100%; }
  .seg > *, .seg-form > .seg-btn { flex: 1 1 0; }
  .seg-form { display: contents; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}

@media (max-width: 599px) {
  /* X9: the tab bar spreads whatever it has evenly */
  .tabbar { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 1fr; }
  /* the docked chat panel does not exist on phones (the chat tab replaces it) */
  .chat-panel, [data-action="toggle-chat"] { display: none !important; }
  .chat-page.view-thread .chat-rail { display: none; }
  .chat-page.view-list .chat-main { display: none; }
  .chat-page.view-thread .chat-back { display: inline-flex; align-items: center; min-height: 44px; font-size: 14px; }
  .chat-page.view-list .chat-threads { grid-template-columns: 1fr; }
  .chat-page.view-list .chat-thread { min-height: 56px; }
  .chat-page.view-thread .chat-composer { position: sticky; bottom: 56px; z-index: 5; }
  .dock-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .decision-dock { position: sticky; bottom: 60px; z-index: 6; margin-left: calc(-1 * var(--s4)); margin-right: calc(-1 * var(--s4)); border-radius: 0; border-left: 0; border-right: 0; padding-bottom: var(--s3); }
  .decision-stack { grid-template-columns: minmax(0, 1fr); }
  .control-row .btn { min-height: 44px; }
  .filter-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: var(--s1); }
  .filter-chips .chip { flex: none; }
  .report-detail { padding-left: 0; }
  .form-actions-wide .btn { flex: 1 1 100%; min-height: 52px; }
}

.check-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; min-width: 0; }
.check-list li { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.check-name { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.dock-grid .btn-ghost, .control-row .btn-ghost { border: 1px solid var(--line-strong); }
