/* Kantin Analytics v2 -- ported 1:1 from DESIGN_SYSTEM.md "CroiFac/NeuroDent" (§1-11) */

:root {
  --bg: #FFFFFF;
  --card: #FFFFFF;
  --surface: rgba(255,255,255,0.68);
  --surface-2: #F5F6FA;
  --text: #16181D;
  --hint: #5F6673;

  --accent: #5B6BFF;
  --accent-2: #8E7CFF;
  --accent-weak: rgba(91,107,255,0.10);

  --success: #17B978;
  --danger:  #F4595B;
  --warning: #E9A23B;

  --border: rgba(46,54,78,0.12);
  --chart-grid: rgba(46,54,78,0.08);
  --shadow: 0 1px 2px rgba(20,24,38,0.05), 0 8px 24px rgba(20,24,38,0.06);
  --nav-space: 76px;

  --tile-1: #EEF0FF; --tile-2: #E7FBF3; --tile-3: #FFF0EF;
  --tile-4: #F3EEFF; --tile-5: #FFF7E8; --tile-6: #EAF6FF;

  --s1:#5B6BFF; --s2:#17B978; --s3:#E9A23B; --s4:#F4595B; --s5:#8E7CFF;
}

:root[data-theme="dark"] {
  --bg:#0E1017; --card:#181B23; --surface:#21252F; --surface-2:#21252F;
  --text:#ECEFF6; --hint:#A3ACBD;
  --accent:#7A87FF; --accent-2:#9E8CFF; --accent-weak:rgba(122,135,255,0.16);
  --success:#2FD695; --danger:#FF7173; --warning:#F0B860;
  --border:rgba(163,172,189,0.16); --chart-grid:rgba(163,172,189,0.12);
  --shadow:0 1px 2px rgba(0,0,0,0.4), 0 8px 28px rgba(0,0,0,0.5);
  --tile-1:#1E2233; --tile-2:#16281F; --tile-3:#2A1C1E;
  --tile-4:#241E33; --tile-5:#2A2418; --tile-6:#16222E;
  --s1:#7A87FF; --s2:#2FD695; --s3:#F0B860; --s4:#FF7173; --s5:#9E8CFF;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: "Inter Tight", -apple-system, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 14px; line-height: 1.4; -webkit-font-smoothing: antialiased;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 20px 0 8px; }

#app { max-width: 720px; margin: 0 auto; min-height: 100vh; position: relative; }

/* ---- appbar ---- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(13px);
  border-bottom: 1px solid var(--border);
}
.appbar .brand { font-weight: 800; font-size: 17px; letter-spacing: -0.01em; }
.appbar .spacer { flex: 1; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  color: var(--text); cursor: pointer;
}
.iconbtn svg { width: 18px; height: 18px; }

.content { padding: 16px; padding-bottom: calc(var(--nav-space) + 16px); }
.tab-panel { animation: panelIn 180ms ease; }
@keyframes panelIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- cards ---- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card h2 { font-size: 17px; }

/* ---- today / hero card ---- */
.today {
  border-radius: 18px; padding: 18px; color: #fff; border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow);
}
.today-head { display: flex; justify-content: space-between; font-size: 12px; opacity: .85; margin-bottom: 6px; }
.today-main b { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.today-row { display: flex; gap: 16px; margin-top: 10px; font-size: 12px; opacity: .92; }

/* ---- insights ---- */
.insights { display: flex; flex-direction: column; gap: 8px; }
.insight-item {
  display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px;
  background: var(--accent-weak); border-radius: 12px; font-size: 13px; font-weight: 600;
}

/* ---- KPI grid ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 12px; }
@media (min-width: 560px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
.kpi {
  border-radius: 14px; padding: 12px 14px; min-height: 96px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.kpi:nth-child(6n+1) { background: var(--tile-1); }
.kpi:nth-child(6n+2) { background: var(--tile-2); }
.kpi:nth-child(6n+3) { background: var(--tile-3); }
.kpi:nth-child(6n+4) { background: var(--tile-4); }
.kpi:nth-child(6n+5) { background: var(--tile-5); }
.kpi:nth-child(6n+0) { background: var(--tile-6); }
.kpi-label { font-size: 12px; color: var(--hint); font-weight: 600; }
.kpi-value { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; margin-top: 6px; }

.delta { font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; gap: 3px; margin-top: 4px; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }
.delta.flat { color: var(--hint); }
.delta .cmp { color: var(--hint); font-weight: 600; margin-left: 2px; }

/* ---- controls ---- */
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.segmented button {
  border: none; background: transparent; color: var(--hint); font-weight: 700; font-size: 13px;
  padding: 7px 12px; border-radius: 10px; cursor: pointer; min-height: 32px;
}
.segmented button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* ---- chart wrap ---- */
.chart-wrap { position: relative; height: 220px; margin-top: 8px; }
.chart-wrap.sm { height: 170px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--hint); margin-top: 6px; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }

/* ---- rows / lists ---- */
.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: none; }
.avatar {
  width: 40px; height: 40px; border-radius: 12px; background: var(--accent-weak);
  display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--accent); flex-shrink: 0;
}
.row .meta { flex: 1; min-width: 0; }
.row .name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 12px; color: var(--hint); font-weight: 600; }
.row .val { text-align: right; font-weight: 800; font-size: 14px; }
.row .val small { display: block; font-weight: 600; font-size: 11px; color: var(--hint); }
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---- chips ---- */
.chip {
  display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--hint);
}
.chip.good { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.chip.bad  { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.chip.warn { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }

/* ---- table ---- */
.dtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.dtable th { text-align: left; color: var(--hint); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; padding: 6px 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card); cursor: pointer; }
.dtable td { padding: 8px; border-bottom: 1px solid var(--border); }
.dtable tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; max-height: 420px; overflow-y: auto; }

/* ---- quadrant matrix ---- */
.matrix-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.matrix-cell { border-radius: 14px; padding: 12px; background: var(--surface-2); }
.matrix-cell h3 { font-size: 13px; margin-bottom: 6px; }
.matrix-cell .count { font-size: 20px; font-weight: 800; }

/* ---- hub ---- */
.hub { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 12px; }
.hub-tile {
  border: 1px solid var(--border); border-radius: 16px; padding: 14px; background: var(--card);
  display: flex; flex-direction: column; gap: 8px; cursor: pointer; text-align: left;
}
.hub-tile:hover { border-color: var(--accent); }
.hub-tile .icn { width: 36px; height: 36px; border-radius: 10px; background: var(--accent-weak); display: flex; align-items: center; justify-content: center; }
.hub-tile .icn svg { width: 18px; height: 18px; color: var(--accent); }
.hub-tile .title { font-weight: 700; font-size: 14px; }
.hub-tile .sub { font-size: 12px; color: var(--hint); }

/* ---- unavailable state ---- */
.unavailable-box {
  border: 1px dashed var(--border); border-radius: 14px; padding: 20px; text-align: center;
  color: var(--hint); font-size: 13px; font-weight: 600;
}
.unavailable-box .big { font-size: 24px; margin-bottom: 6px; }

/* ---- buttons ---- */
.btn { height: 48px; border-radius: 12px; font-weight: 700; border: none; cursor: pointer; padding: 0 18px; font-size: 14px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-block { width: 100%; }

/* ---- bottom nav ---- */
.mobile-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-width: 720px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(13px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.mobile-nav button {
  background: none; border: none; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 2px; min-height: 52px; color: var(--hint); font-size: 10px; font-weight: 700; cursor: pointer;
}
.mobile-nav button svg { width: 20px; height: 20px; }
.mobile-nav button[aria-current="page"] { color: var(--accent); }

/* ---- sheet ---- */
.scrim { position: fixed; inset: 0; background: rgba(10,12,18,.5); opacity: 0; pointer-events: none; transition: opacity 220ms ease; z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-width: 720px; margin: 0 auto; z-index: 41;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 86vh; overflow-y: auto; transform: translateY(100%); transition: transform 220ms ease;
}
.scrim.show, .sheet.show { opacity: 1; pointer-events: auto; transform: translateY(0); }
.grabber { width: 36px; height: 4px; border-radius: 999px; background: var(--border); margin: 0 auto 10px; }

/* ---- splash ---- */
#splash {
  position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column;
  align-items: center; justify-content: center; z-index: 100; transition: opacity .3s ease;
}
#splash .word { font-size: 22px; font-weight: 800; margin-top: 12px; }
#splash .word b { color: var(--accent); }
#splash.hide { opacity: 0; pointer-events: none; }

/* ---- misc ---- */
.hidden { display: none !important; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-space) + 12px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 13px; font-weight: 600;
  z-index: 50; opacity: 0; transition: opacity 180ms ease; pointer-events: none;
}
.toast.show { opacity: 1; }
.demo-badge {
  display: inline-block; margin-left: 6px; padding: 2px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning);
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em;
}
