/* PCB Flasher — Fleet Console. Light theme, restrained, professional. */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1c2430;
  --ink-soft: #5b6675;
  --line: #e3e7ec;
  --accent: #2563eb;
  --accent-soft: #eaf1ff;
  --green: #1f9d55;
  --green-soft: #e6f6ec;
  --red: #d64545;
  --red-soft: #fbeaea;
  --amber: #c98a1b;
  --amber-soft: #fbf2dd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 45, .06), 0 4px 16px rgba(20, 30, 45, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0; font-family: var(--font); color: var(--ink);
  background: var(--bg); font-size: 14px; line-height: 1.5;
}

/* --- top bar --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand .logo { width: 26px; height: 26px; color: var(--accent); fill: none;
  stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.brand .sub { color: var(--ink-soft); font-weight: 400; }
.conn { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-on { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.dot-off { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.logout-link { margin-left: 14px; color: var(--ink-soft); font-size: 13px;
  text-decoration: none; border: 1px solid var(--line); border-radius: 7px;
  padding: 4px 10px; transition: background .12s, color .12s; }
.logout-link:hover { background: #f3f5f8; color: var(--ink); }

/* --- layout --- */
.layout {
  display: grid; grid-template-columns: 320px 1fr; gap: 16px;
  padding: 16px; align-items: start;
}
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }

/* --- firmware library drawer (opened from the header button) --- */
.fw-toggle { margin-left: 6px; }
.fw-backdrop { position: fixed; inset: 0; background: rgba(20,30,45,.35);
  z-index: 40; }
.fw-drawer { position: fixed; top: 0; right: 0; z-index: 41; width: min(420px, 94vw);
  height: 100vh; overflow-y: auto; border-radius: 0; border-top: none;
  border-bottom: none; border-right: none; box-shadow: -8px 0 24px rgba(20,30,45,.12);
  animation: fwslide .18s ease-out; }
@keyframes fwslide { from { transform: translateX(20px); opacity: .6; } to { transform: translateX(0); opacity: 1; } }
.fw-close { padding: 5px 10px; font-size: 12px; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
.panel.grow { min-height: 60vh; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-head h2 { font-size: 15px; margin: 0; }
.pill { background: var(--accent-soft); color: var(--accent); border-radius: 999px;
  padding: 2px 10px; font-size: 12px; font-weight: 600; }

/* --- fleet list --- */
.fleet { display: flex; flex-direction: column; gap: 8px; }
.station {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  cursor: pointer; transition: border-color .12s, background .12s; background: #fff;
}
.station:hover { border-color: #cdd6e2; background: #fafbfc; }
.station.selected { border-color: var(--accent); background: var(--accent-soft); }
.station-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.station-name { font-weight: 600; }
.station-id { color: var(--ink-soft); font-size: 12px; font-weight: 400; }
.station-venue { color: var(--ink-soft); font-size: 12px; margin-top: 2px; }
.station-meta { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 6px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px; }
.badge-online { background: var(--green-soft); color: var(--green); }
.badge-offline { background: var(--red-soft); color: var(--red); }
.badge-available { background: var(--accent-soft); color: var(--accent); }
.badge-armed { background: var(--amber-soft); color: var(--amber); }
.badge-family { background: #eef1f5; color: var(--ink-soft); }
.status-led { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.led-green { background: var(--green); }
.led-red { background: var(--red); }
.led-grey { background: #c2cad6; }

/* --- detail --- */
.detail { display: flex; flex-direction: column; gap: 16px; }
.empty { color: var(--ink-soft); text-align: center; padding: 48px 16px; }
.empty-icon { width: 44px; height: 44px; color: #c2cad6; fill: none;
  stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; margin-bottom: 8px; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kv .cell { background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.kv .cell .label { font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .03em; }
.kv .cell .val { font-weight: 600; margin-top: 2px; }

/* --- MODE 1: Live Flashing container --- */
.live { display: flex; align-items: center; gap: 14px; border-radius: var(--radius);
  padding: 18px 20px; border: 1px solid var(--line); transition: all .2s; }
.live .live-title { font-weight: 700; font-size: 16px; }
.live .live-sub { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.live-dot { width: 14px; height: 14px; border-radius: 50%; background: #c2cad6;
  flex-shrink: 0; }
/* Idle: calm, muted, small visual weight. */
.live-idle { background: #fafbfc; }
.live-idle .live-title { color: var(--ink-soft); font-size: 15px; }
/* Active: big, green, alive — only when a board is really plugged in. */
.live-active { display: block; background: var(--green-soft); border-color: #a9e0bd;
  padding: 22px; box-shadow: 0 0 0 4px rgba(31,157,85,.08); }
.live-active .live-title { color: var(--green); }
.live-chip-tag { vertical-align: middle; margin-left: 6px; }
.live-top { display: flex; align-items: center; gap: 14px; }
.live-action { display: flex; gap: 10px; align-items: center; margin-top: 16px; }
.live-action .prov-select { flex: 1; }
.live-hint { color: var(--ink-soft); font-size: 12px; margin-top: 8px; }
.live-top { justify-content: space-between; }
.live-monitor-btn { display: inline-flex; align-items: center; gap: 6px;
  flex-shrink: 0; align-self: flex-start; }
.live-monitor-btn svg { color: var(--green); }

/* --- live serial monitor overlay --- */
.monitor-overlay { position: fixed; inset: 0; z-index: 60;
  background: rgba(20,30,45,.45); display: flex; align-items: center;
  justify-content: center; padding: 24px; }
.monitor-panel { background: var(--panel); border-radius: var(--radius);
  box-shadow: var(--shadow); width: min(880px, 96vw); height: min(640px, 90vh);
  display: flex; flex-direction: column; overflow: hidden; }
.monitor-head { display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.monitor-title { display: flex; align-items: center; gap: 9px; font-weight: 700;
  font-size: 15px; }
.monitor-station { color: var(--ink-soft); font-weight: 400; font-size: 13px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.monitor-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.monitor-dot-on { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft);
  animation: livepulse 1.4s ease-in-out infinite; }
.monitor-dot-connecting { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.monitor-dot-off { background: #c2cad6; }
.monitor-controls { display: flex; align-items: center; gap: 8px; }
.monitor-baud-label { font-size: 12px; color: var(--ink-soft);
  display: inline-flex; align-items: center; gap: 6px; }
.monitor-baud-label select { padding: 5px 8px; border: 1px solid var(--line);
  border-radius: 7px; font-family: inherit; font-size: 13px; background: #fff; }
.monitor-controls .btn { padding: 5px 11px; font-size: 12px; }
.monitor-body { flex: 1; overflow: auto; background: #1c2430; color: #e7ecf3;
  padding: 12px 14px; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12.5px; line-height: 1.55; }
.monitor-line { white-space: pre-wrap; word-break: break-word; }
.monitor-foot { padding: 8px 16px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--ink-soft); }
.monitor-statustext { display: inline-flex; align-items: center; }
@media (max-width: 560px) {
  .monitor-overlay { padding: 0; }
  .monitor-panel { width: 100vw; height: 100vh; border-radius: 0; }
}

/* live flash progress bar */
.flash-bar { margin-top: 14px; height: 10px; border-radius: 6px;
  background: rgba(31,157,85,.15); overflow: hidden; }
.flash-bar-fill { height: 100%; background: var(--green); border-radius: 6px;
  transition: width .3s ease; min-width: 2%; }
.flash-bar-indet { width: 35%; border-radius: 6px;
  animation: flashindet 1.1s ease-in-out infinite; }
@keyframes flashindet {
  0% { margin-left: -35%; }
  100% { margin-left: 100%; }
}
.live-dot-on { background: var(--green); box-shadow: 0 0 0 5px rgba(31,157,85,.18);
  animation: livepulse 1.4s ease-in-out infinite; }
@keyframes livepulse {
  0%, 100% { box-shadow: 0 0 0 5px rgba(31,157,85,.18); }
  50% { box-shadow: 0 0 0 9px rgba(31,157,85,.04); }
}

/* --- MODE 2: Pre-provisioning --- */
.prov-block { border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; background: #fff; }
.prov-head { margin-bottom: 12px; }
.prov-title { font-weight: 700; font-size: 15px; }
.prov-intro { color: var(--ink-soft); font-size: 12.5px; margin-top: 3px; }
.prov-row { display: grid; grid-template-columns: 180px 1fr auto auto; gap: 10px;
  align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.prov-row:first-of-type { border-top: none; }
.prov-fam-name { font-weight: 600; font-size: 13px; }
.prov-chip { display: inline-block; margin-top: 4px; font-size: 11px;
  font-weight: 600; padding: 2px 8px; border-radius: 6px; }
.prov-none { background: #eef1f5; color: var(--ink-soft); }
.prov-pending { background: var(--amber-soft); color: var(--amber);
  display: inline-flex; align-items: center; gap: 5px; }
.prov-ready { background: var(--green-soft); color: var(--green); }

/* --- inline sync spinner (per-row "sending/removing" + flash progress) --- */
.sync-spinner { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid rgba(201,138,27,.35); border-top-color: var(--amber);
  display: inline-block; animation: syncspin .7s linear infinite; }
.sync-spinner-sm { width: 11px; height: 11px; border-width: 2px; }
@keyframes syncspin { to { transform: rotate(360deg); } }
.prov-select { padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px;
  font-family: inherit; font-size: 13px; background: #fff; width: 100%; }
.prov-send { padding: 7px 14px; }
.prov-clear { padding: 7px 10px; }
.prov-empty { color: var(--ink-soft); font-size: 12px; font-style: italic;
  grid-column: 2 / -1; }
/* Contextual "a board is already connected, flash it now?" prompt under a row. */
.prov-flashnow { grid-column: 1 / -1; display: flex; align-items: center;
  justify-content: space-between; gap: 12px; margin-top: 8px; padding: 9px 12px;
  background: var(--green-soft); border: 1px solid #a9e0bd; border-radius: 8px;
  font-size: 13px; color: var(--green); }
.prov-flashnow-btn { padding: 6px 12px; white-space: nowrap; }

/* While a flash is running, the prepare-next section is secondary — dim it so the
   eye goes to the progress panel, not a wall of green call-to-actions. */
.dimmed-while-flashing { opacity: .45; pointer-events: none; filter: saturate(.7); }
@media (max-width: 560px) {
  .prov-row { grid-template-columns: 1fr; }
  .prov-empty { grid-column: 1; }
}

table.records { width: 100%; border-collapse: collapse; font-size: 13px; }
table.records th, table.records td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.records th { color: var(--ink-soft); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.verdict { font-weight: 600; padding: 2px 8px; border-radius: 6px; font-size: 12px; }
.verdict-ok { background: var(--green-soft); color: var(--green); }
.verdict-recovered { background: var(--amber-soft); color: var(--amber); }
.verdict-hardware_suspected, .verdict-flag, .verdict-recoverable { background: var(--red-soft); color: var(--red); }

/* plain-language result pills + the "what happened" column */
.result-pill { font-weight: 600; padding: 2px 9px; border-radius: 6px; font-size: 12px;
  display: inline-block; white-space: nowrap; }
.result-ok { background: var(--green-soft); color: var(--green); }
.result-warn { background: var(--amber-soft); color: var(--amber); }
.result-bad { background: var(--red-soft); color: var(--red); }
.result-why { color: var(--ink-soft); font-size: 12.5px; }
.boot-toggle { color: var(--accent); cursor: pointer; font-size: 12px;
  text-decoration: underline; white-space: nowrap; }

/* history "Chip" cell: id + optional blue name tag + rename pencil */
.chip-cell { display: inline-flex; align-items: center; gap: 6px; }
.chip-id { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px;
  color: var(--ink-soft); }
.chip-tag { background: var(--accent-soft); color: var(--accent); font-weight: 600;
  font-size: 11px; padding: 2px 8px; border-radius: 999px; max-width: 140px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-edit { border: none; background: none; padding: 2px; cursor: pointer;
  color: #aab3c0; display: inline-flex; align-items: center; border-radius: 4px;
  transition: color .12s, background .12s; }
.chip-edit:hover { color: var(--accent); background: var(--accent-soft); }
.boot-row td { padding: 0 10px 8px; border-bottom: 1px solid var(--line); }
.boot-caption { font-size: 11px; color: var(--ink-soft); margin: 0 0 5px;
  display: inline-block; }
.boot-caption-warn { color: var(--amber); }
.boot-log { margin: 0; padding: 10px 12px; background: #1c2430; color: #e7ecf3;
  border-radius: 7px; font-size: 11.5px; line-height: 1.5; max-height: 220px;
  overflow: auto; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre-wrap; word-break: break-word; }

/* --- firmware --- */
.fw-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; }
.field input, .field select, .arm-form input, .arm-form select {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px;
  font-family: inherit; font-size: 13px; background: #fff;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fw-list { display: flex; flex-direction: column; gap: 6px; }
.fw-item { display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; font-size: 13px; }
.fw-item .fw-name { font-weight: 600; }
.fw-item .fw-sub { color: var(--ink-soft); font-size: 12px; }

/* --- buttons --- */
.btn { border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 7px 12px; border-radius: 7px; font-family: inherit; font-size: 13px;
  font-weight: 600; cursor: pointer; transition: background .12s, border-color .12s; }
.btn:hover { background: #f3f5f8; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4fd8; }
.row { display: flex; gap: 8px; }
.hidden { display: none !important; }
.muted { color: var(--ink-soft); }

/* --- collapsible help reminder --- */
.help { margin: 12px 0; border: 1px solid var(--line); border-radius: 8px;
  background: #fafbfc; overflow: hidden; }
.help summary { cursor: pointer; padding: 10px 12px; font-weight: 600;
  font-size: 13px; display: flex; align-items: center; gap: 8px;
  list-style: none; color: var(--ink); }
.help summary::-webkit-details-marker { display: none; }
.help summary:hover { background: #f3f5f8; }
.help[open] summary { border-bottom: 1px solid var(--line); }
.help-icon { width: 16px; height: 16px; color: var(--accent); fill: none;
  stroke: currentColor; stroke-width: 1.6; stroke-linecap: round;
  stroke-linejoin: round; flex-shrink: 0; }
.help-body { padding: 12px; font-size: 13px; color: var(--ink); }
.help-body p { margin: 0 0 8px; }
.help-body ul { margin: 0 0 10px; padding-left: 18px; }
.help-body li { margin-bottom: 5px; }
.help-body code { background: #eef1f5; padding: 1px 5px; border-radius: 4px;
  font-size: 12px; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.help-body pre { background: #1c2430; color: #e7ecf3; padding: 10px 12px;
  border-radius: 7px; font-size: 11.5px; line-height: 1.5; overflow-x: auto;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; margin: 0 0 10px; }
.help-body pre code { background: none; padding: 0; color: inherit; }

/* --- board types (boot profiles) --- */
.bt-block { margin-bottom: 16px; }
.bt-head { display: flex; align-items: center; justify-content: space-between; }
.bt-head h3 { font-size: 14px; margin: 0; }
.bt-intro { font-size: 12px; margin: 6px 0 10px; }
.bt-list { display: flex; flex-direction: column; gap: 6px; }
.bt-item { display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; }
.bt-item .bt-name { font-weight: 600; font-size: 13px; }
.bt-item .bt-sub { color: var(--ink-soft); font-size: 12px; }
.bt-item .bt-actions { display: flex; gap: 6px; }
.bt-item .btn { padding: 4px 9px; font-size: 12px; }
.bt-note { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px;
  padding: 10px; background: var(--accent-soft); border-radius: 7px;
  font-size: 12px; color: var(--ink); }
.bt-note .help-icon { color: var(--accent); margin-top: 1px; }
.adv-import { margin: 4px 0 14px; }
.adv-import > summary { cursor: pointer; font-size: 12px; color: var(--ink-soft);
  padding: 4px 0; list-style: none; }
.adv-import > summary::-webkit-details-marker { display: none; }
.adv-import[open] > summary { margin-bottom: 8px; }
.arm-form input[type="file"] { padding: 5px; font-size: 12px; }

/* --- dialog --- */
dialog { border: none; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(20, 30, 45, .35); }
.arm-form { display: flex; flex-direction: column; gap: 10px; }
.arm-form h3 { margin: 0; }
.arm-form label { font-size: 12px; color: var(--ink-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s; z-index: 50; }
.toast.show { opacity: 1; }
