:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --nav-bg: #0f172a;
  --nav-text: #e2e8f0;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
  --nav-h: 56px;
}

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

/* ── Navigation ── */
header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--nav-bg);
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,.3);
}
nav {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.site-id {
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  white-space: nowrap;
}
.site-name {
  font-size: 0.8rem;
  color: #94a3b8;
  white-space: nowrap;
  flex-shrink: 0;
}
nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 0.125rem;
  flex: 1;
}
nav ul a {
  display: block;
  padding: 0.375rem 0.75rem;
  color: var(--nav-text);
  text-decoration: none;
  border-radius: var(--radius);
  font-size: 0.8rem;
  transition: background .15s;
}
nav ul a:hover, nav ul a.active { background: rgba(255,255,255,.12); }
nav form button {
  background: transparent;
  border: 1px solid #475569;
  color: #94a3b8;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
}
nav form button:hover { background: rgba(255,255,255,.08); }

/* ── Layout ── */
main {
  max-width: 1280px;
  margin: 0 auto;
  padding: calc(var(--nav-h) + 1.5rem) 1rem 2rem;
}
h1 { font-size: 1.25rem; margin: 0 0 1.25rem; }
h2 { font-size: 1rem; margin: 0 0 1rem; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}
.card-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-body { padding: 1rem; }

/* ── Stats grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 0.7rem; color: var(--muted); margin-top: 0.25rem; text-transform: uppercase; letter-spacing: .04em; }
.stat-ok { color: #15803d; }
.stat-warn { color: var(--warning); }
.stat-err { color: var(--danger); }

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.form-group { margin-bottom: 0.875rem; }
.form-group:last-child { margin-bottom: 0; }
label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: var(--text);
}
.hint {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.2rem;
}
input[type=text], input[type=number], input[type=password],
input[type=url], input[type=datetime-local], select, textarea {
  width: 100%;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
input[type=checkbox] { width: auto; margin-right: 0.4rem; vertical-align: middle; }
.checkbox-label { display: flex; align-items: center; font-weight: 400; cursor: pointer; }
.checkbox-label input { flex-shrink: 0; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.45rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #cbd5e1; }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.75rem; }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.badge-uploaded  { background: #dcfce7; color: #15803d; }
.badge-pending   { background: #fef9c3; color: #854d0e; }
.badge-failed    { background: #fee2e2; color: #991b1b; }
.badge-video     { background: #ede9fe; color: #5b21b6; }
.badge-scheduled { background: #dbeafe; color: #1e40af; }
.badge-nwis      { background: #fce7f3; color: #9d174d; }
.badge-gpio_mode { background: #ffedd5; color: #9a3412; }
.badge-manual    { background: #f0fdf4; color: #166534; }
.badge-na        { background: #f1f5f9; color: #64748b; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
th {
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.col-actions { white-space: nowrap; text-align: right; }

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── Dashboard last image ── */
.last-image-wrap { text-align: center; }
.last-image-wrap img { max-width: 100%; max-height: 400px; border-radius: var(--radius); }

/* ── Mode / status pills ── */
.mode-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  background: #ffedd5;
  color: #c2410c;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  margin-right: 0.25rem;
}

/* ── Alert banner ── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.alert-warn    { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }

/* ── Toast ── */
.toast-container {
  position: fixed;
  top: calc(var(--nav-h) + 0.75rem);
  right: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
  color: #fff;
  font-size: 0.8rem;
  max-width: 360px;
  box-shadow: 0 4px 8px rgba(0,0,0,.25);
  animation: toast-in .2s ease;
}
.toast-success { background: #16a34a; }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--primary); }
.toast-warn    { background: #d97706; }
@keyframes toast-in {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Log viewer ── */
.log-output {
  font-family: monospace;
  font-size: 0.75rem;
  background: #0f172a;
  color: #e2e8f0;
  padding: 0.75rem;
  border-radius: var(--radius);
  height: 500px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.log-output .lvl-ERROR    { color: #f87171; }
.log-output .lvl-WARNING  { color: #fbbf24; }
.log-output .lvl-DEBUG    { color: #94a3b8; }

/* ── Section divider ── */
.section-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}

/* ── Two-col layout ── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
}
.upload-zone:hover { border-color: var(--primary); color: var(--primary); }

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Preview image ── */
#preview-container { margin-top: 1rem; }
#preview-img { max-width: 100%; border-radius: var(--radius); display: block; }
