:root {
  color-scheme: light dark;
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef3f0;
  --text: #14211c;
  --muted: #5a6b63;
  --line: #dbe3de;
  --brand: #0c3b2e;
  --accent: #0f7a55;
  --accent-text: #ffffff;
  --gold: #8a6410;
  --danger: #b3261e;
  --danger-bg: #fcecea;
  --warn: #7a5200;
  --warn-bg: #fff3d6;
  --ok: #0f6b45;
  --ok-bg: #e2f4ea;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 40 30 / 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1512;
    --surface: #15201c;
    --surface-2: #1c2b25;
    --text: #e8f0ec;
    --muted: #9db0a7;
    --line: #29392f;
    --brand: #0a2a21;
    --accent: #3ec48d;
    --accent-text: #06241a;
    --gold: #e2b457;
    --danger: #ff8f86;
    --danger-bg: #3a1c1a;
    --warn: #f0c366;
    --warn-bg: #36290d;
    --ok: #6fdcaa;
    --ok-bg: #12332a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Tamil", "Nirmala UI", sans-serif;
}
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
a { color: var(--accent); }
.boot { padding: 48px 16px; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }

/* Controls */
button, .button {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  min-height: 40px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.danger { color: var(--danger); }
.small { min-height: 32px; padding: 4px 10px; font-size: 0.85rem; }
.link { border: 0; background: none; color: var(--accent); padding: 4px; min-height: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  font: inherit;
  font-size: 16px;
  width: 100%;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  min-height: 42px;
}
textarea { resize: vertical; min-height: 90px; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); flex: none; margin: 0; }
.field { display: grid; gap: 5px; }
.field > span { font-weight: 600; font-size: 0.85rem; }
.hint { color: var(--muted); font-size: 0.83rem; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { margin-top: 2px; }

/* Shell */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--brand);
  color: #e8f3ee;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; }
.logo img { width: 34px; height: 34px; border-radius: 9px; border: 1px solid rgb(255 255 255 / 0.2); }
.logo small { display: block; font-weight: 400; opacity: 0.7; font-size: 0.75rem; }
.nav-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: inherit;
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 9px;
}
.nav-link:hover { background: rgb(255 255 255 / 0.08); }
.nav-link[aria-current="page"] { background: rgb(255 255 255 / 0.16); font-weight: 700; }
.count { background: #e2b457; color: #1c1503; border-radius: 99px; font-size: 0.72rem; font-weight: 700; padding: 0 7px; }
.sidebar button { margin-top: auto; background: transparent; color: inherit; border-color: rgb(255 255 255 / 0.25); }
.tabbar { display: none; }
main { padding: 24px; width: 100%; max-width: 1080px; margin: 0 auto; }
.view { display: grid; gap: 18px; align-content: start; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; justify-content: space-between; }
.page-head p { color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.spread { justify-content: space-between; }
.grow { flex: 1 1 180px; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
}
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; color: inherit; text-decoration: none; }
.tile strong { display: block; font-size: 1.7rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 0.83rem; }
.tile.attention strong { color: var(--gold); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: 12px; align-items: flex-start; padding: 11px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.item-body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 0.83rem; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.done .item-title { text-decoration: line-through; color: var(--muted); }
.empty { color: var(--muted); padding: 6px 0; }

.badge { display: inline-block; border-radius: 99px; padding: 1px 9px; font-size: 0.75rem; font-weight: 600; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }

.notice { border-radius: 11px; padding: 11px 14px; background: var(--surface-2); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.danger { background: var(--danger-bg); color: var(--danger); }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border-radius: 11px; padding: 12px 14px; }
.issues { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.tabs button { white-space: nowrap; }
.tabs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--line); vertical-align: top; }
thead th { border-top: 0; color: var(--muted); font-weight: 600; font-size: 0.78rem; }
td.number, th.number { text-align: right; font-variant-numeric: tabular-nums; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.timeline li { display: grid; grid-template-columns: 76px 1fr; gap: 10px; }
.timeline time { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }

progress { width: 100%; height: 8px; accent-color: var(--accent); }

/* Assistant */
.chat { display: grid; gap: 10px; align-content: start; min-height: 220px; max-height: 55vh; overflow-y: auto; }
.bubble { border-radius: 14px; padding: 10px 14px; max-width: min(100%, 680px); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.user { justify-self: end; background: var(--accent); color: var(--accent-text); }
.bubble.assistant { justify-self: start; background: var(--surface-2); }
.bubble.error { justify-self: start; background: var(--danger-bg); color: var(--danger); }

/* Dialog */
dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  width: min(620px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  padding: 20px;
}
dialog::backdrop { background: rgb(5 15 10 / 0.55); }
dialog form { display: grid; gap: 14px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); border-radius: 11px; padding: 11px 15px; box-shadow: 0 6px 20px rgb(0 0 0 / 0.25); }
.toast.error { background: #8f1d17; color: #fff; }

/* Sign-in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #0c3b2e, #123f55); }
.signin .card { width: min(400px, 100%); padding: 24px; }
.signin form { display: grid; gap: 14px; }

@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  main { padding: 16px 16px 96px; }
  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    inset: auto 0 0 0;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 20;
  }
  .tabbar a, .tabbar button {
    border: 0;
    border-radius: 0;
    background: none;
    color: var(--muted);
    min-height: 58px;
    display: grid;
    place-items: center;
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
    padding: 4px;
  }
  .tabbar [aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
  #toasts { bottom: 78px; }
  .menu-list { display: grid; gap: 8px; }
}
