/* Work OS PWA — 사이드바 통제탑. 다크 기본 + 라이트 대응 + 수동 3-state 토글.
   식별은 아이콘+라벨, 색은 상태(good/warn/critical)에 예약 (dataviz 규칙). */
:root {
  --bg: #0d1220;
  --bg-2: #0a0f1a;
  --surface: #161d2e;
  --surface-2: #1e2739;
  --surface-3: #263149;
  --ink: #f4f6fb;
  --ink-2: #a7b0c4;
  --ink-3: #6b7691;
  --line: #29334a;
  --line-2: #333f5a;
  --accent: #8b93ff;
  --accent-2: #b18cff;
  --accent-ink: #c7ccff;
  --accent-tint: rgba(139, 147, 255, 0.13);
  --good: #34d399;
  --good-tint: rgba(52, 211, 153, 0.14);
  --warn: #fbbf24;
  --warn-tint: rgba(251, 191, 36, 0.15);
  --critical: #fb7185;
  --critical-tint: rgba(251, 113, 133, 0.15);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.22);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --radius: 16px;
  --radius-sm: 11px;
  --sidebar-w: 15.5rem;
  --sidebar-rail: 3.75rem;
}
/* 라이트 토큰 — 두 조건에서 공유: (시스템 라이트 & dark 강제 아님) 또는 (light 강제).
   data-theme는 head 인라인 스크립트가 첫 페인트 전에 세팅(FOUC 방지). */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef1f7; --bg-2: #e6eaf2; --surface: #ffffff; --surface-2: #f4f6fb; --surface-3: #eaeef6;
    --ink: #131826; --ink-2: #55607a; --ink-3: #8a94ad; --line: #e3e8f1; --line-2: #d6dce8;
    --accent: #5b5ef0; --accent-2: #8b5cf6; --accent-ink: #4f46e5; --accent-tint: rgba(91, 94, 240, 0.09);
    --good: #059669; --good-tint: rgba(5, 150, 105, 0.1); --warn: #b45309; --warn-tint: rgba(180, 83, 9, 0.1);
    --critical: #dc2626; --critical-tint: rgba(220, 38, 38, 0.09);
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 20px rgba(16, 24, 40, 0.07);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  }
}
:root[data-theme="light"] {
  --bg: #eef1f7; --bg-2: #e6eaf2; --surface: #ffffff; --surface-2: #f4f6fb; --surface-3: #eaeef6;
  --ink: #131826; --ink-2: #55607a; --ink-3: #8a94ad; --line: #e3e8f1; --line-2: #d6dce8;
  --accent: #5b5ef0; --accent-2: #8b5cf6; --accent-ink: #4f46e5; --accent-tint: rgba(91, 94, 240, 0.09);
  --good: #059669; --good-tint: rgba(5, 150, 105, 0.1); --warn: #b45309; --warn-tint: rgba(180, 83, 9, 0.1);
  --critical: #dc2626; --critical-tint: rgba(220, 38, 38, 0.09);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 20px rgba(16, 24, 40, 0.07);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Noto Sans KR", sans-serif;
  background: var(--bg); color: var(--ink); min-height: 100dvh;
  line-height: 1.45; letter-spacing: -0.006em; -webkit-font-smoothing: antialiased;
}
.muted { color: var(--ink-2); font-size: 0.82rem; }
.pad { padding: 18px; }

/* ---- 셸: 사이드바 + 본문 ---- */
.shell {
  display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh;
  transition: grid-template-columns 0.2s ease;
}
:root[data-sb="rail"] .shell { grid-template-columns: var(--sidebar-rail) 1fr; }
@media (prefers-reduced-motion: reduce) { .shell { transition: none; } }

/* ---- 사이드바 ---- */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
  position: sticky; top: 0; height: 100dvh;
  padding: calc(12px + env(safe-area-inset-top)) 10px 12px;
}
.sidebar-head { display: flex; align-items: center; gap: 9px; padding: 4px 4px 12px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff; box-shadow: 0 2px 10px var(--accent-tint);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-name { font-weight: 750; font-size: 1.05rem; letter-spacing: -0.02em; white-space: nowrap; flex: 1; min-width: 0; }
.nav { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-3); padding: 2px 10px 4px; white-space: nowrap;
}
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 11px; border-radius: 10px; border: 0; background: none;
  color: var(--ink-2); font-size: 0.92rem; font-weight: 550; cursor: pointer;
  position: relative; transition: background 0.15s, color 0.15s; text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { color: var(--accent); background: var(--accent-tint); font-weight: 650; }
.nav-icon { width: 20px; height: 20px; flex-shrink: 0; display: grid; place-items: center; }
.nav-icon svg { width: 20px; height: 20px; }
.nav-label { white-space: nowrap; overflow: hidden; }
.nav-empty { padding: 6px 11px; color: var(--ink-3); font-size: 0.82rem; }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
.sb-collapse { margin-left: auto; }
:root[data-sb="rail"] .sb-collapse svg { transform: rotate(180deg); }
/* 모바일 드로어에서만 노출. .icon-btn(display:grid)이 뒤에 선언돼 동급 셀렉터는 지므로 복합 셀렉터로 고정 */
.icon-btn.drawer-close { display: none; }

/* rail(축소) 모드: 라벨 숨기고 아이콘만 */
:root[data-sb="rail"] .brand-name,
:root[data-sb="rail"] .nav-label,
:root[data-sb="rail"] .nav-group-label,
:root[data-sb="rail"] .nav-empty { display: none; }
:root[data-sb="rail"] .nav-item { justify-content: center; padding: 9px 0; }
:root[data-sb="rail"] .sidebar-head { justify-content: center; }

/* ---- 본문 컬럼 ---- */
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 18px 10px;
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--bg) 62%, transparent); backdrop-filter: blur(6px);
}
.topbar h1 { font-size: 1.22rem; font-weight: 700; letter-spacing: -0.02em; flex: 1; min-width: 3.2em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } /* min-width: 제목이 시계·아이콘에 짓눌리지 않게 */
/* 프로필 메뉴 내비게이션이 제목으로 포커스를 옮긴다 — 키보드 사용자는 링이 보여야 한다 (WCAG focus-visible).
   마우스 클릭 포커스엔 안 뜨고 키보드 경로에만 뜬다. outline:none 전면 제거 금지 (Sol 지적) */
.topbar h1:focus { outline: none; }
.topbar h1:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
#clock { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex-shrink: 1; }
/* 좁은 화면: 날짜는 폰 상태바에 이미 있으니 갱신 시각만 남긴다 */
@media (max-width: 640px) { #clock .clock-date { display: none; } }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 0; background: none;
  color: var(--ink-2); display: grid; place-items: center; cursor: pointer;
  position: relative; flex-shrink: 0; transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }
.drawer-toggle { display: none; }

main { padding: 6px 16px 24px; display: grid; gap: 13px; }
main > *, .card > * { min-width: 0; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
main > * { animation: rise 0.26s cubic-bezier(0.22, 0.61, 0.36, 1) both; }
main > *:nth-child(2) { animation-delay: 0.03s; }
main > *:nth-child(3) { animation-delay: 0.06s; }
main > *:nth-child(4) { animation-delay: 0.09s; }
@media (prefers-reduced-motion: reduce) { main > * { animation: none; } }

/* ---- 모바일: 사이드바 오프캔버스 드로어 ---- */
@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); max-width: 82vw; z-index: 20;
    transform: translateX(-100%); transition: transform 0.22s cubic-bezier(0.22, 0.61, 0.36, 1);
    box-shadow: var(--shadow);
  }
  :root[data-drawer="open"] .sidebar { transform: translateX(0); }
  :root[data-sb="rail"] .sidebar { /* 모바일은 rail 무시, 항상 전체폭 드로어 */
    --_x: 0; }
  :root[data-sb="rail"] .brand-name,
  :root[data-sb="rail"] .nav-label,
  :root[data-sb="rail"] .nav-group-label,
  :root[data-sb="rail"] .nav-empty { display: revert; }
  :root[data-sb="rail"] .nav-item { justify-content: flex-start; padding: 9px 11px; }
  .sb-collapse { display: none; }
  .icon-btn.drawer-close { display: grid; margin-left: auto; }
  .drawer-toggle { display: grid; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
.backdrop {
  position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px); opacity: 0; transition: opacity 0.22s;
}
:root[data-drawer="open"] .backdrop { opacity: 1; }
.backdrop[hidden] { display: none; }

/* ---- KPI 타일 ---- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.tile {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 15px 14px;
  box-shadow: var(--shadow-sm); position: relative; overflow: hidden; display: grid; gap: 7px;
}
.tile-top { display: flex; align-items: center; justify-content: space-between; }
.tile-icon {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; background: var(--accent-tint); color: var(--accent-ink);
}
.tile-icon svg { width: 19px; height: 19px; }
.tile-icon.is-good { background: var(--good-tint); color: var(--good); }
.tile-icon.is-warn { background: var(--warn-tint); color: var(--warn); }
.tile-icon.is-critical { background: var(--critical-tint); color: var(--critical); }
.tile .num { font-size: 1.85rem; font-weight: 750; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.tile .num .sub { font-size: 0.95rem; font-weight: 600; color: var(--ink-3); letter-spacing: -0.01em; }
.tile .label { color: var(--ink-2); font-size: 0.8rem; font-weight: 500; }
.tile .meter { height: 5px; background: var(--surface-3); border-radius: 999px; overflow: hidden; margin-top: 1px; }
.tile .meter > div { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* 데스크탑에선 타일 4열까지 여유롭게 */
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(4, 1fr); } }

/* ---- 카드 ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 11px; box-shadow: var(--shadow-sm); }
.card h2 { font-size: 0.78rem; color: var(--ink-3); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; display: flex; align-items: center; gap: 8px; }
.row { display: flex; gap: 10px; align-items: baseline; }
.row .grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: ui-monospace, "SF Mono", monospace; font-size: 0.76rem; color: var(--accent-ink); background: var(--accent-tint); padding: 1px 6px; border-radius: 6px; flex-shrink: 0; letter-spacing: 0; }
.card .row + .row { border-top: 1px solid var(--line); padding-top: 9px; }
.chip { font-size: 0.72rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--ink-2); flex-shrink: 0; background: var(--surface-2); }
.chip.done { color: var(--good); border-color: transparent; background: var(--good-tint); }
.chip.pending { color: var(--warn); border-color: transparent; background: var(--warn-tint); }
.chip.critical { color: var(--critical); border-color: transparent; background: var(--critical-tint); }
.progress { height: 7px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width 0.5s cubic-bezier(0.22, 0.61, 0.36, 1); }
.notif { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 13px; background: var(--surface-2); display: grid; gap: 3px; transition: border-color 0.15s; }
.notif.unread { border-color: var(--accent); background: var(--accent-tint); }
.notif.unread .title::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 999px; background: var(--accent); margin-right: 7px; vertical-align: middle; }
.notif .title { font-weight: 650; font-size: 0.92rem; }
.notif .body { color: var(--ink-2); font-size: 0.85rem; }

/* ---- 버튼 ---- */
button.action { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border: 0; border-radius: 13px; padding: 13px; font-size: 0.95rem; font-weight: 650; width: 100%; cursor: pointer; box-shadow: 0 4px 14px var(--accent-tint); transition: transform 0.12s, filter 0.12s; }
button.action:active { transform: translateY(1px) scale(0.99); filter: brightness(1.05); }
button.action:disabled { opacity: 0.5; box-shadow: none; }

/* ---- 알림 배지 (사이드바 nav + 우상단 아이콘 공통) ---- */
.badge {
  background: var(--critical); color: #fff; font-size: 0.6rem; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 999px; padding: 0 4px;
  display: grid; place-items: center; box-shadow: 0 0 0 2px var(--surface);
}
.nav-item .badge { position: absolute; top: 7px; left: 24px; }
.icon-btn .badge { position: absolute; top: 3px; right: 3px; }
:root[data-sb="rail"] .nav-item .badge { left: auto; right: 8px; top: 4px; }

/* ---- 승격 카드 (통제탑 t3) ---- */
.candidate { border-top: 1px solid var(--line); padding: 12px 0 2px; }
.candidate:first-of-type { border-top: 0; padding-top: 2px; }
.candidate .title { font-weight: 650; font-size: 0.98rem; }
.candidate .body { margin: 3px 0; font-size: 0.89rem; color: var(--ink-2); }
.candidate .body b, .candidate .body strong { color: var(--ink); }
.action.small { padding: 8px 15px; font-size: 0.88rem; font-weight: 650; width: auto; display: inline-block; margin: 9px 7px 0 0; border-radius: 10px; }
.action.ghost { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line-2); box-shadow: none; }
.action.ghost:active { background: var(--surface-3); }

/* ---- 설정 페이지 ---- */
.settings-section { display: grid; gap: 10px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.settings-row .desc { color: var(--ink-2); font-size: 0.82rem; margin-top: 2px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 2px; gap: 2px; }
.seg button { border: 0; background: none; color: var(--ink-2); font-size: 0.82rem; font-weight: 600; padding: 6px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--accent); color: #fff; }

/* ---- 프로필 메뉴 (우상단 아바타) ---- */
.profile-wrap { position: relative; }
.avatar {
  width: 28px; height: 28px; border-radius: 999px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 0.82rem; font-weight: 750;
  display: grid; place-items: center; letter-spacing: 0;
}
.menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 30;
  min-width: 230px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); display: grid; gap: 2px;
}
.menu[hidden] { display: none; }
.menu-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-head .avatar { width: 34px; height: 34px; font-size: 0.95rem; }
.menu-name { font-weight: 650; font-size: 0.92rem; }
.menu-head .desc { color: var(--ink-3); font-size: 0.78rem; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: 8px; background: none;
  color: var(--ink-2); font-size: 0.9rem; font-weight: 550; cursor: pointer; text-align: left;
  transition: background 0.15s, color 0.15s;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); color: var(--ink); }
.menu-item .nav-icon { width: 18px; height: 18px; }
.menu-item .nav-icon svg { width: 18px; height: 18px; }
.menu-item .desc { margin-left: auto; color: var(--ink-3); font-size: 0.78rem; }

/* ---- AI 사용량 뷰 ---- */
.usage-account { border-top: 1px solid var(--line); padding: 12px 0 4px; display: grid; gap: 8px; }
.usage-account:first-of-type { border-top: 0; padding-top: 2px; }
.usage-account .title { font-weight: 650; font-size: 0.95rem; word-break: break-all; }
.usage-row { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; flex-wrap: wrap; }
.usage-label { width: 74px; flex-shrink: 0; color: var(--ink-2); }
.usage-meter { flex: 1; height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; min-width: 60px; }
.usage-meter > div { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.usage-meter.is-warn > div { background: var(--warn); }
.usage-meter.is-critical > div { background: var(--critical); }
.usage-pct { font-variant-numeric: tabular-nums; font-weight: 650; width: 40px; text-align: right; flex-shrink: 0; }
.usage-reset { flex-shrink: 0; font-size: 0.76rem; }
/* 좁은 폭에선 숨기지 않고 둘째 줄로 — 리셋 시각은 모바일에서 오히려 핵심 데이터 (Sol 3R: display:none 금지) */
@media (max-width: 480px) { .usage-reset { flex-basis: 100%; padding-left: 84px; margin-top: -4px; } }
