/* NP Connect — fleet manager for TI-84 Evo calculators. Original styling; tokens on :root. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #dfe3e8;
  --border-strong: #c5ccd5;
  --text: #17202b;
  --text-2: #4a5666;
  --text-3: #5f6b7a;
  --accent: #c8102e;          /* calculator red, used sparingly */
  --accent-ink: #ffffff;
  --primary: #1d2733;          /* dark buttons */
  --primary-ink: #ffffff;
  --focus: #2f6fdf;
  --ok: #1f8a4c;
  --ok-bg: #e5f5ec;
  --warn: #a35d00;
  --warn-bg: #fff3df;
  --err: #c0262d;
  --err-bg: #fde9ea;
  --info: #2457b8;
  --info-bg: #e7efff;
  --idle: #5d6876;
  --idle-bg: #edf0f3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --surface: #171d24;
    --surface-2: #1d242c;
    --border: #2a333d;
    --border-strong: #3a4552;
    --text: #e8edf2;
    --text-2: #b0bac6;
    --text-3: #808b98;
    --primary: #e8edf2;
    --primary-ink: #11161c;
    --ok: #4cc283;  --ok-bg: #12301f;
    --warn: #f0a54a; --warn-bg: #33250f;
    --err: #ff6b70; --err-bg: #3a1618;
    --info: #79a6ff; --info-bg: #162441;
    --idle: #9aa5b2; --idle-bg: #232b34;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419;
  --surface: #171d24;
  --surface-2: #1d242c;
  --border: #2a333d;
  --border-strong: #3a4552;
  --text: #e8edf2;
  --text-2: #b0bac6;
  --text-3: #808b98;
  --primary: #e8edf2;
  --primary-ink: #11161c;
  --ok: #4cc283;  --ok-bg: #12301f;
  --warn: #f0a54a; --warn-bg: #33250f;
  --err: #ff6b70; --err-bg: #3a1618;
  --info: #79a6ff; --info-bg: #162441;
  --idle: #9aa5b2; --idle-bg: #232b34;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 var(--font);
  color: var(--text);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- App frame ---------- */
.app { display: grid; grid-template-rows: auto auto 1fr; min-height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: .2px; white-space: nowrap; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 13px; font-weight: 800;
}
.brand small { font-weight: 500; color: var(--text-3); font-size: 12px; }
.stats { display: flex; gap: 14px; margin-left: 8px; flex-wrap: wrap; }
.stat { display: flex; align-items: baseline; gap: 5px; color: var(--text-2); font-size: 13px; }
.stat b { color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }
.topbar .spacer { flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap; font-weight: 600; font-size: 13px;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.15); background: var(--primary); }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.icon { width: 34px; padding: 0; }
.btn svg { width: 16px; height: 16px; flex: none; }
.ico { display: inline-flex; width: 16px; height: 16px; flex: none; }
.ico svg { width: 100%; height: 100%; }
.action-card .ac-icon .ico { width: 18px; height: 18px; }
.tile .ico { width: 14px; height: 14px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--text-2); }
.tile-actions { display: flex; gap: 4px; margin-left: auto; }
.tile-result { font-size: 12px; line-height: 1.35; color: var(--text-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile-result.ok { color: var(--ok); }
.tile-result.error { color: var(--err); }
.tile-result.skipped { color: var(--text-3); }
.tile-activity { font-size: 12px; color: var(--info); min-height: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-banner { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius); background: var(--warn-bg); border: 1px solid var(--border); }
.cart-banner b { color: var(--text); }
.jobs { display: flex; flex-direction: column; gap: 6px; padding: 0 20px 10px; }
.job { display: flex; align-items: center; gap: 10px; font-size: 12.5px; }
.job .progress { max-width: 260px; }
.check-row { display: flex; align-items: flex-start; gap: 8px; font-weight: 500; }
.check-row input { margin-top: 3px; }
.kbd { font-family: var(--mono); font-size: 12px; padding: 1px 5px; border-radius: 4px; background: var(--idle-bg); }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.small { font-size: 12px; }
.ico.big { width: 40px; height: 40px; color: var(--text-3); }
.btn .ico { width: 16px; height: 16px; }
.btn.sm .ico { width: 14px; height: 14px; }
.dropzone .ico { width: 26px; height: 26px; margin-bottom: 4px; }
.seg button .ico { vertical-align: middle; }

/* ---------- Action cards ---------- */
.actions {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px;
  padding: 16px 20px 0;
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.action-card {
  display: flex; flex-direction: column; gap: 8px; padding: 14px 14px 12px; text-align: left;
  cursor: pointer; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--text);
}
.action-card:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface-2); }
.action-card:disabled { opacity: .5; cursor: not-allowed; }
.action-card .ac-head { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 14px; }
.action-card .ac-icon {
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
  background: var(--idle-bg); color: var(--text);
}
.action-card .ac-icon svg { width: 18px; height: 18px; }
.action-card .ac-desc { color: var(--text-2); font-size: 12.5px; }

/* ---------- Fleet area ---------- */
.fleet { padding: 16px 20px 24px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar .search {
  height: 34px; min-width: 200px; flex: 1 1 220px; max-width: 360px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 0 10px; background: var(--surface);
}
.toolbar select {
  height: 34px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 0 8px; background: var(--surface);
}
.selcount { color: var(--text-2); font-size: 13px; margin-right: auto; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { border: 0; background: var(--surface); height: 32px; padding: 0 10px; cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.seg button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.tile {
  position: relative; display: flex; flex-direction: column; gap: 8px; padding: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  min-width: 0;
}
.tile.selected { border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus), var(--shadow); }
.tile.offline { background: var(--surface-2); border-style: dashed; box-shadow: none; }
.tile.offline .tile-name, .tile.offline .tile-meta dd { color: var(--text-2); }
.tile.offline .tile-thumb { filter: grayscale(1); opacity: .7; }
.tile.done { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok), var(--shadow); background: linear-gradient(var(--ok-bg), var(--surface) 70%); }
.tile.done .tile-result { font-weight: 700; }
.tile-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tile-head input[type=checkbox] { width: 16px; height: 16px; margin: 0; flex: none; accent-color: var(--focus); }
.tile-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; border: 0; background: transparent; padding: 0; text-align: left; cursor: pointer; }
.tile-name:hover { text-decoration: underline; }
.tile-meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 12.5px; color: var(--text-2); }
.tile-meta dt { color: var(--text-3); }
.tile-meta dd { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tile-foot { display: flex; align-items: center; gap: 8px; min-height: 22px; }
.tile-thumb { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; image-rendering: pixelated; border-radius: 6px; border: 1px solid var(--border); background: #000; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--idle-bg); color: var(--idle);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.err { background: var(--err-bg); color: var(--err); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.busy::before { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.badge { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }

.progress { height: 6px; border-radius: 999px; background: var(--idle-bg); overflow: hidden; flex: 1; }
.progress > i { display: block; height: 100%; width: 0; background: var(--info); transition: width .25s ease; }
.progress.ok > i { background: var(--ok); }
.progress.err > i { background: var(--err); }

/* table view */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table.devices { width: 100%; border-collapse: collapse; font-size: 13px; }
table.devices th, table.devices td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.devices th { font-size: 12px; color: var(--text-3); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
table.devices tr.selected td { background: var(--info-bg); }
table.devices td.progress-cell { min-width: 140px; }

.empty {
  display: grid; place-items: center; gap: 10px; text-align: center; padding: 48px 16px;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-2); background: var(--surface);
}
.empty h2 { margin: 0; font-size: 17px; color: var(--text); }
.empty p { margin: 0; max-width: 520px; }

/* ---------- Dialogs ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg); width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog::backdrop { background: rgba(10, 14, 20, .45); }
dialog.ask { width: min(460px, calc(100vw - 32px)); }
.dlg { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; font-size: 16px; flex: 1; }
.dlg-body { padding: 16px 18px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.dlg-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font-weight: 600; font-size: 13px; }
.field .hint { color: var(--text-3); font-size: 12px; }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  height: 34px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 0 10px; background: var(--surface);
}
.field textarea { height: auto; min-height: 70px; padding: 8px 10px; }
.radio-row { display: flex; gap: 16px; flex-wrap: wrap; }
.radio-row label { display: inline-flex; gap: 6px; align-items: center; font-weight: 500; }
.callout { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; background: var(--info-bg); color: var(--text); border: 1px solid transparent; }
.callout.warn { background: var(--warn-bg); }
.callout.err { background: var(--err-bg); }
.file-list { border: 1px solid var(--border); border-radius: var(--radius-sm); max-height: 220px; overflow: auto; }
.file-list div { display: flex; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.file-list div:last-child { border-bottom: 0; }
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--text-2);
  background: var(--surface-2); cursor: pointer;
}
.dropzone.over { border-color: var(--focus); background: var(--info-bg); }

/* ---------- Drawer (device details) ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); z-index: 40;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; transform: translateX(105%); transition: transform .2s ease;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { overflow: auto; padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 16px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); font-weight: 700; margin: 0 0 6px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; word-break: break-word; }
.screen-big { width: 100%; image-rendering: pixelated; border-radius: 8px; border: 1px solid var(--border); background: #000; }
table.files { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.files th, table.files td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
table.files th { color: var(--text-3); font-weight: 600; }

/* ---------- Activity log ---------- */
.activity { border-top: 1px solid var(--border); background: var(--surface); }
.activity summary { cursor: pointer; padding: 10px 20px; font-weight: 600; font-size: 13px; color: var(--text-2); list-style: none; display: flex; gap: 8px; align-items: center; }
.activity summary::-webkit-details-marker { display: none; }
.log { max-height: 240px; overflow: auto; padding: 0 20px 12px; font: 12px/1.5 var(--mono); color: var(--text-2); }
.log .err { color: var(--err); }
.log .ok { color: var(--ok); }
.log .warn { color: var(--warn); }

/* ---------- Gallery ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.gallery img { width: 100%; image-rendering: pixelated; border-radius: 6px; border: 1px solid var(--border); background: #000; }
.gallery figcaption { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Blocking notices ---------- */
.blocker { max-width: 640px; margin: 48px auto; padding: 24px; }
.blocker h1 { font-size: 20px; margin: 0 0 8px; }
.blocker li { margin: 4px 0; }

.toast-host { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--primary); color: var(--primary-ink); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-lg); font-size: 13px; max-width: min(560px, calc(100vw - 32px)); }
.toast.err { background: #b3261e; color: #fff; }
.linkish { border: 0; background: none; padding: 0; color: var(--info); text-decoration: underline; cursor: pointer; font: inherit; }
.btn.primary.danger-fill { background: #b3261e; border-color: #b3261e; color: #fff; }
label.field { cursor: default; }

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .stats { order: 10; flex-basis: 100%; margin-left: 0; }
}

@media (max-width: 640px) {
  .actions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .action-card { padding: 10px; }
  .action-card .ac-desc { display: none; }
  .action-card .ac-head { font-size: 13px; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .actions, .fleet { padding-left: 16px; padding-right: 16px; }
  .activity summary, .log { padding-left: 16px; padding-right: 16px; }
  .kv { grid-template-columns: 110px 1fr; }
  .toolbar .search { max-width: none; }
}
