/* ==========================================================================
   Components — page header, tabs, filters, KPI ledger, panels, tables,
   charts, badges, modal, toast, empty states, skeletons, tour, upload
   ========================================================================== */

/* ── Page header ("team ribbon") ─────────────────────── */
.page-head { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
.page-head-main { display: flex; gap: 14px; align-items: stretch; min-width: 0; }
.ribbon { width: 5px; border-radius: 3px; background: var(--green-600); flex: none; }
.page-head h1 { word-break: break-word; }
.page-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 6px; font-size: var(--fs-sm); color: var(--muted); }
.page-meta b { color: var(--ink-2); font-weight: 650; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Tabs (scope switch) ─────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 14px; color: var(--muted); text-decoration: none; font-weight: 650; font-size: var(--fs-md); white-space: nowrap;
}
.tab svg { width: 16px; height: 16px; }
.tab:hover { color: var(--ink); }
.tab[aria-current='page'] { color: var(--green-700); }
.tab[aria-current='page']::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--green-600); }
.tab .count { font-size: var(--fs-xs); background: var(--green-50); color: var(--green-700); padding: 1px 7px; border-radius: var(--r-pill); }

/* ── Filter toolbar ──────────────────────────────────── */
.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.toolbar-label { font-size: var(--fs-sm); font-weight: 650; color: var(--ink-2); }
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: transparent; padding: 6px 11px; border-radius: 6px;
  font: 600 var(--fs-sm)/1.2 var(--font); color: var(--muted); cursor: pointer;
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed='true'] { background: var(--surface); color: var(--green-700); box-shadow: var(--shadow-1), 0 0 0 1px var(--line); }
.date-pair { display: inline-flex; gap: 6px; align-items: center; }
.date-pair .input { width: 150px; min-height: 34px; font-size: var(--fs-sm); padding: 5px 8px; }
.toolbar .spacer { flex: 1; }
.scope-note { font-size: var(--fs-xs); color: var(--muted); }

/* ── KPI ledger ──────────────────────────────────────── */
.ledger {
  display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden;
}
.ledger-item { padding: 18px 20px; border-left: 1px solid var(--line); border-top: 1px solid var(--line); margin: -1px 0 0 -1px; min-width: 0; }
.ledger-item .label { font-size: var(--fs-sm); font-weight: 600; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.ledger-item .value { margin-top: 6px; font-size: 28px; font-weight: 760; letter-spacing: -0.03em; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ledger-item .value small { font-size: 15px; font-weight: 650; color: var(--muted); letter-spacing: 0; margin-left: 2px; }
.ledger-item .sub { margin-top: 4px; font-size: var(--fs-xs); color: var(--muted); }
.ledger-item.is-hero { background: linear-gradient(180deg, var(--green-50), var(--surface) 70%); }
.ledger-item.is-hero .value { color: var(--green-700); font-size: 34px; }
.ledger-item .tip { width: 14px; height: 14px; color: var(--faint); cursor: help; }
@media (max-width: 1200px) { .ledger { --cols: 4 !important; } }
@media (max-width: 860px)  { .ledger { --cols: 2 !important; } .ledger-item .value { font-size: 24px; } .ledger-item.is-hero .value { font-size: 28px; } }

/* ── Panels & grids ──────────────────────────────────── */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid-3, .grid-2-1 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px)  { .grid-2, .grid-3, .grid-2-1 { grid-template-columns: 1fr; } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); min-width: 0; display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px 12px; }
.panel-head h2 { font-size: 15px; }
.panel-head p { font-size: var(--fs-xs); color: var(--muted); margin-top: 3px; }
.panel-body { padding: 4px 18px 18px; min-width: 0; flex: 1; }
.panel-body.flush { padding: 0; }
.panel-foot { padding: 10px 18px; border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--muted); }
.view-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; flex: none; }
.view-toggle button { border: 0; background: var(--surface); padding: 5px 9px; font: 600 var(--fs-xs)/1 var(--font); color: var(--muted); cursor: pointer; }
.view-toggle button[aria-pressed='true'] { background: var(--green-50); color: var(--green-700); }

.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }
.chart-box.short { height: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: var(--fs-xs); color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }

/* ── Tables ──────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  position: sticky; top: 0; z-index: 1;
  padding: 10px 14px; text-align: left; white-space: nowrap;
  font-size: var(--fs-xs); font-weight: 700; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--ink); }
.table th[aria-sort] .sort-ind { opacity: 1; }
.sort-ind { opacity: .3; margin-left: 4px; font-size: 10px; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:hover td { background: #fafcfa; }
.table .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th.n { text-align: right; }
.table tfoot td { font-weight: 750; background: var(--surface-2); border-bottom: 0; border-top: 1px solid var(--line-strong); }
.table .name { font-weight: 650; white-space: nowrap; }
.table .dim { color: var(--faint); }
.table-compact td, .table-compact th { padding: 8px 12px; }
.heat { position: relative; }
.heat-cell { border-radius: 4px; padding: 3px 6px; display: inline-block; min-width: 64px; }
.bar-cell { display: grid; gap: 4px; min-width: 120px; }
.bar-cell .bar { height: 4px; border-radius: 4px; background: var(--green-100); overflow: hidden; }
.bar-cell .bar i { display: block; height: 100%; border-radius: 4px; background: var(--green-600); }
.table-empty { padding: 28px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; font-size: var(--fs-sm); color: var(--muted); border-top: 1px solid var(--line); flex-wrap: wrap; }

/* ── Badges ──────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 650; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge svg { width: 12px; height: 12px; }
.badge-good { background: var(--green-50); color: var(--good); border-color: var(--green-100); }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: #f3dea8; }
.badge-bad { background: var(--bad-bg); color: var(--bad); border-color: #f5c9cf; }
.badge-info { background: var(--info-bg); color: var(--info); border-color: #cfe0f3; }
.badge-gold { background: var(--gold-50); color: #7b5d22; border-color: #eadbb5; }
.team-tag { display: inline-flex; align-items: center; gap: 7px; font-weight: 650; }
.team-tag i { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* ── Callouts ────────────────────────────────────────── */
.callout { display: flex; gap: 12px; padding: 12px 14px; border-radius: var(--r-md); font-size: var(--fs-sm); border: 1px solid; }
.callout svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.callout-info { background: var(--info-bg); border-color: #cfe0f3; color: #173f66; }
.callout-warn { background: var(--warn-bg); border-color: #f3dea8; color: #6b4600; }
.callout-good { background: var(--green-50); border-color: var(--green-100); color: var(--green-700); }
.callout b { font-weight: 700; }

/* ── Empty states ────────────────────────────────────── */
.empty { display: grid; justify-items: center; text-align: center; gap: 12px; padding: 56px 24px; background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--r-lg); }
.empty-mark { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--green-50); color: var(--green-600); }
.empty-mark svg { width: 28px; height: 28px; }
.empty h2 { font-size: var(--fs-xl); }
.empty p { max-width: 460px; color: var(--muted); }

/* ── Skeletons ───────────────────────────────────────── */
.skeleton { border-radius: var(--r-md); background: linear-gradient(90deg, #e9eee9 0%, #f4f7f4 50%, #e9eee9 100%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.loading-block { display: grid; gap: 20px; }
.loading-note { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: var(--fs-sm); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--green-100); border-top-color: var(--green-600); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ───────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(4,29,19,.5); animation: fade .18s ease; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); animation: pop .22s var(--ease); }
.modal-wide { width: min(860px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: var(--fs-lg); }
.modal-body { padding: 20px; display: grid; gap: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ── Toasts ──────────────────────────────────────────── */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 300; display: grid; gap: 10px; width: min(380px, calc(100vw - 36px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md); background: var(--forest-900); color: #e9f1ec; box-shadow: var(--shadow-pop); font-size: var(--fs-sm); animation: pop .22s var(--ease); }
.toast svg { width: 18px; height: 18px; flex: none; }
.toast.good svg { color: #7fd8a5; }
.toast.bad { background: #4a0c17; }
.toast.bad svg { color: #ff9aa6; }

/* ── Upload dropzone & progress ──────────────────────── */
.dropzone {
  display: grid; justify-items: center; gap: 10px; text-align: center; padding: 40px 20px;
  border: 2px dashed var(--line-strong); border-radius: var(--r-lg); background: var(--surface);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--green-600); background: var(--green-50); }
.dropzone svg { width: 36px; height: 36px; color: var(--green-600); }
.dropzone strong { font-size: var(--fs-lg); }
.progress { height: 8px; border-radius: 8px; background: var(--green-50); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--green-600); border-radius: 8px; transition: width .25s var(--ease); }

.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 640px) { .choice-grid { grid-template-columns: 1fr; } }
.choice { position: relative; display: grid; gap: 4px; padding: 14px 16px 14px 46px; border: 1px solid var(--line-strong); border-radius: var(--r-md); cursor: pointer; background: var(--surface); }
.choice input { position: absolute; left: 16px; top: 17px; width: 18px; height: 18px; accent-color: var(--green-600); }
.choice strong { font-size: var(--fs-md); }
.choice span { font-size: var(--fs-sm); color: var(--muted); }
.choice:has(input:checked) { border-color: var(--green-600); background: var(--green-50); box-shadow: 0 0 0 1px var(--green-600); }

.steps { display: flex; gap: 8px; flex-wrap: wrap; counter-reset: step; }
.step { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: var(--r-pill); background: var(--surface); border: 1px solid var(--line); font-size: var(--fs-sm); font-weight: 650; color: var(--muted); }
.step::before { counter-increment: step; content: counter(step); width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: var(--fs-xs); }
.step.is-active { color: var(--green-700); border-color: var(--green-600); }
.step.is-active::before { background: var(--green-600); color: #fff; }
.step.is-done::before { background: var(--green-100); color: var(--green-700); }

/* ── Guided tour ─────────────────────────────────────── */
.tour-layer { position: fixed; inset: 0; z-index: 500; pointer-events: none; }
.tour-spot { position: fixed; border-radius: 12px; box-shadow: 0 0 0 9999px rgba(4,29,19,.62); outline: 2px solid var(--gold-300); outline-offset: 3px; transition: all .3s var(--ease); pointer-events: none; }
.tour-card { position: fixed; width: min(360px, calc(100vw - 24px)); background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); padding: 18px; pointer-events: auto; transition: top .3s var(--ease), left .3s var(--ease); }
.tour-card .tour-step { font-size: var(--fs-xs); color: var(--muted); font-weight: 650; }
.tour-card h3 { margin-top: 6px; font-size: var(--fs-lg); }
.tour-card p { margin-top: 6px; color: var(--ink-2); font-size: var(--fs-sm); line-height: 1.6; }
.tour-card .row-between { margin-top: 16px; }
.tour-dots { display: flex; gap: 5px; }
.tour-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line-strong); }
.tour-dots i.on { background: var(--green-600); width: 16px; border-radius: 3px; }

/* ── Install prompt ──────────────────────────────────── */
.install-btn { border-color: var(--gold-300); background: var(--gold-50); color: #6b5020; }
.install-btn:hover { border-color: var(--gold-500); color: #4d3910; }
