/* =====================================================================
   Nigraan demo - shared components
   Purpose : Buttons, controls, pills, status chips, panels, KPI strip,
             tables, tabs, switch, drawer, modal, toast, tooltip, stepper
             and the data-source pins.
   Related : js/core/ui.js (builds most of these), css/widgets.css
   Version : 0.2
   ===================================================================== */
/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 36px; padding: 7px 14px;
  border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 13.5px;
  text-decoration: none; line-height: 1.2; transition: background .15s, border-color .15s, color .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--axis); color: var(--ink); }
.btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); color: #fff; }
.btn.quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.quiet:hover { background: var(--brand-tint); color: var(--brand-ink); }
.btn.sm { min-height: 30px; padding: 4px 10px; font-size: 12.5px; }
.btn.danger { color: var(--critical-ink); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 30px; height: 30px; display: inline-grid; place-items: center; border-radius: 7px; border: 1px solid transparent; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--brand-tint); color: var(--brand-ink); }
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-pressed="true"] { background: var(--brand-tint); color: var(--brand-ink); border-color: var(--brand-tint-2); }

/* ---------- top-bar controls ---------- */
.ctl { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface); font-size: 13px; color: var(--ink-2); }
.ctl select { border: 0; background: transparent; font-weight: 600; color: var(--ink); padding: 0 2px; max-width: 160px; }
.ctl select:focus { outline: none; }
.ctl:focus-within { outline: 3px solid var(--focus); outline-offset: 1px; }
.ctl svg { width: 15px; height: 15px; stroke: var(--muted); fill: none; stroke-width: 1.8; }
.ctl.locked { background: var(--surface-2); }

/* switch (Show data sources) */
.switch { display: inline-flex; align-items: center; gap: 9px; height: 34px; white-space: nowrap; flex: none; padding: 0 12px 0 8px; border-radius: 8px; border: 1px solid var(--pin-tint); background: var(--pin-tint); color: var(--pin); font-weight: 600; font-size: 13px; }
.switch .trk { width: 32px; height: 18px; border-radius: 99px; background: #b8cfd6; position: relative; transition: background .2s; flex: none; }
.switch .trk::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .2s var(--ease); box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch[aria-checked="true"] { background: var(--pin); border-color: var(--pin); color: #fff; }
.switch[aria-checked="true"] .trk { background: rgba(255, 255, 255, .35); }
.switch[aria-checked="true"] .trk::after { transform: translateX(14px); }
.switch.plain { background: var(--surface); border-color: var(--line-2); color: var(--ink-2); }
.switch.plain[aria-checked="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- pills, chips, dummy label ---------- */
.dummy { display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; font-weight: 600; color: #7b8784; background: transparent; border: 1px dashed #c9d2cf; border-radius: 99px; padding: 1px 7px; line-height: 1.5; white-space: nowrap; vertical-align: middle; }
.real { display: inline-flex; font-size: 10.5px; font-weight: 600; color: var(--brand-ink); border: 1px solid var(--brand-tint-2); background: var(--brand-tint); border-radius: 99px; padding: 1px 7px; line-height: 1.5; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; border-radius: 99px; padding: 2px 9px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; line-height: 1.5; }
.pill.brand { background: var(--brand-tint); border-color: var(--brand-tint-2); color: var(--brand-ink); }
.pill.gold { background: var(--gold-tint); border-color: #e6dca3; color: var(--gold-ink); }
.pill.pinp { background: var(--pin-tint); border-color: #cddfe5; color: var(--pin); }
.pill svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 1.9; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; border-radius: 99px; padding: 2px 9px 2px 6px; white-space: nowrap; line-height: 1.5; }
.chip.c0 { background: var(--good-tint); color: var(--good-ink); }
.chip.c1 { background: var(--warn-tint); color: var(--warn-ink); }
.chip.c2 { background: var(--serious-tint); color: var(--serious-ink); }
.chip.c3 { background: var(--critical-tint); color: var(--critical-ink); }
.chip.neutral { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); padding: 1px 9px; }
.chip svg { flex: none; }

/* ---------- headings for screens ---------- */
.screen-head { margin-bottom: 18px; }
.screen-head .eyebrowless { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.screen-head h1 { font-size: 27px; font-weight: 700; max-width: 1050px; letter-spacing: -0.012em; }
.screen-head .lede { color: var(--ink-2); font-size: 14.5px; margin: 8px 0 0; max-width: 880px; }
.screen-head .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; align-items: center; }

/* ---------- panels ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, minmax(0, 1fr)); margin-bottom: 16px; }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-9 { grid-column: span 9; } .span-12 { grid-column: span 12; }
.panel { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px 16px 14px; min-width: 0; display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 12px; min-height: 30px; }
.panel-head .ttl { flex: 1 1 auto; min-width: 0; }
.panel-head h2 { font-size: 15px; font-weight: 650; }
.panel-head .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.panel-head .tools { display: flex; align-items: center; gap: 2px; flex: none; }
.panel-body { flex: 1 1 auto; min-width: 0; }
.panel.flush { padding: 0; }
.panel.hl { box-shadow: 0 0 0 3px var(--pin), 0 0 0 7px rgba(31, 106, 128, .14); animation: hlPulse 2.4s var(--ease) 1; }
@keyframes hlPulse { 0%, 30% { box-shadow: 0 0 0 3px var(--pin), 0 0 0 14px rgba(31, 106, 128, .18); } 100% { box-shadow: 0 0 0 3px var(--pin), 0 0 0 7px rgba(31, 106, 128, .14); } }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 26px 0 12px; }
.section-title h2 { font-size: 18px; font-weight: 700; }
.section-title .sub { color: var(--muted); font-size: 13px; }

/* ---------- KPI strip ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 16px; }
.kpi { padding: 14px 16px 13px; min-width: 0; border-left: 1px solid var(--line); }
.kpi:first-child { border-left: 0; }
.kpi .l { font-size: 12.5px; color: var(--ink-2); font-weight: 500; line-height: 1.3; min-height: 2.6em; }
.kpi .v { font-family: var(--f-display); font-size: 28px; font-weight: 700; line-height: 1.1; margin-top: 4px; letter-spacing: -0.01em; white-space: nowrap; }
.kpi .v small { font-size: 14px; font-weight: 600; color: var(--ink-2); margin-left: 4px; }
.kpi .d { font-size: 12px; color: var(--muted); margin-top: 5px; display: flex; align-items: center; gap: 5px; min-height: 18px; }
.kpi .d.up-good { color: var(--good-ink); }
.kpi .d.up-bad { color: var(--serious-ink); }
.kpis.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis.k6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }

/* ---------- tables ---------- */
.tbl { width: 100%; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 7px 8px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.tbl td { padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl td.dname { font-weight: 600; color: var(--ink); }
.tbl.cmp td { padding: 6px 8px; }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr.click:hover td { background: var(--surface-2); }
.tbl tbody tr.new td { background: var(--gold-tint); animation: newRow 3s ease-out 1 forwards; }
@keyframes newRow { to { background: transparent; } }
.tbl-wrap { overflow-x: auto; }
.tbl code { font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); padding: 0 5px; border-radius: 4px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a, .tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 600; font-size: 13.5px; color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover, .tabs button:hover { color: var(--brand-ink); }
.tabs [aria-current="page"], .tabs [aria-selected="true"] { color: var(--brand-ink); border-bottom-color: var(--brand); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-weight: 600; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--muted); }
.input, .select, .textarea { width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface); font-size: 14px; }
.textarea { min-height: 84px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.input.mask { letter-spacing: .12em; font-family: ui-monospace, Consolas, monospace; }
.err { color: var(--critical-ink); font-size: 12.5px; }

/* ---------- drawer / modal / toast / tooltip ---------- */
.scrim-d { position: fixed; inset: 0; background: rgba(7, 42, 38, .32); z-index: 90; animation: fadeIn .18s ease-out; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 96vw); background: var(--surface); z-index: 91; box-shadow: var(--shadow-pop); display: flex; flex-direction: column; animation: slideIn .24s var(--ease); }
.drawer.wide { width: min(760px, 96vw); }
.drawer-head { display: flex; align-items: flex-start; gap: 10px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.drawer-head .ttl { flex: 1; min-width: 0; }
.drawer-head .k { font-size: 12.5px; color: var(--muted); }
.drawer-head h2 { font-size: 19px; font-weight: 700; margin-top: 2px; }
.drawer-body { overflow-y: auto; padding: 16px 20px 28px; flex: 1; }
.drawer-foot { border-top: 1px solid var(--line); padding: 12px 20px; display: flex; gap: 8px; flex-wrap: wrap; }
.modal { position: fixed; z-index: 92; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(520px, 94vw); max-height: 90vh; overflow: auto; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); padding: 20px 22px; animation: popIn .2s var(--ease); }
.modal h2 { font-size: 19px; font-weight: 700; margin-bottom: 6px; }
.modal .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } }
@keyframes popIn { from { transform: translate(-50%, -46%); opacity: 0; } }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 99; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, 92vw); }
.toast { background: var(--brand-deep); color: #eaf5f2; border-radius: 10px; padding: 11px 14px; box-shadow: var(--shadow-pop); font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; animation: popToast .22s var(--ease); }
.toast b { color: #fff; }
.toast .ic { width: 18px; height: 18px; flex: none; margin-top: 1px; }
@keyframes popToast { from { transform: translateY(10px); opacity: 0; } }
.tip { position: fixed; z-index: 100; pointer-events: none; background: #102824; color: #eef7f5; font-size: 12.5px; line-height: 1.45; padding: 7px 10px; border-radius: 7px; max-width: 280px; opacity: 0; transform: translateY(2px); transition: opacity .12s, transform .12s; box-shadow: 0 6px 18px rgba(0, 0, 0, .18); }
.tip.on { opacity: 1; transform: none; }
.tip b { color: #fff; }

/* ---------- stepper (go-live readiness) ---------- */
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.steps li { position: relative; padding-top: 22px; font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.steps li::before { content: ""; position: absolute; top: 6px; left: 0; right: -6px; height: 4px; border-radius: 4px; background: var(--line); }
.steps li::after { content: ""; position: absolute; top: 1px; left: 0; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line-2); }
.steps li.done { color: var(--ink-2); }
.steps li.done::before { background: var(--brand); }
.steps li.done::after { background: var(--brand); border-color: var(--brand); }
.steps li.now { color: var(--ink); font-weight: 600; }
.steps li.now::after { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint-2); }

/* ---------- data-source pins (the dots of the ADS logo: connectivity) ---------- */
.pin {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; border: 1px solid #c6dbe2; background: var(--pin-tint); color: var(--pin);
  border-radius: 99px; padding: 3px 10px 3px 4px; font-size: 12px; font-weight: 600; line-height: 1.3; text-decoration: none; white-space: nowrap;
}
.pin:hover { background: #d6e8ee; color: #164f60; }
.pin .dot { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--pin); color: #fff; flex: none; }
.pin .dot svg { width: 12px; height: 12px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pin .t { overflow: hidden; text-overflow: ellipsis; }
.tbl .pin { white-space: normal; text-align: left; max-width: 240px; }
.tbl .pin .t { overflow: visible; }
.pin.int { background: var(--surface-2); border-color: var(--line); color: var(--ink-2); }
.pin.int .dot { background: #8a9894; }
.pin.own { background: var(--gold-tint); border-color: #e6dca3; color: var(--gold-ink); }
.pin.own .dot { background: #9a8a1e; }
.pins-on .panel .pin-slot { display: flex; }
.pin-slot { display: none; margin: -4px 0 10px; animation: pinIn .35s var(--ease) both; }
.pins-on .panel { border-color: #c6dbe2; }
@keyframes pinIn { from { opacity: 0; transform: translateY(-4px) scale(.97); } }

/* status dot with word for connection readiness */
.cstat { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.cstat i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.cstat.s0 i { background: transparent; border: 2px solid var(--axis); }
.cstat.s1 i { background: transparent; border: 2px solid var(--s2); }
.cstat.s2 i { background: var(--s2); }
.cstat.s3 i { background: var(--pin); }
.cstat.s4 i { background: var(--brand); box-shadow: 0 0 0 2px var(--brand-tint-2); }
.cstat.s5 i { background: var(--good); }

/* key/value lists in drawers */
.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 8px 14px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; color: var(--ink); min-width: 0; overflow-wrap: anywhere; }
.box { border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; margin-bottom: 14px; background: var(--surface); }
.box.soft { background: var(--surface-2); }
.box h3 { font-size: 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.note { font-size: 12.5px; color: var(--ink-2); background: var(--surface-2); border-left: 3px solid var(--slate-teal); padding: 8px 12px; border-radius: 0 6px 6px 0; margin: 10px 0; }
.note.gold { border-left-color: var(--gold); background: var(--gold-tint); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

@media (max-width: 1100px) {
  .kpis, .kpis.k6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(odd) { border-left: 0; }
  .kpi { border-top: 1px solid var(--line); }
  .kpi:nth-child(-n+2) { border-top: 0; }
  .span-3, .span-4, .span-5, .span-6, .span-7, .span-8, .span-9 { grid-column: span 12; }
  .steps { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 12px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
}
@media (max-width: 760px) {
  .screen-head h1 { font-size: 22px; }
  .screen-head .lede { font-size: 14px; }
  .kpi { padding: 12px; }
  .kpi .v { font-size: 23px; }
  .panel { padding: 14px 12px 12px; }
  .drawer-body { padding: 14px 14px 24px; }
  .section-title { flex-wrap: wrap; }
}
.btn.wrap { white-space: normal; text-align: left; }
@media (max-width: 760px) {
  .pin { white-space: normal; text-align: left; }
}
