:root {
  color-scheme: light dark;
  --bg: #f8fafc;
  --bg-overlay: rgba(248, 250, 252, 0.88);
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --ok: #16a34a;
  --warn: #d97706;
  --error: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --bg-overlay: rgba(15, 23, 42, 0.88);
    --card: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--bg);
  background-image: linear-gradient(var(--bg-overlay), var(--bg-overlay)), url("/static/images/background.avif");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.topbar .brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
}

.topbar nav a {
  margin-left: 1.5rem;
  color: var(--muted);
  text-decoration: none;
}

.topbar nav a:hover { color: var(--text); }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}

main.wide {
  max-width: 1320px;
  padding-top: 1rem;
}

.site-title {
  margin: 0 0 0.6rem;
}

a { color: #2563eb; }

.site-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.site-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  text-decoration: none;
  color: var(--text);
}

.site-card h2 { margin: 0 0 0.25rem; font-size: 1.1rem; }
.site-card .threshold { color: var(--muted); font-size: 0.85rem; margin: 0 0 0.5rem; }

.status { margin: 0.25rem 0; font-size: 0.9rem; }
.status-ok { color: var(--ok); }
.status-error { color: var(--error); }
.status-none { color: var(--muted); }
.window-count { color: var(--muted); font-size: 0.8rem; }

.confidence-outlook { opacity: 0.75; }
.confidence-mixed { opacity: 0.9; }

.windows-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.windows-table th, .windows-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.windows-table thead th { color: var(--muted); font-weight: 600; }

.night-badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  background: linear-gradient(120deg, rgba(0, 0, 0, 0.38), rgba(148, 163, 184, 0.16));
  color: #f8fafc;
}

.hint { color: var(--muted); }
.empty { color: var(--muted); }

.site-layout {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  margin-top: 0.5rem;
}

.site-sidebar {
  width: 300px;
  flex-shrink: 0;
  position: sticky;
  top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.site-main { flex: 1; min-width: 0; }

@media (max-width: 800px) {
  .site-layout { flex-direction: column; }
  .site-sidebar { width: 100%; position: static; }
}

.mission-status {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem;
}

.mission-status-body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
  flex: 1;
}

.mission-status-label { font-weight: 700; font-size: 0.95rem; }
.mission-status select { width: 100%; }

.semaphore-light {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 0.15rem;
}

.semaphore-light.go { background: #16a34a; box-shadow: 0 0 10px rgba(22, 163, 74, 0.6); }
.semaphore-light.nogo { background: #dc2626; box-shadow: 0 0 10px rgba(220, 38, 38, 0.6); }
.semaphore-light.unknown { background: #cbd5e1; }

.semaphore-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-eye {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--muted);
  padding: 0.2rem;
  border-radius: 4px;
}

.legend-eye:hover { color: var(--text); background: var(--bg); }
.legend-item-v.legend-hidden .legend-eye { color: var(--muted); opacity: 0.8; }

.semaphore-dot.go { background: #16a34a; box-shadow: 0 0 6px rgba(22, 163, 74, 0.7); }
.semaphore-dot.nogo { background: #dc2626; box-shadow: 0 0 6px rgba(220, 38, 38, 0.7); }
.semaphore-dot.unknown { background: #cbd5e1; }

.chart-legend-vertical {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.legend-item-v {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
  transition: opacity 0.15s, border-color 0.15s;
}

.legend-item-v:hover { border-color: #94a3b8; }
.legend-item-v.legend-hidden { opacity: 0.4; }

.legend-item-v-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.legend-item-v .legend-label { font-size: 0.78rem; }
.legend-item-v .legend-value { font-size: 0.95rem; text-align: left; min-width: 0; }

.sidebar-logo {
  display: block;
  width: 100%;
  opacity: 0.85;
  transition: opacity 0.15s;
}

.sidebar-logo:hover { opacity: 1; }

.sidebar-logo img {
  display: block;
  width: 100%;
  height: auto;
}

.main-panel {
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 1rem;
}

.chart-wrap {
  position: relative;
  height: 480px;
  margin-bottom: 1rem;
}

.table-scroll {
  overflow-x: auto;
}

.table-scroll .windows-table { margin-top: 0.25rem; }

.chart-time-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.3rem;
}

.chart-time-label {
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  opacity: 0.8;
  pointer-events: none;
}

.legend-swatch {
  flex-shrink: 0;
  width: 18px;
  height: 4px;
  border-radius: 2px;
  background: var(--swatch-color);
}

.legend-label {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.legend-value {
  font-size: 1.05rem;
  font-weight: 700;
  min-width: 4.5rem;
  text-align: right;
  white-space: nowrap;
}

.legend-value-sub {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--muted);
  margin-left: 0.3rem;
}

dialog {
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 1.25rem;
}

dialog::backdrop { background: rgba(15, 23, 42, 0.4); }

input[type="text"], input[type="number"] {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 220px;
}

button {
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}

button[type="submit"] {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
}

.mission-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1rem 0;
}

.mission-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
}

.mission-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mission-card-actions { display: flex; gap: 0.5rem; }

.mission-card-summary {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.mission-vars {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}

.mission-vars th, .mission-vars td {
  text-align: left;
  padding: 0.4rem 0.6rem;
}

.mission-vars input[type="number"] { width: 90px; }

#mission-dialog { min-width: 26rem; }
