/* Generic components: section, overview, panel and card, key figure, table, toolbar, pill, fact grid,
   empty state, skeleton, notice and error box, form, tabs, disclosure block, dialog, message, right drawer
   and the stage of a surface. Everything builds on tokens.css. */

/* ═══ Sections ═════════════════════════════════════════════════════ */

.section { margin-bottom: 30px; }

.section-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px;
  padding: 0 0 10px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line-subtle);
}
.section-head h2 {
  font-family: var(--font-heading);
  font-weight: 600; font-size: 15px; line-height: 22px;
  letter-spacing: -0.005em;
  margin: 0;
  min-width: 0; overflow-wrap: anywhere;
}
.section-head .hint { font-size: 12.5px; color: var(--ink-3); margin-left: auto; }
.section-head .live-pill { margin-left: 4px; }

/* ═══ Overview: status and state of a unit in one line ═════════════ */

.overview {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  margin: 0 0 24px;
  font-size: 13.5px; color: var(--ink-2);
}
.overview .technical { margin-left: auto; }

/* Technical identifiers: small and subordinate */
.technical { font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); overflow-wrap: anywhere; }

/* ═══ Panel and card ═══════════════════════════════════════════════ */

.panel {
  background: var(--raised); border: 1px solid var(--line-subtle);
  border-radius: var(--r-md); box-shadow: var(--e1); overflow: hidden;
  margin-bottom: 14px;
}
.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 13px 16px; border-bottom: 1px solid var(--line-subtle);
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--ink-2);
}
.panel-head .spacer { flex: 1; }
.panel-body { padding: 14px 16px; }
.panel-body .kv { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 8px 12px; font-size: 12.5px; }
.panel-body .kv dt { color: var(--ink-3); }
.panel-body .kv dd { margin: 0; overflow-wrap: anywhere; }
.panel-actions { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-top: 1px solid var(--line-subtle); }
.panel-actions .btn { width: 100%; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.card {
  display: flex; flex-direction: column; gap: 6px;
  min-width: 0;
  padding: 16px 18px;
  background: var(--raised);
  border: 1px solid var(--line-subtle);
  border-radius: var(--r-md);
  box-shadow: var(--e1);
  color: var(--ink);
  text-decoration: none;
  transition: box-shadow var(--dur-2) var(--ease), border-color var(--dur-2), transform var(--dur-2) var(--ease);
}
a.card:hover, button.card:hover { box-shadow: var(--e2); border-color: var(--line-strong); transform: translateY(-1px); text-decoration: none; }
a.card:focus-visible, button.card:focus-visible { outline: none; box-shadow: var(--focus-ring); }
button.card { font: inherit; text-align: left; cursor: pointer; }
.card-head { display: flex; align-items: center; gap: 9px; color: var(--ink-3); }
.card-title { font-family: var(--font-heading); font-weight: 600; font-size: 14px; color: var(--ink); overflow-wrap: anywhere; }
.card-text { font-size: 12.5px; color: var(--ink-3); }

/* ═══ Key figures ══════════════════════════════════════════════════ */

/* Wraps by the width of its own container, not the window: in a narrow card the tiles stand
   below each other, on a wide area in one row. */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: 14px;
  margin-bottom: 26px;
}

.kpi {
  /* Without min-width: 0 a grid cell keeps the width of its longest word and pushes long numbers over the edge. */
  min-width: 0;
  background: var(--raised);
  border: 1px solid var(--line-subtle);
  border-radius: var(--r-md);
  padding: 14px 16px 12px;
  min-height: 104px;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 2px;
  align-content: start;
  box-shadow: var(--e1);
  transition: box-shadow var(--dur-2) var(--ease), border-color var(--dur-2), transform var(--dur-2) var(--ease);
}
.kpi:hover { box-shadow: var(--e2); border-color: var(--line-strong); transform: translateY(-1px); }

.kpi .kpi-label {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-3);
}
.kpi .kpi-num {
  font-family: var(--font-heading);
  font-weight: 700; font-size: 27px; line-height: 32px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
/* When narrow the card gets smaller, the number stays complete. */
@media (max-width: 520px) {
  .kpi { padding: 12px 13px 10px; min-height: 92px; }
  .kpi .kpi-num { font-size: 21px; line-height: 26px; }
}
.kpi .kpi-sub { font-size: 12px; color: var(--ink-3); }
.kpi .kpi-delta { display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; font-weight: 600; }
.kpi .kpi-delta.up { color: var(--ok); }
.kpi .kpi-delta.down { color: var(--bad); }

/* ═══ Tables ═══════════════════════════════════════════════════════ */

.table-scroll { overflow-x: auto; }

table.dir {
  width: 100%;
  border-collapse: separate; border-spacing: 0;
  background: var(--raised);
  border: 1px solid var(--line-subtle);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--e1);
}
table.dir th {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
  text-align: left;
  color: var(--ink-3);
  padding: 0 14px;
  height: 38px;
  background: var(--base);
  border-bottom: 1px solid var(--line-subtle);
}
/* Long header cells wrap instead of stretching the table beyond the page. */
table.dir th, table.dir td { overflow-wrap: anywhere; }
table.dir th { white-space: normal; }
@media (min-width: 1500px) { table.dir th { white-space: nowrap; } }
table.dir td {
  padding: 0 14px;
  height: var(--row-h);
  border-bottom: 1px solid var(--line-subtle);
  vertical-align: middle;
  font-size: 13.5px;
}
table.dir tbody tr:last-child td { border-bottom: none; }
table.dir tbody tr { transition: background var(--dur-1); }
table.dir tbody tr:hover { background: var(--hover); }
table.dir tr.row-click { cursor: pointer; }
table.dir td.flash { animation: row-flash 1s var(--ease); }
@keyframes row-flash { 0% { background: var(--accent-subtle); } 100% { background: transparent; } }

/* ═══ Toolbar ══════════════════════════════════════════════════════ */

.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin: 0 0 16px;
}
.toolbar select { height: 32px; font-size: 12.5px; }
.toolbar .spacer { flex: 1; }

/* Search with icon */
.search-wrap { position: relative; display: flex; align-items: center; }
.search-wrap .search-ico { position: absolute; left: 10px; color: var(--ink-3); pointer-events: none; display: flex; z-index: 1; }
.search-wrap input { padding-left: 32px; }

/* ═══ Pill: a fact, small and framed ═══════════════════════════════ */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 20px; padding: 0 8px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  color: var(--ink-3); background: var(--sunken);
  border: 1px solid var(--line-subtle); border-radius: var(--r-pill);
  white-space: nowrap;
}
.pill svg { width: 11px; height: 11px; flex: none; }
.pill.ok   { color: var(--ok);   background: var(--ok-bg);   border-color: var(--ok-border); }
.pill.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-border); }
.pill.bad  { color: var(--bad);  background: var(--bad-bg);  border-color: var(--bad-border); }
.pill.info { color: var(--info); background: var(--info-bg); border-color: var(--info-border); }
.pill.acc  { color: var(--acc-hover); background: var(--accent-subtle); border-color: var(--acc-border); }

/* Quieter stamps in the dark theme */
body.dark .stamp {
  background: transparent;
  border-color: color-mix(in srgb, currentColor 32%, transparent);
}
body.dark .stamp .s-ico { opacity: 0.9; }

/* ═══ Fact grid ════════════════════════════════════════════════════ */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.detail-grid .cell {
  background: var(--base);
  border: 1px solid var(--line-subtle);
  border-radius: var(--r-sm);
  padding: 10px 13px;
}
.detail-grid .cell dt {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 3px;
}
.detail-grid .cell dd { margin: 0; font-size: 13px; overflow-wrap: anywhere; word-break: break-word; min-width: 0; }

/* ═══ Empty state and skeleton ═════════════════════════════════════ */

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 38px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  color: var(--ink-2);
  background: var(--raised);
  text-align: center;
  margin-top: 4px;
}
.empty .empty-ico {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--sunken);
  display: grid; place-items: center;
  margin-bottom: 4px;
  color: var(--ink-3);
}
.empty .empty-title { font-weight: 600; font-size: 14px; color: var(--ink); }
.empty .empty-hint { font-size: 13px; color: var(--ink-3); max-width: 48ch; }
.empty .btn { margin-top: 8px; }

.skel {
  background: linear-gradient(100deg, var(--skeleton) 40%, var(--hover) 50%, var(--skeleton) 60%);
  background-size: 200% 100%;
  border-radius: var(--r-sm);
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-row { height: var(--row-h); margin-bottom: 8px; }

/* ═══ Notice and error box ═════════════════════════════════════════ */

.notice {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 10px 13px; border-radius: var(--r-sm);
  background: var(--info-bg); border: 1px solid var(--info-border);
  color: var(--ink-2); font-size: 12.5px; line-height: 1.5; margin-top: 12px;
}
.notice.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.notice svg { flex: none; margin-top: 1px; color: var(--info); }
.notice.warn svg { color: var(--warn); }

.error-box {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 14px 16px;
  border: 1px solid var(--bad-border);
  border-left: 3px solid var(--bad);
  border-radius: var(--r-sm);
  background: var(--bad-bg);
  color: var(--ink-2); font-size: 13px; line-height: 1.5;
}
.error-box > svg { flex: none; margin-top: 2px; color: var(--bad); }
.error-box .error-title { font-weight: 600; color: var(--bad); }
.error-box .error-text { margin: 2px 0 0; }
.error-box .technical { display: block; margin-top: 6px; }
.error-box .btn { margin-top: 10px; }

/* ═══ Form ═════════════════════════════════════════════════════════ */

.form { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.form-row input, .form-row select, .form-row textarea { display: block; width: 100%; margin-top: 5px; }
.form-row .form-row-help { display: block; margin-top: 4px; font-size: 11.5px; font-weight: 400; color: var(--ink-3); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

/* ═══ Tabs ═════════════════════════════════════════════════════════ */

.tabs { display: flex; flex-direction: column; gap: 13px; }
/* The bar scrolls horizontally instead of widening the page on narrow windows. */
.tab-bar {
  display: flex; gap: 3px; border-bottom: 1px solid var(--line-subtle);
  overflow-x: auto; scrollbar-width: thin; scroll-snap-type: x proximity;
}
.tab-bar::-webkit-scrollbar { height: 4px; }
.tab-bar::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 2px; }
.tab-button {
  display: inline-flex; align-items: center; gap: 6px;
  flex: none;
  margin-bottom: -1px; padding: 8px 13px;
  border: 0; border-bottom: 2px solid transparent;
  background: none; color: var(--ink-3);
  font: 500 12.5px/1.3 var(--font-body); cursor: pointer;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  scroll-snap-align: start;
  transition: color var(--dur-1), border-color var(--dur-1), background var(--dur-1);
}
.tab-button:hover { color: var(--ink); background: var(--sunken); }
.tab-button.is-an, .tab-button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--acc); font-weight: 600; }
.tab-button:focus-visible { outline: 2px solid var(--acc); outline-offset: -2px; }
.tab-button svg { flex: none; }
.tab-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; padding: 1px 6px;
  border-radius: var(--r-pill);
  background: var(--sunken); color: var(--ink-3);
  font-size: 10.5px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.tab-button.is-an .tab-count, .tab-button[aria-selected="true"] .tab-count { background: color-mix(in srgb, var(--acc) 14%, transparent); color: var(--acc); }
.tab-panel:focus-visible { outline: 2px solid var(--acc); outline-offset: 3px; border-radius: var(--r-sm); }

/* ═══ Disclosure block ═════════════════════════════════════════════ */

.disclosure { margin-top: 4px; }
.disclosure > summary {
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; list-style: none;
  color: var(--ink-2); font-size: 12.5px;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary:hover { color: var(--ink); }
.disclosure[open] > summary { color: var(--ink); font-weight: 600; }
.disclosure-arrow { display: inline-grid; place-items: center; flex: none; color: var(--ink-3); transition: transform var(--dur-1) var(--ease); }
.disclosure[open] > summary > .disclosure-arrow { transform: rotate(90deg); }
.disclosure-body {
  padding: 8px 10px; margin-top: 4px;
  background: var(--sunken);
  border: 1px solid var(--line-subtle);
  border-radius: var(--r-sm);
  font-size: 12.5px;
}

/* ═══ Dialog ═══════════════════════════════════════════════════════ */

.modal-backdrop {
  position: fixed; inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: 50;
  padding: 20px;
  animation: fade-in var(--dur-1);
}
@keyframes fade-in { from { opacity: 0; } }

.modal {
  width: min(600px, 94vw);
  max-height: 86vh;
  overflow: auto;
  background: var(--raised);
  border: 1px solid var(--line-subtle);
  border-radius: var(--r-lg);
  box-shadow: var(--e4);
  padding: 24px 26px 22px;
  animation: modal-in var(--dur-3) var(--ease);
}
.modal.wide { width: min(940px, 96vw); max-height: 92vh; }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } }

.modal h3 {
  font-family: var(--font-heading);
  font-weight: 600; font-size: 16.5px; letter-spacing: -0.01em;
  margin: 0 0 18px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line-subtle);
}
.modal label {
  display: block;
  font-size: 12px; font-weight: 600; color: var(--ink-2);
  letter-spacing: 0.02em;
  margin-bottom: 12px;
}
.modal input, .modal select, .modal textarea { display: block; width: 100%; margin-top: 6px; }
.modal textarea { min-height: 96px; }
.modal .modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 22px;
  padding-top: 15px;
  border-top: 1px solid var(--line-subtle);
}
.modal .modal-actions .btn { width: auto; }
.modal.danger h3 { color: var(--bad); }
.modal .modal-text { margin: 0; color: var(--ink-2); max-width: 46ch; }
.modal .modal-consequence {
  margin: 12px 0 0; padding: 10px 12px;
  border-radius: 6px; border: 1px solid var(--bad-border);
  background: var(--bad-bg); color: var(--bad); font-size: 12.5px;
}

/* ═══ Messages ═════════════════════════════════════════════════════ */

#toast-root {
  position: fixed; right: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 60;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  min-width: 290px; max-width: 410px;
  background: var(--raised);
  border: 1px solid var(--line-subtle);
  border-left: 3px solid var(--acc);
  border-radius: var(--r-sm);
  box-shadow: var(--e3);
  padding: 12px 13px 12px 15px;
  font-size: 13px;
  animation: toast-in var(--dur-3) var(--ease);
  transition: opacity 200ms;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(18px); } }
.toast.err { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
.toast.leaving { opacity: 0; }
.toast .t-ico { flex: none; display: grid; place-items: center; color: var(--ok); }
.toast.err .t-ico { color: var(--bad); }
.toast .t-body { min-width: 0; }
.toast .t-title { font-weight: 600; }
.toast .t-detail { color: var(--ink-3); font-size: 12px; margin-top: 1px; }
.toast .linklike { margin-top: 4px; font-size: 12px; }
@media (max-width: 980px) { #toast-root { bottom: 76px; left: 12px; right: 12px; } .toast { min-width: 0; } }

/* ═══ Right drawer ═════════════════════════════════════════════════ */

.drawer-backdrop {
  position: fixed; inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 55;
  display: flex; justify-content: flex-end;
  animation: fade-in var(--dur-1);
}
.drawer {
  width: min(640px, 92vw);
  height: 100vh;
  background: var(--raised);
  border-left: 1px solid var(--line-subtle);
  box-shadow: var(--e4);
  display: flex; flex-direction: column;
  animation: drawer-in var(--dur-3) var(--ease);
  overflow: hidden;
}
@keyframes drawer-in { from { transform: translateX(44px); opacity: 0; } }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 22px;
  border-bottom: 1px solid var(--line-subtle);
  flex: none;
  background: var(--base);
}
.drawer-head h3 {
  font-family: var(--font-heading);
  font-size: 15.5px; font-weight: 600; margin: 0;
  letter-spacing: -0.005em;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 22px 34px; }

/* ═══ Stage of a surface ═══════════════════════════════════════════ */

/* The stage is the only place where a surface draws. It has its own frame and passes its height
   on to the module; whether it spreads out in it, the module decides. */
.surface-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 320px;
  padding: 16px;
  background: var(--raised);
  border: 1px solid var(--line-subtle);
  border-radius: var(--r-md);
  box-shadow: var(--e1);
  overflow: auto;
}
.surface-stage > * { flex: 1 1 auto; min-height: 0; }
.surface-stage > .empty, .surface-stage > .error-box { flex: none; }
.surface-loading { flex: none; padding: 18px 4px; color: var(--ink-3); font-size: 12.5px; }
