/* Dipper-IG — interface stylesheet.
   Neutral, information-dense design system: tokens first, then layout, then components. */

/* ---------------------------------------------------------------- tokens */
:root {
  --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --surface-3: #e9e9e5;
  --border: #e3e3df;
  --border-strong: #cfcfca;
  --text: #19191c;
  --text-2: #55555d;
  --text-3: #8b8b93;

  --accent: #2f55c4;
  --accent-soft: #e8edfb;
  --primary-bg: #19191c;
  --primary-fg: #ffffff;
  --primary-hover: #34343a;

  --ok: #2c7a4b;      --ok-soft: #e7f2ea;
  --warn: #9a5d0b;    --warn-soft: #f8eedd;
  --err: #b0362b;     --err-soft: #f8e6e3;
  --info: #2f55c4;    --info-soft: #e8edfb;
  --neutral: #6b6b73; --neutral-soft: #ececea;

  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 8px;
  --shadow-pop: 0 1px 2px rgba(20, 20, 25, .06), 0 8px 24px rgba(20, 20, 25, .10);
  --sidebar-w: 224px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #17171a;
    --surface-2: #1d1d21;
    --surface-3: #26262b;
    --border: #2a2a2f;
    --border-strong: #3a3a41;
    --text: #ececee;
    --text-2: #a3a3ab;
    --text-3: #707078;

    --accent: #8aa4ff;
    --accent-soft: #1f2640;
    --primary-bg: #ececee;
    --primary-fg: #111113;
    --primary-hover: #d4d4d8;

    --ok: #6cc28d;      --ok-soft: #17291f;
    --warn: #e0a54a;    --warn-soft: #2e2415;
    --err: #ef7f73;     --err-soft: #331b18;
    --info: #8aa4ff;    --info-soft: #1f2640;
    --neutral: #9a9aa2; --neutral-soft: #232327;
    --shadow-pop: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1;
}
a { color: inherit; text-decoration: none; }
a.link, .link { color: var(--accent); }
a.link:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
code, .mono { font-family: var(--font-mono); font-size: 12.5px; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- layout */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  padding: 16px 12px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-mark {
  width: 24px; height: 24px; border-radius: var(--radius-sm);
  background: var(--primary-bg); color: var(--primary-fg);
  display: grid; place-items: center;
  font: 600 13px/1 var(--font-mono);
}
.brand-name { font-weight: 600; letter-spacing: -.01em; }
.brand-name span { color: var(--text-3); font-weight: 400; }

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-label { padding: 14px 8px 6px; font-size: 11.5px; color: var(--text-3); }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: var(--radius);
  color: var(--text-2);
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 500; }
.nav a[aria-current="page"] .icon { color: var(--accent); }
.nav .count { margin-left: auto; font-size: 12px; color: var(--text-3); }

.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); display: grid; gap: 6px; font-size: 12px; color: var(--text-3); }
.live { display: flex; align-items: center; gap: 8px; }
.live .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--neutral); }
.live[data-state="open"] .dot { background: var(--ok); }
.live[data-state="closed"] .dot { background: var(--err); }

.main { min-width: 0; padding: 28px 36px 64px; }
.container { max-width: 1180px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-title { font-size: 20px; font-weight: 600; letter-spacing: -.015em; }
.page-sub { margin-top: 2px; color: var(--text-2); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-title { font-size: 14px; font-weight: 600; }
.section-meta { font-size: 12.5px; color: var(--text-3); }

.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: 500 13px/1 var(--font-sans);
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-fg); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--err); }
.btn-danger:hover { background: var(--err-soft); border-color: var(--err); }
.btn-sm { height: 26px; padding: 0 8px; font-size: 12.5px; }
.btn-icon { width: 28px; height: 28px; padding: 0; }
.btn[aria-busy="true"] { opacity: .6; pointer-events: none; }

/* ---------------------------------------------------------------- forms */
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 12.5px; font-weight: 500; color: var(--text); }
.hint { font-size: 12px; color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; height: 32px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: 400 13.5px/1.4 var(--font-sans);
}
.textarea { height: auto; padding: 8px 10px; font-family: var(--font-mono); font-size: 12.5px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.select { appearance: none; padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' stroke='%238b8b93' stroke-width='1.5'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.select-sm { height: 26px; font-size: 12.5px; padding-left: 8px; }
.input-mono { font-family: var(--font-mono); font-size: 12.5px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); }
.check input { width: 15px; height: 15px; margin: 0; accent-color: var(--primary-bg); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.form-section { display: grid; gap: 14px; padding: 18px 0; border-top: 1px solid var(--border); }
.dialog-body > .form-section:first-child, .form-error + .form-section { border-top: 0; padding-top: 0; }
.form-section > legend { float: left; width: 100%; }
.form-section > legend + * { clear: both; }
.form-section > legend, .form-section-title { font-size: 13px; font-weight: 600; padding: 0; margin-bottom: 2px; }

.segmented { display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 4px 10px; border-radius: var(--radius-sm); font-size: 12.5px; color: var(--text-2); cursor: pointer; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); font-weight: 500; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
.segmented a { display: block; padding: 4px 10px; border-radius: var(--radius-sm); font-size: 12.5px; color: var(--text-2); }
.segmented a[aria-current="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); font-weight: 500; }

/* ---------------------------------------------------------------- surfaces */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.panel-pad { padding: 16px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.kpi { padding: 14px 16px; border-left: 1px solid var(--border); min-width: 0; }
.kpi:first-child { border-left: 0; }
.kpi-label { font-size: 12.5px; color: var(--text-2); }
.kpi-value { margin-top: 4px; font-size: 22px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 13px; font-weight: 400; color: var(--text-3); letter-spacing: 0; }
.kpi-foot { margin-top: 2px; font-size: 12px; color: var(--text-3); }

.meter { height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; margin-top: 8px; }
.meter > span { display: block; height: 100%; background: var(--text-2); }
.meter[data-level="high"] > span { background: var(--warn); }
.meter[data-level="full"] > span { background: var(--err); }

.notice { display: flex; gap: 12px; align-items: flex-start; padding: 10px 14px; border: 1px solid var(--border); border-left: 3px solid var(--warn); border-radius: var(--radius); background: var(--surface); }
.notice + .notice { margin-top: 8px; }
.notice[data-tone="err"] { border-left-color: var(--err); }
.notice-title { font-weight: 500; }
.notice-body { color: var(--text-2); font-size: 13px; }
.notice .btn { margin-left: auto; }

/* ---------------------------------------------------------------- tables */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 8px 14px; text-align: left; white-space: nowrap;
  font-size: 12px; font-weight: 500; color: var(--text-3);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table .num { text-align: right; }
.table th.num { text-align: right; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * + * { margin-left: 4px; }
.cell-main { font-weight: 500; }
.cell-sub { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.cell-error { font-size: 12px; color: var(--text-3); max-width: 320px; margin-top: 3px; }

.empty { padding: 40px 16px; text-align: center; color: var(--text-2); }
.empty-title { color: var(--text); font-weight: 500; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 1px 8px 1px 7px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  color: var(--neutral); background: var(--neutral-soft);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge[data-tone="ok"] { color: var(--ok); background: var(--ok-soft); }
.badge[data-tone="warn"] { color: var(--warn); background: var(--warn-soft); }
.badge[data-tone="err"] { color: var(--err); background: var(--err-soft); }
.badge[data-tone="info"] { color: var(--info); background: var(--info-soft); }
.badge[data-tone="info"][data-live]::before { animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .25; } }
.tag { display: inline-block; padding: 0 6px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 11.5px; color: var(--text-2); line-height: 18px; }

/* ---------------------------------------------------------------- menus */
.menu { position: relative; display: inline-block; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30;
  min-width: 170px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop); text-align: left;
}
.menu-list button, .menu-list a {
  display: flex; width: 100%; align-items: center; gap: 8px;
  padding: 6px 8px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text); font: 400 13px/1.3 var(--font-sans); cursor: pointer;
}
.menu-list button:hover, .menu-list a:hover { background: var(--surface-2); }
.menu-list .danger { color: var(--err); }
.menu-list hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---------------------------------------------------------------- dialogs */
dialog { padding: 0; border: 0; color: var(--text); background: transparent; max-width: none; max-height: none; }
dialog::backdrop { background: rgba(15, 15, 18, .38); }
.drawer {
  margin: 0 0 0 auto; width: min(520px, 100vw); height: 100vh;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-pop);
}
.drawer[open] { display: flex; flex-direction: column; animation: drawer-in .16s ease-out; }
@keyframes drawer-in { from { transform: translateX(16px); opacity: .6; } }
.modal {
  width: min(460px, calc(100vw - 32px)); margin: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
}
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dialog-title { font-size: 15px; font-weight: 600; }
.dialog-body { padding: 20px; overflow-y: auto; flex: 1; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface); }
.dialog-foot .left { margin-right: auto; }
.form-error { padding: 8px 12px; border-radius: var(--radius); background: var(--err-soft); color: var(--err); font-size: 13px; }

.tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs button { padding: 0 0 10px; border: 0; background: none; color: var(--text-2); font: 500 13px/1 var(--font-sans); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); }
.steps { margin: 0; padding-left: 18px; color: var(--text-2); font-size: 13px; display: grid; gap: 4px; }

/* ---------------------------------------------------------------- library */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 8px; }
.tile {
  position: relative; display: block; width: 100%; aspect-ratio: 1; padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface-2); cursor: pointer;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s ease; }
.tile:hover img { transform: scale(1.03); }
.tile .tile-kind { position: absolute; top: 6px; right: 6px; color: #fff; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.tile .tile-meta {
  position: absolute; inset: auto 0 0 0; padding: 18px 8px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,.55));
  color: #fff; font-size: 11.5px; text-align: left; opacity: 0; transition: opacity .15s;
}
.tile:hover .tile-meta, .tile:focus-visible .tile-meta { opacity: 1; }
.tile.no-thumb::after { content: attr(data-fallback); position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); font-size: 12px; }
.load-more { display: flex; justify-content: center; margin-top: 20px; }

.viewer { width: min(1100px, calc(100vw - 32px)); height: min(760px, calc(100vh - 48px)); margin: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-pop); }
.viewer[open] { display: grid; grid-template-columns: minmax(0, 1fr) 320px; }
.viewer-stage { position: relative; background: #0c0c0e; display: grid; place-items: center; min-height: 0; }
.viewer-stage img, .viewer-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.viewer-nav { position: absolute; z-index: 1; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(255,255,255,.85); color: #111; cursor: pointer; display: grid; place-items: center; }
.viewer-nav.prev { left: 12px; } .viewer-nav.next { right: 12px; }
.viewer-count { position: absolute; z-index: 1; bottom: 12px; left: 50%; transform: translateX(-50%); padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; }
.viewer-side { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--border); }
.viewer-side .dialog-body { display: grid; gap: 16px; align-content: start; }
.meta-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: 13px; }
.meta-list dt { color: var(--text-3); }
.meta-list dd { margin: 0; }
.caption { white-space: pre-wrap; font-size: 13px; color: var(--text-2); max-height: 260px; overflow-y: auto; }

/* ---------------------------------------------------------------- activity */
.activity { display: grid; }
.activity-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--border); }
.activity-item:first-child { border-top: 0; }
.activity-stats { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); margin-top: 3px; flex-wrap: wrap; }
.activity-stats b { color: var(--text); font-weight: 500; }

/* ---------------------------------------------------------------- toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 8px; width: min(380px, calc(100vw - 40px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--neutral);
  border-radius: var(--radius); box-shadow: var(--shadow-pop); font-size: 13px;
  animation: toast-in .18s ease-out;
}
.toast[data-tone="ok"] { border-left-color: var(--ok); }
.toast[data-tone="warn"] { border-left-color: var(--warn); }
.toast[data-tone="err"] { border-left-color: var(--err); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 500; }
.toast-text { color: var(--text-2); margin-top: 1px; overflow-wrap: anywhere; }
.toast button { border: 0; background: none; color: var(--text-3); cursor: pointer; padding: 0; }
@keyframes toast-in { from { transform: translateY(6px); opacity: 0; } }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 960px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(3) { border-left: 0; }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--border); }
  .viewer[open] { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .viewer-side { border-left: 0; border-top: 1px solid var(--border); max-height: 40vh; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 8px; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand { padding: 0 8px 0 0; }
  .brand-name { display: none; }
  .nav { flex-direction: row; }
  .nav-label, .nav .count, .sidebar-foot .version { display: none; }
  .nav a { white-space: nowrap; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
  .main { padding: 20px 16px 48px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .grid-2 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
