/* ─────────────────────────────────────────────────────────────
   CoPilot — clean dark dashboard
   One accent colour, soft cards, system typography, no decoration.
   ───────────────────────────────────────────────────────────── */

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

:root {
  color-scheme: dark;

  --bg: #08090b;
  --surface: rgba(21, 23, 28, 0.86);
  --surface-flat: #15171c;
  --border: rgba(255, 255, 255, 0.09);
  --divider: rgba(255, 255, 255, 0.07);
  --text: #f3f5f8;
  --muted: #9aa1ac;
  --faint: #6a727e;

  --accent: #64a8ff;
  --cyan: #64a8ff;   /* used by setStatus() */
  --green: #3ddc97;
  --yellow: #f5c451;
  --red: #ff6b6b;
  --orange: #ff9f5a;
  --blue: #4b82ff;

  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; }

/* ── CAMERA LAYER ─────────────────────────────────────────── */
#camera-wrap {
  position: fixed;
  inset: 0;
  background: #000;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: brightness(0.92);
}

#overlay-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ── HUD SHELL ────────────────────────────────────────────── */
#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.flex-grow { flex: 1; }

/* ── TOP BAR ──────────────────────────────────────────────── */
#top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(to bottom, rgba(8, 9, 11, 0.7), transparent);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--text);
}

.logo::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.top-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

#time-display {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex: 0 0 auto;
}

#emergency-chip {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(255, 107, 107, 0.14);
  border: 1px solid rgba(255, 107, 107, 0.32);
  color: var(--red);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

#emergency-chip.show { display: inline-flex; }

#emergency-chip::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--red);
}

/* ── ALERT BANNER ─────────────────────────────────────────── */
#alert-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: calc(100% - 24px);
  max-width: 560px;
  margin: 4px auto 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(18, 20, 24, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

#alert-banner.show {
  opacity: 1;
  transform: translateY(0);
}

.alert-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 18px;
  line-height: 1;
}

.alert-text { min-width: 0; }

#alert-msg {
  font-size: 15px;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

.alert-sub {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
  color: var(--muted);
}

#alert-banner.alert-red {
  border-color: rgba(255, 107, 107, 0.35);
  background: rgba(48, 20, 23, 0.92);
}
#alert-banner.alert-red #alert-msg { color: var(--red); }
#alert-banner.alert-red .alert-icon { background: rgba(255, 107, 107, 0.12); }

#alert-banner.alert-orange {
  border-color: rgba(255, 159, 90, 0.35);
  background: rgba(46, 29, 18, 0.92);
}
#alert-banner.alert-orange #alert-msg { color: var(--orange); }
#alert-banner.alert-orange .alert-icon { background: rgba(255, 159, 90, 0.12); }

#alert-banner.alert-yellow {
  border-color: rgba(245, 196, 81, 0.35);
  background: rgba(45, 37, 16, 0.92);
}
#alert-banner.alert-yellow #alert-msg { color: var(--yellow); }
#alert-banner.alert-yellow .alert-icon { background: rgba(245, 196, 81, 0.12); }

#alert-banner.alert-green {
  border-color: rgba(61, 220, 151, 0.35);
  background: rgba(16, 40, 31, 0.92);
}
#alert-banner.alert-green #alert-msg { color: var(--green); }
#alert-banner.alert-green .alert-icon { background: rgba(61, 220, 151, 0.12); }

#alert-banner.alert-cyan {
  border-color: rgba(100, 168, 255, 0.35);
  background: rgba(18, 30, 48, 0.92);
}
#alert-banner.alert-cyan #alert-msg { color: var(--accent); }
#alert-banner.alert-cyan .alert-icon { background: rgba(100, 168, 255, 0.12); }

/* ── BOTTOM PANEL ─────────────────────────────────────────── */
#bottom-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 12px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(8, 9, 11, 0.94) 35%, rgba(8, 9, 11, 0.6) 70%, transparent);
  pointer-events: auto;
}

#metrics,
#controls,
#start-btn {
  width: 100%;
  max-width: 640px;
}

/* ── METRICS ──────────────────────────────────────────────── */
#metrics {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  overflow: hidden;
}

.metric-card {
  padding: 8px 3px 7px;
  text-align: center;
  border-right: 1px solid var(--divider);
  transition: background 0.2s ease;
}

.metric-card:last-child { border-right: none; }

.metric-card.active { background: rgba(100, 168, 255, 0.07); }

.metric-label {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--faint);
  white-space: nowrap;
}

.metric-value {
  margin-top: 2px;
  font-size: clamp(14px, 4.2vw, 17px);
  font-weight: 650;
  line-height: 1.25;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: color 0.2s ease;
}

.metric-value.ok { color: var(--green); }
.metric-value.warn { color: var(--yellow); }
.metric-value.danger { color: var(--red); }

.metric-unit {
  font-size: 9px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--faint);
  white-space: nowrap;
}

/* ── CONTROLS ─────────────────────────────────────────────── */
#controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(21, 23, 28, 0.72);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
  touch-action: manipulation;
}

.toggle-btn::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--faint);
  flex: 0 0 auto;
  transition: background 0.18s ease;
}

.toggle-btn.on {
  border-color: rgba(100, 168, 255, 0.32);
  background: rgba(100, 168, 255, 0.1);
  color: var(--text);
}

.toggle-btn.on::before { background: var(--accent); }

.toggle-btn.warn-on {
  border-color: rgba(255, 107, 107, 0.34);
  background: rgba(255, 107, 107, 0.1);
  color: var(--red);
}

.toggle-btn.warn-on::before { background: var(--red); }

.toggle-btn:active { opacity: 0.75; }

/* ── PRIMARY BUTTON ───────────────────────────────────────── */
#start-btn {
  width: 100%;
  height: 46px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--accent);
  color: #06101f;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease,
              transform 0.1s ease;
  touch-action: manipulation;
}

#start-btn:active { transform: scale(0.99); }

#start-btn.active {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.16);
  color: var(--text);
}

/* ── GET STARTED SCREEN ───────────────────────────────────── */
#permissions-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: safe center;
  justify-content: center;
  padding: 28px 20px calc(28px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(100, 168, 255, 0.09), transparent 60%),
    var(--bg);
  overflow-y: auto;
  scrollbar-width: none;
}

#permissions-screen::-webkit-scrollbar { display: none; }

.perm-inner {
  width: 100%;
  max-width: 400px;
  margin: auto;
  text-align: left;
}

.perm-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 30px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--text);
}

.perm-brand-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.perm-title {
  margin: 0 0 10px;
  font-size: 25px;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text);
}

.perm-desc {
  margin: 0 0 22px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--muted);
}

.feature-list {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  display: grid;
  gap: 9px;
}

.feature-list li {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.feature-list li::before {
  content: '✓';
  flex: 0 0 auto;
  margin-top: 1px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}

.tag {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--faint);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: 1px;
}

.opt-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(21, 23, 28, 0.7);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.opt-row input {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--accent);
}

.voice-row {
  justify-content: space-between;
  gap: 12px;
}

.opt-label {
  color: var(--muted);
  white-space: nowrap;
}

#voice-select {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 62%;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  text-align: right;
  cursor: pointer;
}

#voice-select option {
  background: var(--surface-flat);
  color: var(--text);
}

#voice-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

#grant-btn {
  width: 100%;
  height: 48px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--accent);
  color: #06101f;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.1s ease;
  touch-action: manipulation;
}

#grant-btn:active { transform: scale(0.99); }
#grant-btn:disabled { opacity: 0.6; cursor: default; }

.perm-error {
  min-height: 16px;
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--red);
}

.disclaimer {
  margin: 14px 0 0;
  font-size: 11px;
  line-height: 1.55;
  color: var(--faint);
}

/* ── FLASH ────────────────────────────────────────────────── */
#flash {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

#flash.flash-red { background: rgba(255, 107, 107, 0.16); }
#flash.flash-green { background: rgba(61, 220, 151, 0.1); }
#flash.flash-yellow { background: rgba(245, 196, 81, 0.1); }
#flash.flash-orange { background: rgba(255, 159, 90, 0.12); }
#flash.flash-cyan { background: rgba(100, 168, 255, 0.08); }

/* ── HIDDEN PROCESSING CANVAS ─────────────────────────────── */
#proc-canvas { display: none; }

/* Compact HUD for landscape phones and short windows. */
@media (max-height: 560px) {
  #top-bar {
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-bottom: 8px;
  }
  #bottom-bar {
    gap: 8px;
    padding-top: 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .metric-card { padding: 6px 3px 5px; }
  .metric-value { font-size: 15px; }
  .toggle-btn { height: 30px; }
  #start-btn { height: 40px; }
}

@media (min-width: 700px) and (max-height: 560px) {
  #controls { grid-template-columns: repeat(8, 1fr); }
}

/* ── SMALL / SHORT SCREENS ────────────────────────────────── */
@media (max-height: 680px) {
  .perm-brand { margin-bottom: 18px; }
  .perm-title { font-size: 22px; }
  .perm-desc { margin-bottom: 16px; }
  .feature-list { gap: 7px; margin-bottom: 16px; }
  .feature-list li { font-size: 12px; }
  .opt-row { padding: 10px 12px; margin-bottom: 10px; }
  #grant-btn { height: 44px; }
  .disclaimer { margin-top: 10px; }
}

@media (max-width: 360px) {
  .metric-label,
  .metric-unit { font-size: 8px; }
  .toggle-btn { font-size: 10px; gap: 4px; }
}
