:root {
  --bg: #08101f;
  --bg-gradient: linear-gradient(180deg, #07111f 0%, #09121f 100%);
  --surface: rgba(20, 33, 56, 0.96);
  --surface2: rgba(38, 55, 83, 0.95);
  --surface3: #172c47;
  --border: rgba(100, 116, 139, 0.24);
  --text: #f8fafc;
  --muted: #94a3b8;
  --dim: #7b8a9f;
  --accent: #38bdf8;
  --accent2: #7dd3fc;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.22);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.3), 0 10px 24px rgba(0, 0, 0, 0.32);
  --shadow-lg: 0 -2px 8px rgba(0, 0, 0, 0.25), 0 -12px 40px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-gradient);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  padding-bottom: 180px;
}

.hidden { display: none !important; }

/* Auth */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.auth-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.auth-card .subtitle { color: var(--muted); font-size: 14px; margin-bottom: 24px; }

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="date"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
}

input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active { transform: none; }

.btn:focus-visible,
.icon-btn:focus-visible,
.app-tabs button:focus-visible,
.call-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  color: #0f172a;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.28);
}

.btn-primary:hover { box-shadow: 0 6px 18px rgba(56, 189, 248, 0.36); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.16);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
}

.error-msg {
  color: var(--red);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
}

/* App layout */
.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid transparent;
  border-image: linear-gradient(90deg, rgba(56, 189, 248, 0.35), rgba(56, 189, 248, 0)) 1;
}

.app-header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.header-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.header-status.live-active { color: var(--green); }
.header-status.live-active .header-status-text { color: var(--green); }

.header-status.live-partial { color: var(--amber); }
.header-status.live-partial .header-status-text { color: var(--amber); }
.header-status.live-partial .live-dot { background: var(--amber); animation: live-pulse 2s ease-in-out infinite; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.stat-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, rgba(56, 189, 248, 0), var(--accent), rgba(56, 189, 248, 0));
  opacity: 0.55;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: rgba(56, 189, 248, 0.35);
}

.stat-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-value .status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

.stat-value .status-dot.up { background: var(--green); }
.stat-value .status-dot.down { background: var(--red); }

.stat-warn {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  vertical-align: middle;
  color: #fef3c7;
  background: rgba(245, 158, 11, 0.22);
  border: 1px solid rgba(245, 158, 11, 0.5);
}

.stat-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

.disk-warn {
  background: #7f1d1d44;
  border: 1px solid var(--red);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* App tabs */
.app-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.app-tabs button {
  transition: background-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.app-tabs button.active {
  box-shadow: 0 2px 10px rgba(56, 189, 248, 0.3);
}

.tab-panel:not(.hidden) {
  animation: fade-in 0.22s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.app-tabs button {
  flex: 1;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
}

.app-tabs button:hover {
  background: rgba(56, 189, 248, 0.09);
  color: var(--text);
}

.app-tabs button.active {
  background: var(--accent);
  color: #0f172a;
}

.tab-panel.hidden { display: none !important; }

body.tab-timemachine { padding-bottom: 24px; }

/* Time Machine */
.tm-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}

.tm-toolbar input[type="date"] {
  flex: 0 0 150px;
  width: auto;
}

.tm-call-count {
  font-size: 13px;
  color: var(--muted);
}

.tm-scrub-label {
  margin-left: auto;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent2);
}

.tm-shift-toggle {
  display: inline-flex;
  gap: 4px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.tm-shift-toggle .btn-sm {
  min-width: 58px;
  padding: 6px 10px;
  border-radius: 6px;
}

.tm-shift-toggle .btn-sm.active {
  background: var(--accent);
  color: #0f172a;
}

.tm-zoom-controls {
  display: flex;
  gap: 4px;
}

.tm-zoom-controls .btn-sm {
  min-width: 36px;
  padding: 6px 8px;
}

.tm-tooltip {
  position: absolute;
  bottom: 100%;
  left: 0;
  transform: translate(-50%, -8px);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
}

.tm-hour-panel {
  margin-bottom: 16px;
}

.tm-hour-panel.hidden { display: none !important; }

.tm-hour-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.tm-hour-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface2) transparent;
}

.tm-hour-list::-webkit-scrollbar { width: 8px; }
.tm-hour-list::-webkit-scrollbar-track { background: transparent; }
.tm-hour-list::-webkit-scrollbar-thumb {
  background: var(--surface2);
  border-radius: 999px;
}
.tm-hour-list::-webkit-scrollbar-thumb:hover { background: #3b5478; }

.tm-hour-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}

.tm-hour-row:hover { border-color: var(--accent); }
.tm-hour-row.playing { border-color: var(--accent); background: rgba(56, 189, 248, 0.08); }
.tm-hour-row-time { color: var(--muted); min-width: 52px; font-variant-numeric: tabular-nums; }
.tm-hour-row-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm-hour-row-dur { color: var(--dim); font-size: 12px; }

.day-timeline-wrap {
  margin-bottom: 20px;
}

.day-timeline-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.day-timeline-hours {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--dim);
  margin-top: 4px;
  opacity: 0.7;
}

.day-timeline {
  position: relative;
  height: 88px;
  background: #0a101f;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

.day-timeline-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.day-timeline-cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
  box-shadow: 0 0 6px rgba(56, 189, 248, 0.9);
  pointer-events: none;
  z-index: 3;
  transform: translateX(-1px);
}

.day-timeline-cursor::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #fff;
}

.tm-player {
  background: rgba(24, 41, 66, 0.96);
  border: 1px solid rgba(100, 116, 139, 0.24);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}

.tm-waveform-wrap {
  min-height: 76px;
}

.tm-waveform-wrap .waveform {
  min-height: 76px;
}

/* Toolbar */
.toolbar-sticky {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(8, 16, 31, 0.96);
  backdrop-filter: blur(12px);
  padding: 12px 0 6px;
  margin-bottom: 18px;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding: 10px 0;
}

.toolbar input[type="date"] {
  flex: 0 0 180px;
  min-width: 140px;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 160px;
}

.search-wrap input[type="search"] {
  padding-right: 40px;
}

.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-clear:hover {
  background: var(--surface2);
  color: var(--text);
}

/* Sections */
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dim);
  flex-shrink: 0;
}

.live-active .live-dot {
  background: var(--green);
  animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  50% { opacity: 0.85; box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

.section-badge {
  font-size: 11px;
  font-weight: 700;
  background: var(--surface2);
  color: var(--text);
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0;
  text-transform: none;
}

#section-earlier { margin-top: 24px; }

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

.timeline-note {
  color: var(--dim);
  font-size: 13px;
  line-height: 1.4;
}

.timeline-group {
  margin: 16px 0 4px;
}

.timeline-group-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.18);
  border-radius: 14px;
  font-size: 13px;
  color: var(--accent2);
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.timeline-group-toggle:hover {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.28);
}

.timeline-group-toggle:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.timeline-group-label {
  flex: 1;
}

.timeline-group-icon {
  margin-left: 8px;
  transition: transform 0.2s;
  font-size: 12px;
}

.timeline-group-toggle[aria-expanded="false"] .timeline-group-icon {
  transform: rotate(-90deg);
}

.timeline-group-content {
  overflow: hidden;
  transition: max-height 0.3s ease-out, opacity 0.2s ease-out;
  max-height: 10000px;
  opacity: 1;
}

.timeline-group-content.collapsed {
  max-height: 0;
  opacity: 0;
}

/* Call list */
.call-list { display: flex; flex-direction: column; gap: 6px; }

.call-row {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  background: rgba(24, 41, 66, 0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.18s ease, background-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

/* Accept flourish (Queue tab) — visually distinct from the delete dissolve */
.call-row.accept-flash {
  border-color: rgba(34, 197, 94, 0.6);
  background: rgba(34, 197, 94, 0.14);
}

.call-row.accept-slide {
  transform: translateX(40px);
  opacity: 0;
  margin-top: -6px;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
  transition: transform 0.34s ease, opacity 0.3s ease, max-height 0.34s ease,
    margin 0.34s ease, padding 0.34s ease, border-width 0.34s ease;
}

.accept-check {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%) scale(0.4);
  opacity: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(34, 197, 94, 0.9);
  color: #052e16;
  font-size: 18px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.22s ease;
}

.accept-check.show {
  transform: translateY(-50%) scale(1);
  opacity: 1;
}

.call-row:hover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
}

.call-row.playing {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
}

.call-row.new-call {
  animation: highlight 2.2s ease-out, call-slide-in 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes highlight {
  from { background: #0c4a6e66; }
  to { background: var(--surface); }
}

@keyframes call-slide-in {
  from { opacity: 0; transform: translateY(-14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.call-row[data-tag-color] {
  box-shadow: var(--shadow), inset 3px 0 0 var(--row-tag-color);
  background: linear-gradient(90deg, var(--row-tag-tint), rgba(24, 41, 66, 0.96) 40%);
}

.call-row.tag-pulse {
  animation: tag-pulse 1.6s ease-in-out infinite;
}

@keyframes tag-pulse {
  0%, 100% { box-shadow: var(--shadow), inset 3px 0 0 var(--row-tag-color), 0 0 0 0 var(--row-tag-pulse-a); }
  50%      { box-shadow: var(--shadow), inset 3px 0 0 var(--row-tag-color), 0 0 0 6px var(--row-tag-pulse-b); }
}

.tag-emergency-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  vertical-align: middle;
}

/* DURESS: highest-priority alert (crew safety) — a full siren-style strobe
   well beyond the standard tag pulse, so it's unmistakable at a glance. */
.call-row[data-tag-id="duress"] {
  animation: duress-alarm 0.65s steps(2, end) infinite;
  border-color: transparent;
}

@keyframes duress-alarm {
  0%, 100% {
    box-shadow: var(--shadow), inset 5px 0 0 var(--row-tag-color), 0 0 0 2px rgba(236, 72, 153, 0.9), 0 0 28px rgba(236, 72, 153, 0.65);
    background: linear-gradient(90deg, rgba(236, 72, 153, 0.32), rgba(24, 41, 66, 0.96) 60%);
  }
  50% {
    box-shadow: var(--shadow), inset 5px 0 0 var(--row-tag-color), 0 0 0 2px rgba(255, 255, 255, 0.85), 0 0 40px rgba(236, 72, 153, 0.9);
    background: linear-gradient(90deg, rgba(236, 72, 153, 0.55), rgba(24, 41, 66, 0.96) 70%);
  }
}

.call-row[data-tag-id="duress"] .tag-emergency-badge {
  font-size: 13px;
  font-weight: 900;
  padding: 4px 12px;
  letter-spacing: 0.03em;
  animation: duress-badge-flash 0.65s steps(2, end) infinite;
}

@keyframes duress-badge-flash {
  0%, 100% { background: #ec4899; color: #fff; box-shadow: 0 0 12px rgba(236, 72, 153, 0.8); }
  50%      { background: #fff; color: #831843; box-shadow: 0 0 18px rgba(255, 255, 255, 0.9); }
}

@media (prefers-reduced-motion: reduce) {
  .call-row[data-tag-id="duress"],
  .call-row[data-tag-id="duress"] .tag-emergency-badge {
    animation: none;
    box-shadow: var(--shadow), inset 5px 0 0 var(--row-tag-color), 0 0 0 2px rgba(236, 72, 153, 0.9);
    background: #ec489955;
  }
}

.complaint-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
  color: var(--muted);
  background: rgba(148, 163, 184, 0.14);
  border: 1px solid var(--border);
}

.color-swatch-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.25);
  display: block;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.tag-select {
  height: 38px;
  min-width: 96px;
  max-width: 120px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 0 8px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.tag-select:hover {
  border-color: var(--accent);
}

.tag-select option {
  background: var(--surface, #182942);
  color: #f1f5f9;
}

/* Manage Tags drawer */
.tag-manager-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.tag-manager-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(24, 41, 66, 0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.tag-manager-row-label {
  font-weight: 600;
  flex: 1;
}

.tag-manager-row-actions {
  display: flex;
  gap: 4px;
}

.tag-manager-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.tag-form-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-palette-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  padding: 0;
}

.tag-palette-swatch.selected {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

.tag-form-pulse-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.tag-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Per-call waveform */
.call-wave {
  grid-column: 1 / -1;
  width: 100%;
  height: 34px;
  display: block;
  margin-top: 2px;
}

.call-row.emergency .call-wave { opacity: 0.95; }

.call-row.playing .call-wave {
  animation: wave-pulse 1.8s ease-in-out infinite;
}

@keyframes wave-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.call-time {
  font-size: 14px;
  font-weight: 700;
  min-width: 72px;
  color: var(--accent2);
  font-variant-numeric: tabular-nums;
}

.call-body {
  min-width: 0;
}
.call-label {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.call-meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.call-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.15s ease;
}

.icon-btn:hover {
  background: rgba(56, 189, 248, 0.18);
  color: #f8fafc;
  transform: translateY(-1px);
}

.icon-btn:active { transform: none; }

.icon-btn-danger {
  background: rgba(239, 68, 68, 0.14);
}

.icon-btn-danger:hover {
  background: rgba(239, 68, 68, 0.32);
  color: #fff;
}

.icon-btn-accept {
  background: rgba(34, 197, 94, 0.16);
}

.icon-btn-accept:hover {
  background: rgba(34, 197, 94, 0.34);
  color: #fff;
}

.icon-btn-active {
  background: rgba(234, 179, 8, 0.28);
  color: #fde68a;
}

.icon-btn-active:hover {
  background: rgba(234, 179, 8, 0.42);
}

.call-row.bad-audio-flagged {
  box-shadow: inset 3px 0 0 rgba(234, 179, 8, 0.7);
}

/* Skeleton loading rows */
.call-row.skeleton {
  pointer-events: none;
  cursor: default;
}

.skeleton-block {
  background: linear-gradient(90deg, var(--surface2) 25%, #475569 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
  border-radius: 6px;
}

.call-row.skeleton .call-time {
  width: 64px;
  height: 16px;
  min-width: 64px;
}

.call-row.skeleton .call-label {
  width: 55%;
  height: 14px;
  margin-bottom: 6px;
}

.call-row.skeleton .call-meta {
  width: 35%;
  height: 12px;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.load-more {
  width: 100%;
  margin-top: 12px;
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
  font-size: 14px;
  opacity: 0.85;
}

.empty-state::before {
  content: '';
  display: block;
  width: 32px;
  height: 32px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 2px dashed rgba(148, 163, 184, 0.4);
}

/* Player bar */
.player-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(8, 16, 31, 0.98);
  border-top: 1px solid rgba(100, 116, 139, 0.22);
  padding: 14px 18px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 14px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg);
}

.player-bar:not(.hidden) {
  animation: slide-up 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

.tm-player:not(.hidden) {
  animation: slide-up 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.player-top {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.player-controls {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.player-btn {
  min-width: 44px;
  min-height: 44px;
  font-size: 18px;
  font-weight: 700;
}

.player-info { flex: 1; min-width: 0; }

#player-title {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.player-time {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}

.waveform-wrap {
  position: relative;
  width: 100%;
  min-height: 48px;
}

.waveform {
  width: 100%;
  min-height: 48px;
}

.waveform-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.7);
  font-size: 12px;
  color: var(--muted);
  border-radius: 8px;
}

.trim-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 8px;
}

.trim-readout {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text, #e2e8f0);
}

.trim-bar-actions {
  display: flex;
  gap: 8px;
}

.waveform-wrap .wavesurfer-region {
  cursor: grab;
}

.waveform-wrap .wavesurfer-handle {
  cursor: ew-resize;
  background: #38bdf8 !important;
  width: 4px !important;
}

/* Spectrum + VU meter */
.spectrum-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  /* Reveal smoothly only while a call is actually playing. */
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.spectrum-strip.spectrum-live {
  opacity: 1;
  transform: translateY(0);
}

.spectrum {
  flex: 1;
  min-width: 0;
  height: 30px;
  opacity: 0.9;
}

.vu-meter {
  position: relative;
  flex-shrink: 0;
  width: 68px;
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.vu-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #38bdf8, #7dd3fc);
  transition: width 60ms linear;
}

.vu-peak {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0%;
  width: 2px;
  margin-left: -1px;
  background: #e0f2fe;
  box-shadow: 0 0 4px rgba(224, 242, 254, 0.9);
  transition: left 90ms linear;
}

/* Emergency call accent */
.waveform-wrap.emergency {
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.5), 0 0 18px rgba(220, 38, 38, 0.28);
  border-radius: 10px;
}

.waveform-wrap.emergency .vu-fill {
  background: linear-gradient(90deg, #dc2626, #f87171);
}

.waveform-wrap.emergency .vu-peak {
  background: #fecaca;
  box-shadow: 0 0 4px rgba(254, 202, 202, 0.9);
}

.emergency-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fee2e2;
  background: rgba(220, 38, 38, 0.22);
  border: 1px solid rgba(239, 68, 68, 0.55);
  animation: emergency-pulse 1.4s ease-in-out infinite;
}

@keyframes emergency-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  50% { box-shadow: 0 0 0 5px rgba(239, 68, 68, 0); }
}

/* Hover-to-preview time tooltip */
.waveform-tip {
  position: absolute;
  top: -26px;
  transform: translateX(-50%);
  padding: 2px 7px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  background: rgba(8, 16, 31, 0.95);
  color: var(--text);
  border: 1px solid rgba(100, 116, 139, 0.3);
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
}

/* On Air Now banner (real-time, from Trunk Recorder's stat_socket link) */
.on-air-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.35);
  border-left: 3px solid var(--green);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.on-air-banner .live-dot {
  background: var(--green);
  animation: live-pulse 2s ease-in-out infinite;
}

.on-air-banner.emergency {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.45);
  border-left-color: var(--red);
}

.on-air-banner.emergency .live-dot {
  background: var(--red);
  animation: emergency-pulse 1.4s ease-in-out infinite;
}

.on-air-label {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.on-air-timer {
  flex-shrink: 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* Ambient live-feed activity strip */
.live-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 12px;
  background: var(--surface2, rgba(15, 23, 42, 0.5));
  border: 1px solid rgba(100, 116, 139, 0.18);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.live-strip-canvas {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
}

.live-strip .live-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.live-strip-canvas {
  flex: 1;
  min-width: 0;
  height: 28px;
}

.live-strip-label {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Mobile */
@media (max-width: 520px) {
  body { padding-bottom: 270px; }

  .app {
    padding: 14px;
  }

  .spectrum { height: 24px; }
  .vu-meter { width: 48px; }
  .live-strip-canvas { height: 22px; }
  .live-strip-label { font-size: 11px; }
  .on-air-label { font-size: 13px; }
  .on-air-timer { font-size: 12px; }

  .app-tabs {
    grid-template-columns: 1fr;
  }

  .toolbar {
    gap: 10px;
  }

  .toolbar input[type="date"],
  .search-wrap {
    flex: 1 1 100%;
  }

  .call-row {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 14px;
  }

  .call-wave { height: 26px; order: 5; }

  .call-actions {
    justify-content: flex-end;
    width: 100%;
  }

  .player-top {
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .player-info {
    flex: 1 1 100%;
    order: 3;
  }

  #player-time,
  #tm-player-time {
    order: 4;
  }

  #btn-player-stop,
  #btn-tm-stop {
    order: 5;
    width: 100%;
  }
}

/* Hourly chart */
.hourly-chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.hourly-chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.hourly-chart-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hourly-chart {
  width: 100%;
  height: 64px;
  display: block;
}

/* Chime toggle */
.chime-toggle {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--surface2);
  font-size: 16px;
  line-height: 1;
}

.chime-toggle input { display: none; }
.chime-toggle:has(input:checked) { background: var(--accent); }

/* Call drawer */
.call-drawer {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.call-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.call-drawer-panel {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: 72vh;
  background: rgba(20, 33, 56, 0.98);
  border: 1px solid rgba(100, 116, 139, 0.24);
  border-radius: 20px 20px 16px 16px;
  padding: 20px;
  overflow-y: auto;
  z-index: 1;
}

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

.call-drawer-header h3 { font-size: 16px; }

.call-drawer-body {
  font-size: 14px;
  line-height: 1.6;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--muted); flex-shrink: 0; }
.detail-value { text-align: right; word-break: break-all; }

.detail-row-complaint select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  max-width: 60%;
  font-size: 13px;
}

.call-drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

body.tab-storage { padding-bottom: 24px; }

/* Storage tab */
.storage-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.storage-list { display: flex; flex-direction: column; gap: 8px; }

.storage-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.storage-date {
  font-weight: 600;
  min-width: 100px;
}

.storage-meta {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
}

.storage-actions { display: flex; gap: 6px; flex-shrink: 0; }

.calendar-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}

.calendar-month-label {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 1.05rem;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 0 16px;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 8px 16px 16px;
}

.calendar-day {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}

.calendar-day.adjacent {
  background: transparent;
  border-color: transparent;
  color: var(--dim);
  opacity: 0.35;
  cursor: default;
}

.calendar-day.empty {
  color: var(--dim);
  opacity: 0.55;
}

.calendar-day.has-calls {
  border-color: var(--border);
  background: var(--surface2);
}

.calendar-day.has-calls:hover {
  border-color: var(--accent2);
  box-shadow: var(--shadow-hover);
}

.calendar-day.today {
  border-color: var(--accent);
}

.calendar-day.today .calendar-day-num {
  color: var(--accent2);
  font-weight: 700;
}

.calendar-day.selected {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.14);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.calendar-day-num {
  font-size: 0.9rem;
}

.calendar-day-count {
  font-size: 0.68rem;
  color: var(--accent2);
}

.calendar-day-section {
  padding: 0 16px 24px;
}

@media (min-width: 481px) {
  .call-drawer { align-items: center; }
  .call-drawer-panel {
    border-radius: var(--radius);
    max-height: 80vh;
    margin: 24px;
  }
}
