@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;600;700&display=swap');

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

/* ── Exact Gradio theme values ────────────────────
   body_background_fill:              #1a1a1a
   block_background_fill:             #2d2d2d
   border_color_primary:              #444
   body_text_color:                   #e0e0e0
   button_primary_background_fill:    #2196f3
   button_primary_text_color:         white
   button_secondary_background_fill:  #2d2d2d
   button_secondary_text_color:       #e0e0e0
   block_radius:                      radius_sm = 4px
   button_medium_radius:              radius_md = 6px
   button_medium_padding:             6px 12px
   button_medium_text_weight:         600
   block_label_radius:                3px 0 3px 0
   block_label_padding:               4px 8px
   block_label_text_weight:           400
   block_label_text_color:            #e0e0e0
   font:                              IBM Plex Sans
───────────────────────────────────────────────── */

:root {
  --bg:       #1a1a1a;
  --block:    #2d2d2d;
  --surface:  rgb(82, 82, 91);
  --border:   #444;
  --text:     #e0e0e0;
  --muted:    #6b7280;
  --blue:     rgb(38, 99, 235);
  --blue-h:   rgb(29, 78, 216);
  --green:    #00aa00;
  --red:      #ff0000;
  --orange:   #ff9800;
  --r-sm:     4px;
  --r-md:     6px;
}

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Header ──────────────────────────────────────
   Matches the Gradio #1a1a1a body + top block row
   ─────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--block);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  gap: 12px;
}

.header-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Settings button ─────────────────────────────── */
.settings-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--muted);
  font-size: 15px;
  padding: 4px 8px;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.settings-btn:hover  { color: var(--text); border-color: var(--text); }
.settings-btn:active { opacity: 0.7; }

/* Connection status pill */
.conn-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.3s, border-color 0.3s;
}
.conn-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.3s;
}
.conn-pill.online  { color: #4caf50; border-color: #4caf50; }
.conn-pill.offline { color: var(--red); border-color: var(--red); }
.conn-dot.online   { background: #4caf50; }
.conn-dot.offline  { background: var(--red); }

/* ── Main layout ─────────────────────────────────
   Same spacing rhythm as Gradio Blocks
   ─────────────────────────────────────────────── */
main {
  padding: 12px 12px 48px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
}

/* ── Gradio block ─────────────────────────────────
   block_background_fill="#2d2d2d"
   border: 1px solid #444
   block_radius = radius_sm = 4px
   ─────────────────────────────────────────────── */
.block {
  background: var(--block);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}

/* ── Gradio block label (chip at top-left) ────────
   block_label_radius: 3px 0 3px 0
   block_label_padding: spacing_sm spacing_lg = 4px 8px
   block_label_text_weight: 400
   block_label_text_color: #e0e0e0
   block_label_background_fill: #2d2d2d
   block_label_border_color: #444, border-right + border-bottom
   ─────────────────────────────────────────────── */
.block-label {
  display: inline-block;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text);
  background: var(--surface);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: 3px 0 3px 0;
  line-height: 1.4;
}

/* ── Alert banner (matches main system inline HTML) ──
   monitoring: gray
   alerting:   #ff0000 + blink animation
   safe:       #00aa00
   snoozed:    #ff9800
   ─────────────────────────────────────────────── */
@keyframes blink-alert {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}

.alert-banner {
  margin: 8px 8px 0;
  padding: 10px 14px;
  text-align: center;
  font-weight: bold;
  font-size: 1.1em;
  color: #fff;
  border-radius: var(--r-sm);
  transition: background 0.3s;
}
.alert-banner.monitoring { background: gray; }
.alert-banner.alerting   { background: var(--red);    animation: blink-alert 1s infinite; }
.alert-banner.safe       { background: var(--green);  animation: none; }
.alert-banner.snoozed    { background: var(--orange); animation: none; }
.alert-banner.offline    { background: #555;          animation: none; }

.alert-msg {
  padding: 4px 8px 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
  word-break: break-word;
}
.snooze-info {
  padding: 2px 8px 0;
  font-size: 12px;
  color: var(--orange);
  min-height: 16px;
}

/* ── Buttons ─────────────────────────────────────
   button_medium_radius:   radius_md = 6px
   button_medium_padding:  6px 12px
   button_medium_text_weight: 600
   button_transition:      all 0.2s ease
   ─────────────────────────────────────────────── */
.btn-row {
  display: flex;
  gap: 8px;
  padding: 10px 8px 10px;
  flex-wrap: wrap;
}

button {
  cursor: pointer;
  border: none;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 12px;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.5;
}

/* Primary: button_primary_background_fill="#2196f3" */
.btn-primary {
  background: var(--blue);
  color: #fff;
  border: 1px solid var(--blue);
  flex: 1;
}
.btn-primary:hover  { background: var(--blue-h); border-color: var(--blue-h); }
.btn-primary:active { opacity: 0.85; }

/* Secondary: button_secondary_background_fill="#2d2d2d", text="#e0e0e0" */
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  flex: 1;
}
.btn-secondary:hover  { background: #626270; }
.btn-secondary:active { opacity: 0.85; }

/* ── Camera tabs ─────────────────────────────────
   Styled exactly like the mode-selection buttons:
   active = primary (#2196f3), inactive = secondary (#2d2d2d)
   ─────────────────────────────────────────────── */
.cam-tabs {
  display: flex;
  gap: 8px;
  padding: 8px 8px;
  border-top: 1px solid var(--border);
}

.cam-tab {
  flex: 1;
  padding: 6px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.cam-tab.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.cam-tab:active { opacity: 0.85; }

/* ── Camera panels ───────────────────────────────── */
.cam-panel { display: none; }
.cam-panel.active { display: block; }

.cam-stream-wrap {
  background: #000;
  width: 100%;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.cam-stream-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.cam-offline-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}
.cam-offline-msg .icon { font-size: 36px; }

.cam-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  border-top: 1px solid var(--border);
}
.cam-label { flex: 1; font-size: 12px; font-weight: 400; color: var(--muted); }
.cam-footer button { flex: 0; min-width: unset; padding: 6px 12px; white-space: nowrap; }

/* ── Alert log ───────────────────────────────────── */
.log-list {
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
}
.log-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 8px;
  border-bottom: 1px solid #333;
  font-size: 13px;
  font-weight: 400;
}
.log-list li:last-child { border-bottom: none; }

.log-time {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  padding-top: 2px;
  min-width: 40px;
}
.log-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}
.log-dot.alert   { background: var(--red); }
.log-dot.snoozed { background: var(--orange); }
.log-dot.safe    { background: var(--green); }

.log-empty {
  padding: 16px 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  text-align: center;
}

/* ── System Control trigger (in main page) ──────── */
.ctrl-trigger-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  gap: 12px;
}

.ctrl-mode-display {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.ctrl-mode-icon { font-size: 22px; flex-shrink: 0; }
.ctrl-mode-name { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.3; }
.ctrl-mode-sub  { font-size: 11px; color: var(--muted); margin-top: 1px; }

.ctrl-adjust-btn { flex: 0; white-space: nowrap; }

/* ── Control Panel Overlay ───────────────────────── */
.ctrl-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 150;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.ctrl-overlay.open { transform: translateX(0); }

.ctrl-overlay-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--block);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.ctrl-back-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.ctrl-back-btn:active { opacity: 0.75; }

.ctrl-overlay-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}

.ctrl-section {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
}

.ctrl-section-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
  margin-bottom: 8px;
}

/* ── Dark-theme select dropdown ──────────────────── */
.ctrl-select {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 9px 32px 9px 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23e0e0e0' d='M5 6L0 0h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
  line-height: 1.4;
}
.ctrl-select:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.ctrl-select option { background: var(--block); color: var(--text); }

.ctrl-apply-btn-full {
  display: block;
  width: 100%;
  margin-top: 10px;
  flex: unset;
}

/* ── Item / face chips ───────────────────────────── */
.item-chips, .face-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.item-chip, .face-chip {
  padding: 5px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.item-chip.selected, .face-chip.selected {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.item-chip:active, .face-chip:active { opacity: 0.75; }

/* ── Disappearance video clip list ───────────────── */
.vclip-list-wrap {
  max-height: 220px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

.vclip-empty {
  padding: 14px 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.vclip-list { list-style: none; }

.vclip-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-bottom: 1px solid #333;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}
.vclip-item:last-child { border-bottom: none; }
.vclip-item:hover  { background: #383838; }
.vclip-item.active { background: rgba(38, 99, 235, 0.15); color: var(--blue); }

.vclip-item-icon { font-size: 16px; flex-shrink: 0; }
.vclip-item-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.vclip-item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vclip-item-time { font-size: 11px; color: var(--muted); }

/* ── Disappearance video player ───────────────────── */
.vclip-player {
  border-top: 1px solid var(--border);
}

.vclip-player-label {
  padding: 6px 8px 4px;
  font-size: 12px;
  color: var(--muted);
}

#vclip-video {
  width: 100%;
  display: block;
  background: #000;
  max-height: 280px;
}

/* ── Settings modal ──────────────────────────────── */
.settings-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.settings-modal.open { display: flex; }

.settings-box {
  background: var(--block);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  width: 100%;
  max-width: 300px;
  overflow: hidden;
}

.settings-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px;
  font-size: 14px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.lang-toggle { display: flex; gap: 6px; }

.lang-btn {
  padding: 5px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.lang-btn.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.settings-footer {
  padding: 10px 14px;
  display: flex;
  justify-content: flex-end;
}
.settings-done-btn { flex: 0; padding: 6px 18px; white-space: nowrap; }

/* ── Button tap feedback ─────────────────────────── */
@keyframes btnTap {
  0%   { transform: scale(1); }
  35%  { transform: scale(0.92); }
  100% { transform: scale(1); }
}
.btn-pressed {
  animation: btnTap 0.35s ease-out !important;
  pointer-events: none !important;
}

/* ── Active snooze button highlight ─────────────── */
.btn-snooze-active {
  background: var(--blue) !important;
  color: #fff !important;
  border-color: var(--blue) !important;
}

/* ── Clear alert button dimmed while snooze is active ── */
.btn-clear-dimmed {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

/* ── Security feature checkboxes ─────────────────── */
.security-feature-checks {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}
.sf-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.15s;
}
.sf-label:hover { border-color: var(--blue); }
.sf-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
  flex-shrink: 0;
}
