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

:root {
  --sidebar-w: 200px;
  --sidebar-collapsed-w: 56px;
  --header-h: 52px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0a0f1e;
  color: #e2e8f0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100vh;
  transition: grid-template-columns 0.2s ease;
}

body.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-w) 1fr;
}

/* ── Sidebar ── */
.sidebar {
  grid-row: 1;
  grid-column: 1;
  background: #0f1629;
  border-right: 1px solid #1e3a5f;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  padding: 0 0 0 1rem;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid #1e3a5f;
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-header .logo-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar-header .logo-text {
  font-size: 0.95rem;
  font-weight: 700;
  color: #67e8f9;
  letter-spacing: 0.04em;
  opacity: 1;
  transition: opacity 0.15s;
  white-space: nowrap;
}

body.sidebar-collapsed .sidebar-header .logo-text { opacity: 0; width: 0; overflow: hidden; }

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
  text-decoration: none;
  color: #94a3b8;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.sidebar-nav a .nav-icon {
  font-size: 1rem;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.sidebar-nav a .nav-label {
  opacity: 1;
  transition: opacity 0.15s;
}

body.sidebar-collapsed .sidebar-nav a .nav-label { opacity: 0; }

.sidebar-nav a:hover {
  background: #102030;
  color: #e2e8f0;
}

.sidebar-nav a.active {
  background: #0c2a3d;
  color: #a5f3fc;
  border-left-color: #06b6d4;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  flex-shrink: 0;
  background: none;
  border: none;
  border-top: 1px solid #1e3a5f;
  color: #64748b;
  font-size: 1.1rem;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.sidebar-toggle:hover { background: #102030; color: #e2e8f0; }

/* ── Layout Main ── */
.layout-main {
  grid-row: 1;
  grid-column: 2;
  display: flex;
  flex-direction: column;
  overflow: auto;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: var(--header-h);
  background: #0f1629;
  border-bottom: 1px solid #1e3a5f;
  flex-shrink: 0;
}

.header h1 {
  font-size: 1rem;
  font-weight: 600;
  color: #e2e8f0;
  letter-spacing: 0.03em;
}

/* ── Buttons ── */
.btn {
  cursor: pointer;
  border: 1px solid #1e4976;
  background: #0d1e33;
  color: #cbd5e1;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  font-size: 0.85rem;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) { background: #0f2540; border-color: #06b6d4; }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary { background: #06b6d4; border-color: #06b6d4; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #0891b2; }

.btn-danger { background: #7f1d1d; border-color: #991b1b; color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: #991b1b; }
.btn-ai-on  { background: #14532d; border-color: #16a34a; color: #86efac; }
.btn-ai-on:hover:not(:disabled)  { background: #166534; }
.btn-ai-off { background: #1e293b; border-color: #334155; color: #94a3b8; }
.btn-ai-off:hover:not(:disabled) { background: #334155; }
.btn-line { background: #064e3b; border-color: #10b981; color: #a7f3d0; }
.btn-line:hover:not(:disabled) { background: #065f46; }

.ai-status-label {
  display: inline-block;
  font-size: 0.68rem;
  padding: 0.15rem 0.4rem;
  border-radius: 0.25rem;
  vertical-align: middle;
  animation: ai-pulse 1.4s ease-in-out infinite;
}
.ai-status--connecting,
.ai-status--running     { background: #1e293b; color: #94a3b8; }
.ai-status--reconnecting,
.ai-status--error       { background: #451a03; color: #fbbf24; }
@keyframes ai-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

.btn-active { background: #164e63; border-color: #06b6d4; color: #a5f3fc; }

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; }

/* ── Pagination ── */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 0.6rem 0.25rem;
  border-top: 1px solid var(--border, #2e3f52);
}
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.pagination-info {
  font-size: 0.85rem;
  color: var(--text-muted, #8a9bb0);
  min-width: 80px;
  text-align: center;
}
.pagination-size {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.pagination-size-label {
  font-size: 0.8rem;
  color: var(--text-muted, #8a9bb0);
}

/* ── Badge ── */
.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.badge-idle    { background: #1e293b; color: #64748b; border: 1px solid #334155; }
.badge-watch   { background: #083344; color: #67e8f9; border: 1px solid #0e4d64; }
.badge-record  { background: #450a0a; color: #fca5a5; border: 1px solid #7f1d1d; }

/* ── Grid ── */
.grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 3), 1fr);
  gap: 1.25rem;
  padding: 1.5rem;
}

/* RWD：視窗寬度不足時下降欄數，最少 1 欄 */
@media (max-width: 900px) {
  .grid {
    grid-template-columns: repeat(min(var(--grid-cols, 3), 2), 1fr);
  }
}
@media (max-width: 560px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

/* ── Card ── */
.card {
  background: #0f1629;
  border: 1px solid #1e3a5f;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #1e3a5f;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

/* ── Player ── */
.player-wrap {
  background: #020617;
  aspect-ratio: 16 / 9;
  width: 100%;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex: 0 0 auto;
}

.video-shell {
  position: relative;
  background: #020617;
}

.player {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: block;
  object-fit: contain;
  background: #020617;
}

.live-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid rgba(254, 202, 202, 0.22);
  border-radius: 999px;
  background: rgba(185, 28, 28, 0.88);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  pointer-events: none;
}

.live-badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.14);
}

.no-stream {
  color: #475569;
  font-size: 0.85rem;
}

/* ── AI Observation Summary ── */
.ai-observation-panel {
  margin: 14px 18px 12px;
  padding: 14px 16px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.88));
  border: 1px solid rgba(148, 163, 184, 0.16);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  color: #e2e8f0;
  font-size: 13px;
}

.ai-observation-title {
  color: #e2e8f0;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.01em;
}

.ai-observation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.ai-observation-refresh {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
  color: #64748b;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.ai-poll-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #64748b;
}

.ai-observation-refresh.is-active {
  color: #78b990;
}

.ai-observation-refresh.is-active .ai-poll-dot {
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.1);
}

.ai-observation-refresh.is-error {
  color: #d9956a;
}

.ai-observation-refresh.is-stale {
  color: #94a3b8;
}

.ai-observation-refresh.is-stale .ai-poll-dot {
  background: #94a3b8;
}

.ai-observation-refresh.is-error .ai-poll-dot {
  background: #f97316;
}

.ai-last-update {
  color: #718096;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.ai-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.ai-metric {
  min-width: 0;
  padding: 9px 11px;
  border-radius: 9px;
  background: rgba(30, 41, 59, 0.58);
  border: 1px solid rgba(148, 163, 184, 0.1);
}

.ai-metric-label {
  color: #7c8ca1;
  font-size: 11px;
}

.ai-metric-value {
  margin-top: 3px;
  overflow: hidden;
  color: #dbe5f1;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-confidence-value {
  color: #a5b4c7;
}

.ai-count-running {
  color: #86cfa0;
}

.ai-count-stopped {
  color: #e5a477;
}

.ai-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.ai-status-badge.running {
  color: #86cfa0;
  background: rgba(22, 163, 74, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.ai-status-badge.stopped {
  color: #e5a477;
  background: rgba(234, 88, 12, 0.11);
  border: 1px solid rgba(249, 115, 22, 0.2);
}

.ai-status-badge.unknown {
  color: #a8b3c3;
  background: rgba(100, 116, 139, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.16);
}

.waterwheel-list-header {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
  color: #8795a8;
  font-size: 11px;
  font-weight: 700;
}

.waterwheel-list-header span:last-child {
  color: #566579;
  font-weight: 500;
}

.waterwheel-list {
  margin-top: 5px;
  max-height: 210px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.38) transparent;
}

.waterwheel-list::-webkit-scrollbar {
  width: 5px;
}

.waterwheel-list::-webkit-scrollbar-track {
  background: transparent;
}

.waterwheel-list::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.38);
  border-radius: 999px;
}

.waterwheel-item {
  display: grid;
  grid-template-columns: 34px minmax(60px, 1fr) auto 48px;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 6px 7px;
  border-top: 1px solid rgba(148, 163, 184, 0.08);
  color: #aebaca;
  font-size: 12px;
}

.waterwheel-item:first-child {
  border-top: 0;
}

.waterwheel-index {
  color: #64748b;
  font-weight: 700;
}

.waterwheel-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.waterwheel-confidence {
  color: #8290a3;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.ai-observation-empty {
  padding: 7px;
  color: #566579;
  font-size: 11px;
}

.ai-report-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
  color: #8795a8;
  font-size: 11px;
  font-weight: 700;
}

.ai-report-count {
  margin-left: 7px;
  color: #566579;
  font-variant-numeric: tabular-nums;
}

.ai-report-clear {
  padding: 2px 6px;
  border: 0;
  background: transparent;
  color: #64748b;
  font: inherit;
  cursor: pointer;
}

.ai-report-clear:hover {
  color: #cbd5e1;
}

.ai-report-stream {
  max-height: 220px;
  margin-top: 5px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.38) transparent;
}

.ai-report-stream::-webkit-scrollbar {
  width: 5px;
}

.ai-report-stream::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.38);
}

.ai-report-row {
  display: grid;
  grid-template-columns: 66px 82px minmax(110px, 1fr) 46px;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 5px 7px;
  border-top: 1px solid rgba(148, 163, 184, 0.07);
  color: #9cabbc;
  font-size: 11px;
}

.ai-report-row:first-child {
  border-top: 0;
  background: rgba(30, 41, 59, 0.38);
  color: #d1dae6;
}

.ai-report-time,
.ai-report-confidence {
  font-variant-numeric: tabular-nums;
}

.ai-report-state {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-report-confidence {
  color: #8290a3;
  text-align: right;
}

.ai-report-empty {
  padding: 8px 7px;
  color: #526176;
  font-size: 11px;
}

/* ── Card Actions ── */
.card-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.8rem 1.1rem 0.9rem;
  border-top: 1px solid #1e3a5f;
  flex-wrap: wrap;
}

@media (max-width: 560px) {
  .ai-observation-panel {
    margin: 10px 12px;
    padding: 12px;
  }

  .ai-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .waterwheel-item {
    grid-template-columns: 30px minmax(50px, 1fr) auto 42px;
    gap: 6px;
  }
}

/* ── Empty State ── */
.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: #475569;
  font-size: 0.9rem;
  padding: 3rem;
  text-align: center;
}

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

.modal {
  background: #0f1629;
  border: 1px solid #1e4976;
  border-radius: 12px;
  padding: 1.75rem;
  width: 100%;
  max-width: 440px;
}

.modal h2 {
  font-size: 1.05rem;
  margin-bottom: 1.25rem;
  color: #67e8f9;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.form-group label {
  font-size: 0.8rem;
  color: #94a3b8;
}

.form-group input,
.form-group select,
.form-group textarea {
  background: #0a0f1e;
  border: 1px solid #1e4976;
  color: #e2e8f0;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.15s;
}

.form-group textarea { resize: vertical; }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: #06b6d4; }

.form-group input[type="datetime-local"] {
  cursor: pointer;
  height: 2.375rem;
  line-height: 1.375rem;
}

.form-group input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
  cursor: pointer;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
}

.form-group .datetime-wrap {
  position: relative;
}

.form-group .datetime-wrap input {
  padding-right: 2rem;
}

.form-group .datetime-wrap::after {
  content: '';
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  width: 1rem;
  height: 1rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.form-hint {
  color: #64748b;
  font-size: 0.75rem;
}

.form-error {
  color: #fca5a5;
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

/* ── Page toolbar ── */
.page-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 0.75rem 1.5rem 0;
}

/* ── Page (create/edit) ── */
.page-container {
  max-width: 560px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.page-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #67e8f9;
}

.page-card {
  background: #0f1629;
  border: 1px solid #1e3a5f;
  border-radius: 12px;
  padding: 1.75rem;
}

/* ── Table ── */
.table-wrap {
  padding: 1.5rem;
  overflow-x: auto;
}

/* ── AI Server Manager ── */
.ai-server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 16px;
  padding: 1.5rem;
}

.ai-server-card {
  padding: 18px;
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.84));
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.ai-server-card.is-selected {
  border-color: rgba(34, 211, 238, 0.42);
  box-shadow: 0 12px 30px rgba(8, 145, 178, 0.12);
}

.ai-server-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.ai-server-card h3 {
  margin: 4px 0 0;
  color: #e2e8f0;
  font-size: 16px;
}

.ai-server-selected-label {
  color: #67e8f9;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.ai-server-online-badge {
  padding: 4px 9px;
  border-radius: 999px;
  color: #cbd5e1;
  background: rgba(100, 116, 139, 0.14);
  border: 1px solid rgba(148, 163, 184, 0.18);
  font-size: 11px;
  font-weight: 700;
}

.ai-server-online-badge.is-online {
  color: #86efac;
  background: rgba(22, 163, 74, 0.13);
  border-color: rgba(34, 197, 94, 0.25);
}

.ai-server-online-badge.is-offline {
  color: #fda4af;
  background: rgba(190, 18, 60, 0.12);
  border-color: rgba(244, 63, 94, 0.22);
}

.ai-server-description {
  margin: 10px 0 0;
  color: #94a3b8;
  font-size: 12px;
}

.ai-server-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin: 15px 0;
}

.ai-server-details div {
  min-width: 0;
  padding: 9px 10px;
  border-radius: 9px;
  background: rgba(30, 41, 59, 0.48);
  border: 1px solid rgba(148, 163, 184, 0.08);
}

.ai-server-details dt {
  color: #64748b;
  font-size: 10px;
}

.ai-server-details dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  color: #cbd5e1;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.ai-server-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-top: 13px;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
}

@media (max-width: 560px) {
  .ai-server-grid {
    grid-template-columns: 1fr;
  }

  .ai-server-details {
    grid-template-columns: 1fr;
  }
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  color: #64748b;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #1e3a5f;
}

tbody tr {
  border-bottom: 1px solid #0d1e33;
  transition: background 0.1s;
}

tbody tr:hover { background: #0d1e33; }

tbody td {
  padding: 0.65rem 0.75rem;
  color: #cbd5e1;
  vertical-align: middle;
}

/* ── Detection Event Manager ── */
.events-page {
  padding: 1.25rem 1.5rem 2rem;
}

.events-page-subtitle {
  margin: 3px 0 0;
  color: #64748b;
  font-size: 0.78rem;
  font-weight: 400;
}

.events-summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.events-summary-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 4px 12px;
  padding: 13px 15px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.82);
}

.events-summary-card span {
  grid-column: 1 / -1;
  color: #94a3b8;
  font-size: 0.72rem;
}

.events-summary-card strong {
  color: #e2e8f0;
  font-size: 1.45rem;
  line-height: 1;
}

.events-summary-card small {
  color: #64748b;
  font-size: 0.68rem;
}

.events-summary-card.is-live strong { color: #86efac; }
.events-summary-card.is-alert strong { color: #fdba74; }
.events-summary-card.is-muted strong { color: #cbd5e1; }
.events-summary-card .events-summary-text {
  font-size: 0.98rem;
  line-height: 1.18;
  text-align: right;
}

.events-filter-card,
.events-table-card {
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.86));
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.16);
}

.events-filter-card {
  margin-bottom: 14px;
  padding: 14px;
}

.events-table-card {
  margin-bottom: 14px;
  overflow: hidden;
}

.events-filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-bottom: 13px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

.events-filter-tab {
  padding: 6px 11px;
  border: 1px solid rgba(148, 163, 184, 0.17);
  border-radius: 999px;
  color: #94a3b8;
  background: rgba(30, 41, 59, 0.42);
  font-size: 0.76rem;
  cursor: pointer;
  transition: 0.15s ease;
}

.events-filter-tab:hover {
  color: #e2e8f0;
  border-color: rgba(34, 211, 238, 0.28);
}

.events-filter-tab.active {
  color: #a5f3fc;
  border-color: rgba(34, 211, 238, 0.38);
  background: rgba(8, 145, 178, 0.14);
}

.events-filter-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  padding-top: 13px;
}

.events-filter-form .form-group { margin: 0; }

.events-filter-actions {
  display: flex;
  gap: 7px;
  padding-bottom: 1px;
}

.events-table-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 17px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.events-table-heading h2 {
  margin: 0;
  color: #e2e8f0;
  font-size: 0.95rem;
}

.events-table-heading p,
.events-table-heading > span {
  margin: 3px 0 0;
  color: #64748b;
  font-size: 0.72rem;
}

.events-table-wrap { padding: 0; }
.events-table { min-width: 1160px; }
.target-status-table { min-width: 1180px; }
.open-events-table { min-width: 980px; }
.history-events-table { min-width: 1320px; }
.events-table th:last-child,
.events-table td:last-child { text-align: right; }

.events-id {
  color: #64748b;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.events-monitor-name {
  color: #e2e8f0;
  font-size: 0.82rem;
  white-space: nowrap;
}

.event-class-badge,
.event-state-badge,
.target-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.event-class-badge.running {
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.24);
  background: rgba(22, 163, 74, 0.12);
}

.event-class-badge.stopped {
  color: #fdba74;
  border-color: rgba(249, 115, 22, 0.28);
  background: rgba(234, 88, 12, 0.13);
}

.event-class-badge.unknown {
  color: #cbd5e1;
  border-color: rgba(148, 163, 184, 0.2);
  background: rgba(100, 116, 139, 0.12);
}

.events-raw-class {
  display: block;
  margin-top: 3px;
  color: #64748b;
  font-size: 0.65rem;
}

.event-state-badge.open {
  color: #67e8f9;
  border-color: rgba(34, 211, 238, 0.26);
  background: rgba(8, 145, 178, 0.12);
}

.event-state-badge.closed {
  color: #94a3b8;
  border-color: rgba(148, 163, 184, 0.17);
  background: rgba(71, 85, 105, 0.12);
}

.event-state-badge.none {
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.22);
  background: rgba(22, 163, 74, 0.1);
}

.target-status-badge.running {
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.24);
  background: rgba(22, 163, 74, 0.12);
}

.target-status-badge.stopped {
  color: #fda4af;
  border-color: rgba(244, 63, 94, 0.28);
  background: rgba(159, 18, 57, 0.14);
}

.target-status-badge.unknown {
  color: #cbd5e1;
  border-color: rgba(148, 163, 184, 0.2);
  background: rgba(100, 116, 139, 0.12);
}

.events-muted {
  color: #64748b;
  font-size: 0.72rem;
}

.event-thumbnail-button {
  width: 68px;
  height: 43px;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 7px;
  color: #64748b;
  background: #080e1c;
  font-size: 0.64rem;
  cursor: pointer;
}

.event-thumbnail-button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.events-row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
  white-space: nowrap;
}

.btn-warning {
  color: #fdba74;
  border-color: rgba(249, 115, 22, 0.32);
  background: rgba(154, 52, 18, 0.24);
}

.btn-warning:hover:not(:disabled) {
  background: rgba(194, 65, 12, 0.34);
}

.events-loading,
.events-empty,
.events-message {
  padding: 2.5rem 1rem;
  color: #64748b;
  text-align: center;
}

.events-empty {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.events-empty strong { color: #94a3b8; }
.events-empty.compact { padding: 1.25rem; }

.events-message.is-error {
  margin-bottom: 14px;
  padding: 10px 13px;
  border: 1px solid rgba(244, 63, 94, 0.22);
  border-radius: 9px;
  color: #fda4af;
  background: rgba(159, 18, 57, 0.1);
  text-align: left;
}

.events-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
  color: #64748b;
  font-size: 0.74rem;
}

.event-detail-overlay {
  padding: 20px;
  overflow-y: auto;
}

.event-detail-modal {
  width: min(1040px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  border: 1px solid rgba(34, 211, 238, 0.22);
  border-radius: 15px;
  background: #0b1220;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
}

.event-detail-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(11, 18, 32, 0.96);
  backdrop-filter: blur(10px);
}

.event-detail-kicker {
  color: #22d3ee;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.event-detail-header h2 {
  margin: 3px 0 0;
  color: #e2e8f0;
  font-size: 1.08rem;
}

.event-modal-close {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 9px;
  color: #94a3b8;
  background: rgba(30, 41, 59, 0.55);
  font-size: 1.35rem;
  cursor: pointer;
}

.event-detail-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 18px 14px;
}

.event-detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 16px 18px;
}

.event-detail-grid > div {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.11);
  border-radius: 9px;
  background: rgba(30, 41, 59, 0.42);
}

.event-detail-grid span {
  display: block;
  margin-bottom: 5px;
  color: #64748b;
  font-size: 0.68rem;
}

.event-detail-grid strong {
  color: #cbd5e1;
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.event-detail-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 18px;
  padding: 13px 0 9px;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.event-detail-section-heading h3 {
  margin: 0;
  color: #e2e8f0;
  font-size: 0.88rem;
}

.event-detail-section-heading p {
  margin: 3px 0 0;
  color: #64748b;
  font-size: 0.68rem;
}

.event-json-block {
  max-height: 240px;
  margin: 0 18px 16px;
  padding: 12px;
  overflow: auto;
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 8px;
  color: #cbd5e1;
  background: rgba(2, 6, 23, 0.62);
  font-size: 0.72rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.event-detail-table-wrap {
  margin: 0 18px 16px;
  padding: 0;
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 8px;
}

.detail-window-table,
.detail-log-table {
  min-width: 720px;
}

.event-snapshot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
  padding: 0 18px 18px;
}

.event-snapshot-card {
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.13);
  border-radius: 11px;
  background: rgba(15, 23, 42, 0.78);
}

.event-snapshot-image {
  height: 155px;
  background: #020617;
}

.event-snapshot-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.event-snapshot-missing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 5px;
  color: #64748b;
}

.event-snapshot-missing small { color: #475569; }

.event-snapshot-content { padding: 10px 11px; }

.event-snapshot-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  color: #64748b;
  font-size: 0.67rem;
}

.event-snapshot-meta > span {
  color: #67e8f9;
  font-weight: 700;
}

.event-box-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.event-box-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 6px;
  color: #94a3b8;
  background: rgba(30, 41, 59, 0.58);
  font-size: 0.72rem;
}

.event-box-row strong { color: #cbd5e1; }
.event-box-empty { color: #64748b; font-size: 0.7rem; }

@media (max-width: 1050px) {
  .events-summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .events-filter-form { grid-template-columns: repeat(3, minmax(140px, 1fr)); }
  .event-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .events-page { padding: 12px 10px 22px; }
  .events-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .events-filter-form { grid-template-columns: 1fr; }
  .events-filter-actions { justify-content: flex-end; }
  .event-detail-overlay { padding: 8px; }
  .event-detail-modal { max-height: calc(100vh - 16px); }
  .event-detail-grid { grid-template-columns: 1fr; }
  .event-snapshot-grid { grid-template-columns: 1fr; }
}

.thumbnail-sm {
  width: 56px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  background: #0a0f1e;
  display: block;
}

.thumbnail-placeholder {
  width: 56px;
  height: 36px;
  border-radius: 4px;
  background: #0d1e33;
  border: 1px solid #1e3a5f;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: #475569;
}

.text-muted { color: #475569; }

/* ── Status Buttons (edit page) ── */
.status-group {
  display: flex;
  gap: 0.5rem;
}

/* ── History page ── */
.history-form {
  padding: 1.25rem 1.75rem 1.5rem;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.form-row .form-group {
  flex: 1 1 200px;
  margin-bottom: 0;
}

.form-group-btn {
  flex: 0 0 auto !important;
}

.page-card + .page-card {
  margin-top: 1.5rem;
}

/* ── Coverage Bar ── */
.coverage-wrap {
  padding: 0 1.5rem 1.25rem;
}

.coverage-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: #64748b;
  margin-bottom: 0.35rem;
}

.coverage-bar {
  position: relative;
  height: 20px;
  background: #0a0f1e;
  border: 1px solid #1e3a5f;
  border-radius: 4px;
  overflow: hidden;
}

.coverage-fill {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(6, 182, 212, 0.85);
  border-radius: 2px;
  cursor: default;
  transition: opacity 0.15s;
}

.coverage-fill:hover {
  opacity: 0.75;
}

.coverage-legend {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.4rem;
  font-size: 0.72rem;
  color: #64748b;
}

.legend-filled {
  display: inline-block;
  width: 16px;
  height: 10px;
  background: rgba(6, 182, 212, 0.85);
  border-radius: 2px;
}

.legend-empty {
  display: inline-block;
  width: 16px;
  height: 10px;
  background: #0a0f1e;
  border: 1px solid #1e3a5f;
  border-radius: 2px;
}

/* ════════════════════════════════════════
   RWD 全站斷點
   ════════════════════════════════════════ */

/* ── 768px：側邊欄預設折疊，主內容佔滿寬度 ── */
@media (max-width: 768px) {
  body {
    grid-template-columns: var(--sidebar-collapsed-w) 1fr;
  }
}

/* ── 640px：表格間距縮小 ── */
@media (max-width: 640px) {
  thead th,
  tbody td {
    padding: 0.4rem 0.5rem;
    font-size: 0.78rem;
  }
  .completeness-table th,
  .completeness-table td {
    padding: 0.3rem 0.4rem;
    font-size: 0.75rem;
  }
}

/* ── 560px：單欄化 ── */
@media (max-width: 560px) {
  /* timesync status grid：2 欄 → 1 欄 */
  .status-grid {
    grid-template-columns: 1fr !important;
  }

  /* page-container 邊距縮小 */
  .page-container {
    padding: 0 0.75rem;
    margin: 1rem auto;
  }

  /* page-card 內距縮小 */
  .page-card {
    padding: 1.25rem 1rem;
  }
}

/* ── 480px：form-row 單欄化，防止表單項目過擠 ── */
@media (max-width: 480px) {
  .form-row .form-group {
    flex: 1 1 100%;
  }
  .form-row .form-group-btn {
    width: 100%;
  }
  .form-row .form-group-btn .btn {
    width: 100%;
  }
}

/* ── Live Stream Page ── */
.layout-live {
  overflow-y: auto;
  overflow-x: hidden;
  height: 100vh;
}

.layout-live > #app {
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.layout-live .grid {
  flex: 0 0 auto;
  grid-auto-rows: auto;
  padding: 0.75rem;
  gap: 0.75rem;
}

.layout-live .card {
  min-height: 0;
}

.layout-live .player-wrap {
  aspect-ratio: 16 / 9;
  flex: 0 0 auto;
  min-height: 180px;
}

.layout-live .pagination-bar {
  flex-shrink: 0;
  margin-top: 0;
  padding: 0.4rem 0.75rem;
}
