/* IWBI Data Hub — app layout on top of the One WELL Design System.
   Tokens come from ds/colors_and_type.css and buttons/tags from ds/components.css (both verbatim from the design system).
   This file only adds layout and app-specific pieces, using design-system tokens (no new colors, sizes or fonts). */

[hidden] { display: none !important; }
* { box-sizing: border-box; }
body { margin: 0; font-size: var(--type-body-sm); }
h1, h2, h3, h4, p { margin: 0; }
code { font-family: ui-monospace, monospace; font-size: var(--type-meta); background: var(--gray-100); padding: 2px var(--space-xs); border-radius: var(--radius-xs); }
:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

/* ---------- Top bar (64px, white, gray-200 border) ---------- */
.topbar { height: 64px; display: flex; align-items: center; gap: var(--space-md); padding: 0 var(--space-lg); background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--primary); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand .logo { height: 52px; width: auto; display: block; }   /* IWBI logo used as supplied (never recolored) */
.brand .divider { width: 1px; height: 20px; background: var(--border); }
.brand .product { font-size: var(--type-body-sm); font-weight: 500; color: var(--gray-600); letter-spacing: 0.01em; }
.topbar .spacer { flex: 1; }
.who { display: flex; align-items: center; gap: var(--space-sm); color: var(--foreground-muted); font-size: var(--type-body-sm); }
.avatar { width: 32px; height: 32px; border-radius: var(--radius-full); background: var(--cyan-100); color: var(--cyan-900); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: var(--type-meta); text-transform: uppercase; }

/* ---------- Workspace: side rail + canvas ---------- */
.shell { display: grid; grid-template-columns: 256px minmax(0, 1fr); min-height: calc(100vh - 64px);
  background: linear-gradient(to right, var(--surface-side) 0 255px, var(--border-panel) 255px 256px, transparent 256px); }  /* rail color runs the full page height */
.rail { background: var(--surface-side); border-right: 1px solid var(--border-panel); align-self: start; padding: var(--space-lg) 0; position: sticky; top: 64px; height: calc(100vh - 64px); overflow-y: auto; }
.rail .section-label { padding: 0 var(--space-md) 0 22px; margin: var(--space-md) 0 var(--space-sm); display: block; }
.rail .section-label:first-child { margin-top: 0; }
.rail a { display: block; padding: var(--space-sm) var(--space-md) var(--space-sm) 20px; border-left: 2px solid transparent; color: var(--gray-700); font-size: var(--type-body-sm); line-height: 1.35; text-decoration: none; }
.rail a:hover { background: var(--cyan-100); text-decoration: none; }
.rail a.active { border-left-color: var(--primary); background: var(--cyan-100); color: var(--cyan-900); font-weight: 600; }
.rail .rail-foot { margin-top: var(--space-lg); padding-top: var(--space-md); border-top: 1px solid var(--border-panel); }
main { padding: var(--space-lg); min-width: 0; }

/* ---------- Page header ---------- */
.page-head { display: flex; gap: var(--space-md); align-items: flex-start; margin-bottom: var(--space-md); }
.page-head .titles { flex: 1; min-width: 0; }
.page-head .section-label { display: block; margin-bottom: var(--space-sm); }
.page-head .desc { margin-top: var(--space-sm); color: var(--foreground-muted); font-size: var(--type-body-sm); line-height: 1.55; max-width: 880px; }
.page-head .actions { display: flex; align-items: center; gap: var(--space-sm); }
.muted { color: var(--foreground-muted); }
.small { font-size: var(--type-meta); }
.err { color: var(--destructive); font-size: var(--type-body-sm); white-space: pre-wrap; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); padding: var(--space-md) 20px; }
.empty { padding: var(--space-xl) var(--space-lg); text-align: center; color: var(--foreground-muted); }

/* Dashboard list */
.folder { margin-bottom: var(--space-lg); }
.folder > .section-label { display: block; margin-bottom: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--space-md); }
.tile { display: flex; flex-direction: column; gap: var(--space-sm); color: inherit; text-decoration: none; padding: 20px; transition: border-color .15s ease, box-shadow .15s ease; }
.tile:hover { text-decoration: none; border-color: var(--border-panel); box-shadow: var(--shadow-md); }
.tile h3 { font-size: var(--type-body); font-weight: 600; }
.tile .desc { color: var(--foreground-muted); font-size: var(--type-body-sm); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tile .go { margin-top: auto; color: var(--link); font-size: var(--type-body-sm); font-weight: 500; }

/* ---------- Filters & form fields ---------- */
.filters { display: flex; flex-wrap: wrap; gap: var(--space-md); align-items: flex-end; margin: 0 0 20px; padding: var(--space-md) 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.filters label, .field { display: flex; flex-direction: column; gap: var(--space-xs); font-size: var(--type-meta); font-weight: 500; color: var(--gray-600); }
input, select, textarea { font: inherit; font-size: var(--type-body-sm); color: var(--foreground); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
input, select { height: 40px; padding: 0 12px; }
textarea { padding: var(--space-sm) 12px; }
input[type=checkbox] { height: auto; accent-color: var(--primary); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--cyan-100); }
.filters select { max-width: 320px; text-overflow: ellipsis; }

/* Type-ahead */
.ta { position: relative; width: 320px; }
.ta-input { width: 100%; padding-right: 32px; }
.ta-input::placeholder { color: var(--gray-400); }
.ta-clear { position: absolute; right: var(--space-xs); top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border: none; background: none; border-radius: var(--radius-sm); color: var(--gray-500); font-size: var(--type-body-lg); line-height: 1; cursor: pointer; }
.ta-clear:hover { background: var(--gray-100); color: var(--gray-800); }
.ta-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + var(--space-xs)); margin: 0; padding: var(--space-xs) 0; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); max-height: 320px; overflow: auto; font-size: var(--type-body-sm); font-weight: 400; color: var(--foreground); }
.ta-list li { padding: var(--space-sm) 12px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ta-list li.active, .ta-list li:hover { background: var(--blue-100); }
.ta-list li mark { background: var(--cyan-100); color: var(--cyan-900); padding: 0 1px; border-radius: var(--radius-xs); }
.ta-list li.ta-none { color: var(--foreground-muted); cursor: default; background: none; }

/* ---------- Dashboard grid & charts ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--space-md); }
.chart { position: relative; display: flex; flex-direction: column; min-height: 120px; }
.chart .head { display: flex; align-items: center; gap: var(--space-sm); margin-bottom: 12px; min-height: 28px; }
.chart .head h3 { font-size: var(--type-body); font-weight: 600; line-height: 1.3; flex: 1; }
.chart .hint { font-size: var(--type-meta); color: var(--foreground-muted); white-space: nowrap; }
.chart .body { flex: 1; min-height: 300px; }
.chart .foot { font-size: 11px; color: var(--gray-400); margin-top: var(--space-sm); }

/* KPI: hero number in FT Made (display face is allowed for hero numbers) */
.chart.kpi { padding: 20px; }
.chart.kpi .head { margin-bottom: var(--space-sm); min-height: 0; }
.chart.kpi .head h3 { font-size: var(--type-meta); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--foreground-muted); }
.chart.kpi .body { min-height: 0; }
.kpi .value { font-family: var(--font-display); font-size: var(--type-page-title); font-weight: 400; line-height: 1.15; color: var(--foreground); font-variant-numeric: tabular-nums; }
.kpi .value.pos { color: var(--emerald-800); }
.kpi .value.neg { color: var(--coral-800); }

/* Drill-down chip (selectable-tag colors: blue-100 / blue-200) */
.drillbar { margin: 0 0 12px; }
.drill-chip { gap: var(--space-sm); background: var(--blue-100); color: var(--blue-800); box-shadow: inset 0 0 0 1px var(--blue-200); padding-right: var(--space-xs); font-size: var(--type-meta); height: 28px; }
.drill-chip strong { font-weight: 600; }
.drill-chip button { border: none; background: none; width: 22px; height: 22px; border-radius: var(--radius-xs); color: inherit; font-size: var(--type-body); line-height: 1; cursor: pointer; }
.drill-chip button:hover { background: var(--blue-200); }

/* Export menu */
.menu { position: relative; }
.menu .items { display: none; position: absolute; right: 0; top: calc(100% + var(--space-xs)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); z-index: 15; min-width: 168px; padding: var(--space-xs) 0; }
.menu.open .items { display: block; }
.menu .items a { display: block; padding: var(--space-sm) var(--space-md); color: var(--foreground); font-size: var(--type-body-sm); }
.menu .items a:hover { background: var(--gray-50); text-decoration: none; }

/* ---------- Tables ---------- */
.tablewrap { overflow: auto; max-height: 560px; border-radius: var(--radius-md); }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: var(--type-body-sm); }
table.data th { position: sticky; top: 0; z-index: 1; background: var(--gray-50); color: var(--foreground-muted); font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; }
table.data th:hover { color: var(--gray-800); }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); color: var(--foreground); white-space: nowrap; }
table.data tbody tr:hover td { background: var(--gray-50); }
table.data th.num, table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.card > table.data th { cursor: default; }

/* ---------- Admin ---------- */
.tabs { display: flex; gap: var(--space-xs); border-bottom: 1px solid var(--border); margin: 0 0 20px; }
.tab { height: 40px; padding: 0 var(--space-md); border: none; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; font: inherit; font-size: var(--type-body-sm); font-weight: 500; color: var(--gray-600); cursor: pointer; display: inline-flex; align-items: center; gap: var(--space-sm); }
.tab:hover { color: var(--gray-900); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--radius-full); background: var(--coral-100); color: var(--coral-800); font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; margin: 2px var(--space-xs) 2px 0; border-radius: var(--radius-full); background: var(--gray-100); color: var(--gray-700); font-size: var(--type-meta); font-weight: 500; white-space: nowrap; }
label.pill { cursor: pointer; }
label.pill:has(input:checked) { background: var(--blue-100); color: var(--blue-800); box-shadow: inset 0 0 0 1px var(--blue-200); }
.st-active { background: var(--emerald-100); color: var(--emerald-900); }
.st-invited { background: var(--gray-100); color: var(--gray-700); }
.st-off { background: var(--coral-100); color: var(--coral-900); }
.is-danger { color: var(--destructive) !important; }
.row { display: flex; gap: var(--space-sm); align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: var(--space-md); }
h2.section { font-size: var(--type-body); font-weight: 600; margin: var(--space-lg) 0 12px; }

/* ---------- Sign-in ---------- */
body.signin { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--background); }
.signin-card { width: 420px; text-align: center; padding: var(--space-lg) var(--space-lg) 40px; border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); position: relative; overflow: hidden; }
.signin-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 6px; background: var(--gradient-soft); }
.signin-card .brand { justify-content: center; margin: var(--space-sm) 0 var(--space-lg); }
.signin-card .brand .logo { height: 72px; }
.signin-card h1 { margin-bottom: var(--space-sm); }
.signin-card p { color: var(--foreground-muted); margin-bottom: var(--space-lg); }
.signin-card .dev { margin-top: var(--space-lg); padding-top: 20px; border-top: 1px solid var(--border-soft); }
.signin-card .dev .row { justify-content: center; }

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border-panel); padding: var(--space-md) 0; }
  main { padding: var(--space-md); }
  .grid { grid-template-columns: 1fr; }
  .chart { grid-column: auto !important; }
  .ta { width: 100%; }
}

/* Truncated table text: full value in the hover title */
.trunc { cursor: help; text-decoration: underline dotted var(--gray-300); text-underline-offset: 3px; border-radius: var(--radius-xs); }
.trunc:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.tip { position: fixed; z-index: 1000; max-width: 480px; padding: 6px 10px; border-radius: var(--radius-sm); background: var(--gray-900); color: var(--foreground-on-dark);
  font-family: var(--font-body); font-size: var(--type-meta); font-weight: 500; line-height: 1.4; white-space: normal; overflow-wrap: anywhere; box-shadow: var(--shadow-lg); pointer-events: none; }
