:root {
  --bg-base:       #0e0e0e;
  --bg-panel:      #1a1a1a;
  --bg-raised:     #222222;
  --accent:        #097479;
  --accent-bright: #0eb8c0;
  --text-primary:  #eeeeee;
  --text-muted:    #777777;
  --border:        #2e2e2e;
  --danger:        #c0392b;
  --warn:          #e87c2a;
  --success:       #27ae60;
  --font-mono: "SF Mono", Consolas, "Fira Mono", "Courier New", monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Top nav ── */
#top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 52px;
}

#top-nav h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-right: auto;
}

#top-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

#top-nav a:hover { color: var(--text-primary); }
#top-nav a.active { color: var(--text-primary); border-bottom-color: var(--accent-bright); }

#auth-indicator {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

#auth-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
#auth-dot.ok   { background: var(--success); }
#auth-dot.fail { background: var(--danger); }

/* ── Page layout ── */
#page {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* ── Section ── */
.section {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.section-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  flex: 1;
}

.section-body { padding: 20px; }

.header-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 16px;
  position: relative;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent-bright);
  background: rgba(9,116,121,0.08);
}

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.upload-zone-text {
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
}

.upload-zone-text strong { color: var(--accent-bright); }

.format-note {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.5;
}

/* ── Audio upload status panel ── */
.upload-status-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}
.upload-status-panel:empty { display: none; }

.upload-status-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  line-height: 1.5;
}
.upload-status-row.uploading  { border-color: var(--border); color: var(--text-muted); }
.upload-status-row.converting { border-color: rgba(9,116,121,0.5); color: var(--accent-bright); }
.upload-status-row.success    { border-color: rgba(39,174,96,0.4); color: #2ecc71; }
.upload-status-row.error      { border-color: rgba(192,57,43,0.4); color: #e74c3c; }

.upload-status-icon {
  flex-shrink: 0;
  width: 14px;
  text-align: center;
  font-style: normal;
}
.upload-status-row.uploading  .upload-status-icon,
.upload-status-row.converting .upload-status-icon {
  display: inline-block;
  animation: status-spin 1s linear infinite;
}
@keyframes status-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.upload-progress {
  margin-top: 10px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  display: none;
}

.upload-progress-bar {
  height: 100%;
  background: var(--accent-bright);
  width: 0%;
  transition: width 0.1s;
}

/* ── File table ── */
.file-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.file-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

.file-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.file-table tr:last-child td { border-bottom: none; }

.file-table tr:hover td { background: var(--bg-raised); }

.file-name { font-family: var(--font-mono); font-size: 12px; }

.file-hash {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  cursor: help;
}

.file-size { color: var(--text-muted); white-space: nowrap; }

.file-date { color: var(--text-muted); white-space: nowrap; font-size: 12px; }

.empty-row td { color: var(--text-muted); font-style: italic; text-align: center; padding: 20px; }

/* ── Confirm inline ── */
.confirm-inline {
  display: none;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
}
.confirm-inline.visible { display: flex; }
.confirm-label { font-size: 12px; color: var(--text-muted); }

/* ── Form ── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field.full { grid-column: 1 / -1; }

.form-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-field input,
.form-field select {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

.form-field input:focus,
.form-field select:focus { border-color: var(--accent-bright); }

.form-field select option { background: var(--bg-raised); }

/* Audio checklist */
.audio-checklist {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 140px;
  overflow-y: auto;
  padding: 6px 0;
}

.audio-check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font-mono);
}

.audio-check-item:hover { background: rgba(255,255,255,0.04); }

.audio-check-item input { accent-color: var(--accent-bright); width: 14px; height: 14px; }

/* Manifest result */
.manifest-result {
  display: none;
  margin-top: 16px;
}

.manifest-result.visible { display: block; }

.manifest-json {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
  white-space: pre;
  color: var(--accent-bright);
  max-height: 320px;
  overflow-y: auto;
}

/* ── Push OTA table ── */
.push-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.push-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

.push-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.push-table tr:last-child td { border-bottom: none; }

/* ── Status badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-success { background: rgba(39,174,96,0.18);  color: #2ecc71; }
.badge-failed  { background: rgba(192,57,43,0.18);  color: #e74c3c; }
.badge-started { background: rgba(9,116,121,0.18);  color: var(--accent-bright); }
.badge-yes     { background: rgba(39,174,96,0.18);  color: #2ecc71; }
.badge-no      { background: rgba(120,120,120,0.15); color: var(--text-muted); }

/* ── Reports table ── */
.reports-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.reports-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.reports-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.reports-table td:first-child { color: var(--text-primary); }

.reports-table tr:last-child td { border-bottom: none; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.pagination-info { flex: 1; }

/* ── Selection toolbar (audio / files batch actions) ── */
.selection-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  margin-bottom: 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  flex-wrap: wrap;
}

.sel-all-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.sel-all-label input { accent-color: var(--accent-bright); cursor: pointer; }

.sel-count {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 72px;
}

.sel-actions { display: flex; gap: 8px; margin-left: auto; }

.col-check { width: 32px; text-align: center; }
.col-check input[type="checkbox"] { accent-color: var(--accent-bright); cursor: pointer; }

.auto-refresh-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.auto-refresh-row input { accent-color: var(--accent-bright); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-bright); }

.btn-secondary {
  background: var(--bg-raised);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--text-muted); }

.btn-danger {
  background: rgba(192,57,43,0.18);
  color: #e74c3c;
  border: 1px solid rgba(192,57,43,0.3);
}
.btn-danger:hover:not(:disabled) { background: rgba(192,57,43,0.3); }

.btn-warn {
  background: rgba(232,124,42,0.18);
  color: var(--warn);
  border: 1px solid rgba(232,124,42,0.3);
}
.btn-warn:hover:not(:disabled) { background: rgba(232,124,42,0.3); }

.btn-accent {
  background: rgba(9,116,121,0.18);
  color: var(--accent-bright);
  border: 1px solid rgba(9,116,121,0.35);
}
.btn-accent:hover:not(:disabled) { background: rgba(9,116,121,0.32); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Token table ── */
.token-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.token-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

.token-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  color: var(--text-muted);
  vertical-align: middle;
}

.token-table tr:last-child td { border-bottom: none; }

/* ── Auth dialog ── */
#auth-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#auth-dialog.hidden { display: none; }

.auth-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-box h2 { font-size: 16px; }
.auth-box p  { font-size: 13px; color: var(--text-muted); }

.auth-box input {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-mono);
  width: 100%;
  outline: none;
}

.auth-box input:focus { border-color: var(--accent-bright); }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
}

.toast {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  min-width: 220px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: toast-in 0.2s ease;
}

.toast-success { border-color: rgba(39,174,96,0.4);  color: #2ecc71; }
.toast-error   { border-color: rgba(192,57,43,0.4);  color: #e74c3c; }
.toast-info    { border-color: rgba(9,116,121,0.5);  color: var(--accent-bright); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Misc ── */
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.muted { color: var(--text-muted); }
.mono  { font-family: var(--font-mono); }

.note {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-raised);
  border-radius: 6px;
  padding: 8px 12px;
  margin-top: 12px;
}

/* ── Device online count ── */
.device-count {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 4px;
}

.device-count-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.device-count-dot.ok { background: var(--success); }

/* ── Radio groups ── */
.radio-group {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.radio-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.15s;
}

.radio-item input { accent-color: var(--accent-bright); cursor: pointer; }
.radio-item:has(input:checked) { color: var(--text-primary); }


/* ── Delete tag input ── */
.delete-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 32px;
  padding: 4px 0;
}

.delete-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(192,57,43,0.15);
  border: 1px solid rgba(192,57,43,0.35);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: #e74c3c;
}

.delete-tag button {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  opacity: 0.7;
}
.delete-tag button:hover { opacity: 1; }

.delete-tag-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.delete-tag-row input {
  flex: 1;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-mono);
  outline: none;
}
.delete-tag-row input:focus { border-color: var(--accent-bright); }

/* ── Load manifest modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 420px;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.load-section-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 10px 16px 4px;
}

.load-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

.load-item:last-child { border-bottom: none; }
.load-item:hover { background: var(--bg-raised); }

.load-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Push table (5 cols now) ── */
.push-table tr:hover td { background: var(--bg-raised); }

/* ── Live Activity ── */
.activity-count {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.activity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.activity-table th {
  text-align: left;
  padding: 7px 12px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.activity-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.activity-table tr:last-child td { border-bottom: none; }
.activity-table tr:hover td { background: var(--bg-raised); }

.activity-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 24px !important;
  font-style: italic;
}

.activity-ip   { font-family: monospace; font-size: 12px; white-space: nowrap; }
.activity-file { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-speed { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text-muted); font-size: 12px; }

.activity-cat {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.activity-cat--firmware { background: #1a2a3a; color: #5ba3d9; }
.activity-cat--audio    { background: #1a2e1a; color: #5dc45d; }
.activity-cat--config   { background: #2e2a14; color: #c4a85d; }
.activity-cat--general  { background: #2a1a2e; color: #a05dc4; }

.activity-progress-cell { min-width: 200px; }

.activity-bar-wrap {
  height: 6px;
  background: var(--bg-raised);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}

.activity-bar {
  height: 100%;
  background: var(--accent-bright);
  border-radius: 3px;
  transition: width 0.3s linear;
}

.activity-pct {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  margin-right: 6px;
}

.activity-size {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.activity-status { font-size: 12px; white-space: nowrap; }
.activity-status--active  { color: var(--accent-bright); }
.activity-status--done    { color: #5dc45d; }
.activity-status--aborted { color: var(--text-muted); }
.activity-status--error   { color: var(--danger); }

/* ── Audio rename inline edit ── */
.rename-input {
  width: 90px;
  padding: 2px 6px;
  font-size: 13px;
  font-family: monospace;
  background: var(--bg-raised);
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: var(--text-primary);
  outline: none;
}
.rename-input:focus { border-color: var(--accent-bright); }

.rename-hint {
  font-size: 11px;
  margin-left: 4px;
  font-family: monospace;
}
.rename-hint--ok   { color: var(--accent-bright); }
.rename-hint--warn { color: var(--text-muted); }
