/* Widgets v2 — premium dark. Consumes tokens.css only. */

/* ——— panels ——————————————————————————————————— */
.panel {
  background: linear-gradient(180deg, var(--glass-2), rgba(255, 255, 255, 0.015)), var(--bg-1);
  border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s5);
  box-shadow: var(--shadow-2); margin-bottom: var(--s4); position: relative; overflow: hidden;
}
.panel::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 1px; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.14), transparent); }
.panel > header { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); margin-bottom: var(--s4); flex-wrap: wrap; }
.panel h2 { font-size: var(--fs-lg); font-weight: 600; }
.panel h3 { font-size: var(--fs-sm); font-weight: 600; color: var(--fg-2); text-transform: uppercase; letter-spacing: 0.08em; margin: var(--s4) 0 var(--s2); }
.panel > header .muted { font-size: var(--fs-xs); }
.empty { color: var(--fg-dim); text-align: center; padding: var(--s7) var(--s4); font-size: var(--fs-sm); }

/* ——— KPI cards ————————————————————————————————— */
.kpi {
  background: linear-gradient(180deg, var(--glass-2), rgba(255, 255, 255, 0.012)), var(--bg-1);
  border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s4) var(--s5);
  display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden;
  transition: border-color var(--t-micro) var(--ease), transform var(--t-micro) var(--ease);
}
.kpi:hover { border-color: var(--line-strong); }
.kpi::after { content: ""; position: absolute; inset: auto 0 0 0; height: 2px; background: linear-gradient(90deg, var(--brand), transparent 70%); opacity: 0.5; }
.kpi[data-state="ok"]::after { background: linear-gradient(90deg, var(--ok), transparent 70%); }
.kpi[data-state="warn"] { border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.kpi[data-state="warn"]::after { background: linear-gradient(90deg, var(--warn), transparent 70%); }
.kpi[data-state="crit"] { border-color: color-mix(in srgb, var(--crit) 45%, transparent); }
.kpi[data-state="crit"]::after { background: linear-gradient(90deg, var(--crit), transparent 70%); }
.kpi-label { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: var(--fs-xs); color: var(--fg-dim); display: flex; gap: 6px; align-items: center; text-transform: uppercase; letter-spacing: 0.09em; font-weight: 550; }
.kpi-hint { width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line-strong); font-size: 10px; display: inline-grid; place-items: center; cursor: help; color: var(--fg-faint); }
.kpi-value { font-size: clamp(22px, 2.1vw, 32px); line-height: 1.05; font-weight: 620; letter-spacing: -0.03em; white-space: nowrap; }
.kpi-unit { font-size: var(--fs-xs); color: var(--fg-dim); margin-left: 4px; letter-spacing: 0; }
.kpi-hint-text { font-size: var(--fs-xs); color: var(--fg-faint); }

/* ——— buttons ——————————————————————————————————— */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-strong); background: var(--glass); color: var(--fg);
  border-radius: var(--r-sm); padding: 8px 14px; min-height: 38px; font: inherit; font-size: var(--fs-sm);
  font-weight: 550; cursor: pointer; transition: all var(--t-micro) var(--ease); white-space: nowrap;
}
.btn:hover { background: var(--glass-2); border-color: var(--fg-faint); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn.primary { background: linear-gradient(140deg, var(--brand-400), var(--brand-600)); border-color: transparent; color: #fff; box-shadow: var(--shadow-brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--fg-dim); }
.btn.ghost:hover { background: var(--glass); color: var(--fg); }
.btn.danger { border-color: color-mix(in srgb, var(--crit) 45%, transparent); color: #ffd9df; background: var(--crit-soft); }
.btn.sm { padding: 5px 10px; min-height: 30px; font-size: var(--fs-xs); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ——— pills / status ————————————————————————————— */
.pill, .status {
  display: inline-flex; align-items: center; gap: 6px; border-radius: var(--r-pill);
  padding: 3px 10px; font-size: var(--fs-2xs); font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; border: 1px solid var(--line-strong); color: var(--fg-2); background: var(--glass);
}
.pill::before, .status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill[data-state="ok"], .status[data-state="ok"] { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: var(--ok-soft); }
.pill[data-state="warn"], .status[data-state="warn"] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: var(--warn-soft); }
.pill[data-state="crit"], .status[data-state="crit"] { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, transparent); background: var(--crit-soft); }
.pill[data-state="idle"], .status[data-state="idle"] { color: var(--idle); }

/* ——— chips ————————————————————————————————————— */
.chips { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  background: var(--glass); color: var(--fg-2); border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 6px 13px; font-size: var(--fs-xs); min-height: 38px; cursor: pointer; white-space: nowrap;
  font: inherit; transition: all var(--t-micro) var(--ease);
}
.chip:hover { border-color: var(--line-strong); color: var(--fg); }
.chip.is-active { border-color: var(--line-brand); background: var(--brand-soft); color: #fff; }

/* ——— tables ———————————————————————————————————— */
.table-wrap { overflow-x: auto; }
.dt { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.dt th {
  text-align: left; color: var(--fg-faint); font-weight: 600; font-size: var(--fs-2xs);
  text-transform: uppercase; letter-spacing: 0.09em; padding: 10px var(--s3);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg-1); z-index: 2;
}
.dt td { padding: 11px var(--s3); border-bottom: 1px solid var(--line); color: var(--fg-2); }
.dt tbody tr { transition: background var(--t-micro) var(--ease); }
.dt tbody tr:hover { background: var(--glass); }
.dt tbody tr:last-child td { border-bottom: 0; }
.dt td:first-child { color: var(--fg); font-weight: 550; }
/* status is carried by a thin left bar + a barely-there wash: a row is data,
   not an alarm, and 100 tinted rows read as noise (was 14% fill — too loud). */
.dt tr[data-state] td:first-child { position: relative; }
.dt tr[data-state] td:first-child::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 3px; }
.dt tr[data-state="crit"] { background: color-mix(in srgb, var(--crit) 6%, transparent); }
.dt tr[data-state="crit"] td:first-child::before { background: var(--crit); }
.dt tr[data-state="warn"] { background: color-mix(in srgb, var(--warn) 6%, transparent); }
.dt tr[data-state="warn"] td:first-child::before { background: var(--warn); }
.dt tr[data-state="ok"] td:first-child::before { background: var(--ok); }
.dt td.num, .dt th.num { text-align: right; }
.dt td.empty { text-align: center; color: var(--fg-dim); padding: var(--s7); }

/* ——— key/value rows (used by Ops, Default egress, Keepers) ————— */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px var(--s5); align-items: baseline; font-size: var(--fs-sm); }
.kv > span { color: var(--fg-faint); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.08em; }
.kv > b { color: var(--fg); font-weight: 550; overflow-wrap: anywhere; }

/* ——— tunnel cards ————————————————————————————— */
.tun-card { background: var(--glass); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s3) var(--s4); }
.tun-card[data-state="crit"] { border-color: color-mix(in srgb, var(--crit) 45%, transparent); }
.tun-card[data-state="warn"] { border-color: color-mix(in srgb, var(--warn) 40%, transparent); }

/* ——— inputs ———————————————————————————————————— */
input.search, select, textarea {
  background: var(--glass); border: 1px solid var(--line); color: var(--fg);
  border-radius: var(--r-sm); padding: 9px var(--s3); font: inherit; font-size: var(--fs-sm); min-height: 38px;
  transition: border-color var(--t-micro) var(--ease), box-shadow var(--t-micro) var(--ease);
}
input.search:focus, select:focus, textarea:focus { border-color: var(--line-brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
label { font-size: var(--fs-xs); color: var(--fg-dim); display: flex; flex-direction: column; gap: 6px; }

/* ——— sheets / drawers / palette ————————————————— */
.sheet {
  position: fixed; inset: auto 0 0 0; background: var(--bg-elev); border-top-left-radius: var(--r-xl);
  border-top-right-radius: var(--r-xl); border: 1px solid var(--line); z-index: var(--z-sheet);
  max-height: 82vh; overflow: auto; box-shadow: var(--shadow-3);
}
.sheet[hidden] { display: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg-elev); }
.sheet-body { padding: var(--s4) var(--s5) var(--s6); }
.sheet-close { background: none; border: 0; color: var(--fg-dim); font-size: 24px; min-width: 40px; min-height: 40px; cursor: pointer; border-radius: var(--r-sm); }
.sheet-close:hover { background: var(--glass); color: var(--fg); }

#palette { position: fixed; inset: 0; z-index: var(--z-palette); background: rgba(3, 5, 10, 0.66); backdrop-filter: blur(4px); display: grid; place-items: start center; padding-top: 12vh; }
#palette[hidden] { display: none; }
.pal { width: min(640px, 92vw); background: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-3); overflow: hidden; }
.pal .search { width: 100%; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: var(--s4) var(--s5); font-size: var(--fs-lg); background: transparent; }
.pal-list { list-style: none; margin: 0; padding: var(--s2); max-height: 52vh; overflow: auto; }
.pal-list li { padding: 10px var(--s3); border-radius: var(--r-sm); cursor: pointer; display: flex; gap: var(--s3); align-items: center; font-size: var(--fs-sm); color: var(--fg-2); }
.pal-list li:hover, .pal-list li.is-active { background: var(--brand-soft); color: #fff; }
.pal-list li .muted { margin-left: auto; }

/* ——— toasts / misc ————————————————————————————— */
.toast { position: fixed; bottom: var(--s6); left: 50%; transform: translateX(-50%); background: var(--bg-2); border: 1px solid var(--line-strong); border-radius: var(--r-pill); padding: 10px var(--s5); z-index: var(--z-toast); box-shadow: var(--shadow-2); font-size: var(--fs-sm); }
.toast[data-kind="ok"] { border-color: var(--ok); }
.toast[data-kind="crit"] { border-color: var(--crit); }
.spark { color: var(--info); display: block; }
.divider { height: 1px; background: var(--line); margin: var(--s4) 0; }
.progress { height: 8px; border-radius: var(--r-pill); background: var(--glass-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand-400), var(--brand-600)); }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: var(--r-xs); background: var(--glass-2); border: 1px solid var(--line); font-size: var(--fs-2xs); color: var(--fg-2); }
.skeleton { background: linear-gradient(90deg, var(--glass), var(--glass-2), var(--glass)); background-size: 200% 100%; animation: sk 1.4s ease infinite; border-radius: var(--r-sm); height: 14px; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
