/* TUTAS — design system.
   Layout: fixed left sidebar + sticky topbar on desktop; topbar + bottom tab bar + drawer on mobile. */
:root {
  --bg: #F3F5F7; --surface: #FFFFFF; --surface-2: #F8F9FB; --ink: #0F1A24; --ink-2: #455566; --ink-3: #78889A;
  --line: #E2E7ED; --line-2: #EDF0F4;
  --accent: #0A7A69; --accent-ink: #FFFFFF; --accent-soft: #E2F3EF; --accent-strong: #075E51;
  --wood: #B7791F; --wood-soft: #FBF1DD;
  --ok: #12805C; --ok-soft: #E1F4EB; --warn: #B54708; --warn-soft: #FEF0D9; --bad: #C0362C; --bad-soft: #FDE8E6;
  --info: #2457C5; --info-soft: #E6EEFC; --neutral-soft: #EBEEF2;
  --shadow: 0 1px 2px rgba(15,26,36,.05), 0 4px 16px rgba(15,26,36,.04);
  --shadow-lg: 0 20px 60px rgba(15,26,36,.22);
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-head: 'Manrope', 'Inter', system-ui, sans-serif;
  --r: 12px; --r-sm: 8px; --sidebar: 268px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0C1218; --surface: #131B23; --surface-2: #17212B; --ink: #EAF0F5; --ink-2: #A8B5C2; --ink-3: #7B8A99;
    --line: #25313C; --line-2: #1D2832; --accent: #35C2A8; --accent-ink: #06231D; --accent-soft: #123A33; --accent-strong: #5AD6BE;
    --wood: #E2A94B; --wood-soft: #3A2D14; --ok: #4CC796; --ok-soft: #12362A; --warn: #F0A15A; --warn-soft: #3B2A12;
    --bad: #F08379; --bad-soft: #3D1B18; --info: #7FA6F5; --info-soft: #172B52; --neutral-soft: #202B35;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 20px 60px rgba(0,0,0,.6); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0C1218; --surface: #131B23; --surface-2: #17212B; --ink: #EAF0F5; --ink-2: #A8B5C2; --ink-3: #7B8A99;
  --line: #25313C; --line-2: #1D2832; --accent: #35C2A8; --accent-ink: #06231D; --accent-soft: #123A33; --accent-strong: #5AD6BE;
  --wood: #E2A94B; --wood-soft: #3A2D14; --ok: #4CC796; --ok-soft: #12362A; --warn: #F0A15A; --warn-soft: #3B2A12;
  --bad: #F08379; --bad-soft: #3D1B18; --info: #7FA6F5; --info-soft: #172B52; --neutral-soft: #202B35;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 20px 60px rgba(0,0,0,.6); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: auto; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); background: var(--surface); z-index: 60; }
h1, h2, h3, h4 { font-family: var(--font-head); margin: 0; letter-spacing: -.01em; text-wrap: balance; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num, td.num, .kpi-value { font-variant-numeric: tabular-nums; }

/* App shell */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: env(safe-area-inset-top, 0px); height: calc(100vh - env(safe-area-inset-top, 0px)); background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 14px 14px max(14px, env(safe-area-inset-left, 0px)); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-family: var(--font-head); font-weight: 800; font-size: 17px; }
.brand-name { font-family: var(--font-head); font-weight: 800; font-size: 16px; letter-spacing: .02em; }
.brand-name small { display: block; font-family: var(--font-body); font-weight: 500; font-size: 11px; color: var(--ink-3); letter-spacing: 0; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); padding: 14px 10px 6px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 9px; color: var(--ink-2); font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.nav a .count { margin-left: auto; font-size: 11px; font-weight: 700; background: var(--bad); color: #fff; border-radius: 999px; padding: 1px 7px; }
.sidebar-foot { margin-top: auto; padding-top: 14px; }
.plan-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; font-size: 12px; color: var(--ink-2); }
.plan-card b { color: var(--ink); display: block; margin-bottom: 2px; font-size: 13px; }

.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 40; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-in { display: flex; align-items: center; gap: 12px; height: 62px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); }
.topbar h1 { font-size: 19px; font-weight: 800; white-space: nowrap; }
.search { position: relative; flex: 1; max-width: 420px; margin-left: 12px; }
.search input { width: 100%; height: 38px; padding: 0 12px 0 36px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.search .ic { position: absolute; left: 11px; top: 10px; color: var(--ink-3); }
.search-results { position: absolute; top: 44px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-lg); padding: 6px; max-height: 360px; overflow: auto; z-index: 50; }
.search-results a { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.search-results a:hover { background: var(--surface-2); }
.search-results small { color: var(--ink-3); }
.spacer { flex: 1; }
.icon-btn { position: relative; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; color: var(--ink-2); }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn .dot { position: absolute; top: 7px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); border: 2px solid var(--surface); }
.menu-btn { display: none; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 3px 10px 3px 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.user-chip span { font-weight: 600; font-size: 13px; }

.page { padding: 24px max(24px, env(safe-area-inset-right, 0px)) 48px max(24px, env(safe-area-inset-left, 0px)); max-width: 1480px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h2 { font-size: 24px; font-weight: 800; }
.page-head p { color: var(--ink-2); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Primitives */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 0; }
.card-h h3 { font-size: 15px; font-weight: 700; }
.card-b { padding: 16px 18px 18px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: grid; gap: 16px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 13px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--neutral-soft); color: var(--ink-2); }
.chip.ok { background: var(--ok-soft); color: var(--ok); } .chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); } .chip.info { background: var(--info-soft); color: var(--info); }
.chip.accent { background: var(--accent-soft); color: var(--accent-strong); } .chip.wood { background: var(--wood-soft); color: var(--wood); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; background: var(--accent-soft); color: var(--accent-strong); }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }
.muted { color: var(--ink-2); } .faint { color: var(--ink-3); } .small { font-size: 12px; } .bold { font-weight: 700; }
.row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row.wrap { flex-wrap: wrap; } .between { justify-content: space-between; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.progress { height: 6px; border-radius: 99px; background: var(--neutral-soft); overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.progress.warn i { background: var(--warn); } .progress.bad i { background: var(--bad); }

/* KPI */
.kpi { padding: 16px 18px; }
.kpi-top { display: flex; justify-content: space-between; align-items: center; color: var(--ink-2); font-weight: 500; }
.kpi-ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-strong); }
.kpi-value { font-family: var(--font-head); font-size: 26px; font-weight: 800; margin: 10px 0 4px; letter-spacing: -.02em; }
.delta { font-size: 12px; font-weight: 600; } .delta.up { color: var(--ok); } .delta.down { color: var(--bad); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
td { padding: 12px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }

/* Controls */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.input, select.input, textarea.input { height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); width: 100%; }
textarea.input { height: auto; padding: 10px 12px; min-height: 80px; resize: vertical; }
.toolbar .input { width: auto; min-width: 0; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--ink-2); font-weight: 600; font-size: 13px; }
.tab:hover { background: var(--surface-2); } .tab.active { background: var(--accent-soft); color: var(--accent-strong); }
.tab .n { opacity: .65; margin-left: 4px; font-weight: 500; }
.field { display: grid; gap: 5px; } .field label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; } .form-grid .full { grid-column: 1 / -1; }
.switch { position: relative; width: 40px; height: 23px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + i { background: var(--accent); } .switch input:checked + i::after { transform: translateX(17px); }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line-2); }
.list-item:last-child { border-bottom: 0; }
.empty { padding: 36px 18px; text-align: center; color: var(--ink-3); }

/* Kanban */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(258px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.col { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; }
.col.over { outline: 2px dashed var(--accent); }
.col-h { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px 8px; font-weight: 700; font-size: 13px; }
.col-b { display: grid; gap: 8px; padding: 6px 10px 12px; min-height: 60px; }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; display: grid; gap: 8px; cursor: grab; }
.kcard:hover { border-color: var(--accent); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }
.chart-wrap { width: 100%; overflow: hidden; } .chart-wrap svg { display: block; width: 100%; height: auto; }

/* Overlays */
.overlay { position: fixed; inset: 0; background: rgba(10,18,26,.5); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 16px; width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: var(--shadow-lg); }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-h h3 { font-size: 17px; } .modal-b { padding: 20px 22px; } .modal-f { padding: 14px 22px 20px; display: flex; justify-content: flex-end; gap: 8px; }
.drawer-overlay { position: fixed; inset: 0; background: rgba(10,18,26,.45); z-index: 100; display: flex; justify-content: flex-end; }
.drawer { width: min(480px, 100%); height: 100%; background: var(--surface); overflow: auto; box-shadow: var(--shadow-lg); padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
.toasts { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 200; display: grid; gap: 8px; }
.toast { background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 10px; font-weight: 500; box-shadow: var(--shadow-lg); animation: rise .2s ease; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* Chat */
.chat { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: calc(100vh - 230px); min-height: 460px; }
.msgs { overflow-y: auto; padding: 18px; display: grid; gap: 14px; align-content: start; }
.msg { max-width: 82%; padding: 11px 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); white-space: pre-wrap; }
.msg.me { justify-self: end; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.suggest { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 18px 12px; }

.bottom-nav { display: none; }
.scrim { display: none; }

@media (max-width: 1180px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-main { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 900px) {
  .app { display: block; }
  .sidebar { position: fixed; z-index: 90; left: 0; top: 0; bottom: 0; height: auto; width: min(300px, 86vw); transform: translateX(-102%); transition: transform .2s; padding-top: calc(18px + env(safe-area-inset-top, 0px)); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(10,18,26,.45); z-index: 80; }
  .menu-btn { display: grid; }
  .topbar-in { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .page { padding: 18px max(16px, env(safe-area-inset-right, 0px)) 96px max(16px, env(safe-area-inset-left, 0px)); }
  .search, .user-chip span { display: none; }
  .topbar h1 { font-size: 17px; overflow: hidden; text-overflow: ellipsis; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 70; background: var(--surface); border-top: 1px solid var(--line); padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); }
  .bottom-nav a, .bottom-nav button { display: grid; justify-items: center; gap: 2px; padding: 6px 0; border: 0; background: none; color: var(--ink-3); font-size: 11px; font-weight: 600; border-radius: 10px; }
  .bottom-nav .active { color: var(--accent-strong); background: var(--accent-soft); }
  .g3, .g2 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .chat { height: calc(100vh - 300px); }
  .msg { max-width: 92%; }
  .toasts { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); left: 16px; right: 16px; }
}
@media (max-width: 520px) { .g4 { grid-template-columns: minmax(0, 1fr); } .kpi-value { font-size: 23px; } .page-head h2 { font-size: 21px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
