:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #080b10;
  color: #f7f8fa;
  font-synthesis: none;
  --surface: #10151d;
  --surface-raised: #171e28;
  --border: #28313e;
  --muted: #8993a3;
  --green: #31d17c;
  --red: #ff4655;
  --amber: #f2b84b;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: #080b10;
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at 8% 0%, rgba(49, 135, 255, 0.09), transparent 32rem),
    radial-gradient(circle at 95% 5%, rgba(255, 70, 85, 0.09), transparent 30rem),
    #080b10;
}

button { font: inherit; }

.monitor-shell {
  width: min(100%, 1440px);
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(30px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.monitor-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 18px;
}

.eyebrow,
.card-label {
  margin: 0;
  color: #95a1b4;
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.14em;
  line-height: 1.35;
  text-transform: uppercase;
}

h1 {
  margin: 5px 0 0;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  letter-spacing: -0.045em;
}

.monitor-subtitle {
  margin: 5px 0 0;
  color: #8f99a8;
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.system-state,
.header-link {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #0d1118;
  color: #c5ccd6;
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-decoration: none;
  text-transform: uppercase;
}

.system-dot,
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(242, 184, 75, 0.11);
}

.system-state[data-state="online"] .system-dot { background: var(--green); box-shadow: 0 0 0 4px rgba(49, 209, 124, 0.11); }
.system-state[data-state="warning"] .system-dot { background: var(--amber); }

.summary-bar {
  display: grid;
  grid-template-columns: repeat(3, auto) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(13, 17, 24, 0.82);
}

.summary-bar > div {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 92px;
}

.summary-bar strong {
  color: #f5f7fa;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.summary-bar span,
.summary-bar p {
  color: #8e99a9;
  font-size: 0.78rem;
}

.summary-bar p {
  justify-self: end;
  margin: 0;
}

.deck-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.monitor-card {
  --accent: #ff4655;
  --accent-soft: rgba(255, 70, 85, 0.13);
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 18px;
  background: linear-gradient(145deg, var(--accent-soft), transparent 42%), var(--surface);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.2);
}

.monitor-card[data-deck="jf"] { --accent: #ff4655; --accent-soft: rgba(255, 70, 85, 0.14); }
.monitor-card[data-deck="eng1"] { --accent: #3187ff; --accent-soft: rgba(49, 135, 255, 0.14); }
.monitor-card[data-deck="eng2"] { --accent: #f0ad35; --accent-soft: rgba(240, 173, 53, 0.13); }
.monitor-card[data-deck="eng3"] { --accent: #9b6cff; --accent-soft: rgba(155, 108, 255, 0.14); }
.monitor-card[data-deck="eng4"] { --accent: #19c3cf; --accent-soft: rgba(25, 195, 207, 0.13); }
.monitor-card[data-deck="eng5"] { --accent: #33c676; --accent-soft: rgba(51, 198, 118, 0.13); }

.monitor-card[data-state="recording"] {
  border-color: color-mix(in srgb, var(--accent) 72%, #ffffff 10%);
  box-shadow: 0 0 0 1px var(--accent-soft), 0 18px 48px rgba(0, 0, 0, 0.3);
}

.monitor-card[data-state="offline"],
.monitor-card[data-state="unconfigured"] { opacity: 0.68; }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 18px 13px;
}

.deck-name {
  margin: 3px 0 0;
  color: var(--accent);
  font-size: clamp(1.4rem, 3vw, 2rem);
  letter-spacing: -0.04em;
}

.status-pill {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border: 1px solid #303a48;
  border-radius: 999px;
  background: rgba(8, 11, 16, 0.8);
  color: #b9c2cf;
  font-size: 0.66rem;
  font-weight: 850;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.monitor-card[data-state="recording"] .status-pill { color: #ff8089; }
.monitor-card[data-state="recording"] .status-dot { background: #ff3b46; box-shadow: 0 0 0 4px rgba(255, 59, 70, 0.12); animation: pulse 1.5s ease-in-out infinite; }
.monitor-card[data-state="stopped"] .status-dot { background: var(--green); box-shadow: 0 0 0 4px rgba(49, 209, 124, 0.11); }
.monitor-card[data-state="offline"] .status-dot,
.monitor-card[data-state="unconfigured"] .status-dot { background: #667184; box-shadow: none; }

.timecode-block {
  padding: 8px 18px 17px;
}

.timecode {
  display: block;
  margin-top: 6px;
  color: #f4f6f8;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: clamp(1.45rem, 3.3vw, 2.05rem);
  font-weight: 750;
  letter-spacing: 0.035em;
  font-variant-numeric: tabular-nums;
}

.file-block {
  min-height: 92px;
  padding: 13px 18px 14px;
  border-top: 1px solid var(--border);
  background: rgba(7, 10, 15, 0.32);
}

.previous-file-block {
  min-height: 108px;
  background: rgba(7, 10, 15, 0.5);
}

.file-line {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-top: 7px;
}

.file-name {
  min-width: 0;
  margin: 0;
  color: #f3f5f7;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.previous-info { min-width: 0; }

.file-duration {
  margin: 6px 0 0;
  color: #8f9aab;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.card-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  background: rgba(8, 11, 16, 0.7);
}

.mini-control {
  position: relative;
  min-width: 0;
  min-height: 38px;
  overflow: hidden;
  border: 1px solid #3a4658;
  border-radius: 10px;
  background: #1a2230;
  color: #edf1f6;
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.record-control {
  border-color: rgba(255, 70, 85, 0.45);
  background: rgba(255, 70, 85, 0.14);
  color: #ff8d96;
}

.stop-control { touch-action: none; }
.stop-control > span:last-child { position: relative; z-index: 1; }
.stop-progress {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: #d71f2d;
  pointer-events: none;
}
.stop-control[data-holding="true"] .stop-progress { animation: hold-fill 1s linear forwards; }
.stop-control[data-holding="complete"] .stop-progress { width: 100%; }
.mini-control:disabled { opacity: 0.28; cursor: default; }

.monitor-modal {
  width: min(92vw, 390px);
  padding: 0;
  border: 1px solid #3b4656;
  border-radius: 18px;
  background: #171e28;
  color: #f7f8fa;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.55);
}
.monitor-modal::backdrop { background: rgba(3, 6, 10, 0.8); backdrop-filter: blur(5px); }
.monitor-modal form { padding: 22px; }
.monitor-modal h2 { margin: 5px 0 8px; font-size: 1.35rem; }
.monitor-modal form > p:not(.eyebrow):not(.pin-error) { margin: 0 0 16px; color: #a4adba; font-size: 0.88rem; }
.monitor-modal input {
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  border: 1px solid #435064;
  border-radius: 10px;
  background: #0c1118;
  color: #ffffff;
  font: 700 1.05rem "SFMono-Regular", Consolas, monospace;
}
.pin-error { min-height: 20px; margin: 7px 0 0; color: #ff7d87; font-size: 0.78rem; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 12px; }
.modal-actions button { min-height: 44px; border-radius: 10px; font-weight: 850; cursor: pointer; }
.modal-cancel { border: 1px solid #445064; background: #222c3a; color: #e8edf4; }
.modal-continue { border: 1px solid #d92a37; background: #d71f2d; color: #fff; }

.copy-button {
  flex: 0 0 auto;
  min-width: 42px;
  min-height: 36px;
  padding: 6px 9px;
  border: 1px solid #3a4658;
  border-radius: 9px;
  background: #202938;
  color: #e8edf4;
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0.06em;
  cursor: pointer;
  touch-action: manipulation;
}

.copy-button:disabled { opacity: 0.28; cursor: default; }
.copy-button[data-copied="true"] { border-color: var(--green); color: #48e5aa; }

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 18px;
  border-top: 1px solid rgba(40, 49, 62, 0.75);
  color: #7e8999;
  font-size: 0.72rem;
}

.control-link { color: #abb6c5; font-weight: 750; text-decoration: none; }
.control-link:hover { color: #ffffff; }

.header-link:focus-visible,
.control-link:focus-visible,
.copy-button:focus-visible { outline: 3px solid #7bb7ff; outline-offset: 2px; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@keyframes hold-fill { from { width: 0; } to { width: 100%; } }

.history-panel {
  margin-top: 18px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(13, 17, 24, 0.92);
}

.history-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.history-header h2 { margin: 4px 0 0; font-size: 1.35rem; }
.history-header p:not(.eyebrow) { margin: 5px 0 0; color: #8f99a8; font-size: 0.8rem; }
.history-tools { display: flex; align-items: center; gap: 8px; }
.history-tools label { color: #8f99a8; font-size: 0.72rem; font-weight: 750; }
.history-tools select,
.history-tools button {
  min-height: 38px;
  border: 1px solid #3a4658;
  border-radius: 9px;
  background: #1a2230;
  color: #edf1f6;
  font-size: 0.7rem;
  font-weight: 800;
}
.history-tools select { padding: 0 30px 0 10px; }
.history-tools button { padding: 0 12px; cursor: pointer; }
.history-tools .history-danger { border-color: rgba(255, 71, 89, 0.5); color: #ff8e99; }
.history-tools .history-danger:hover { background: rgba(255, 71, 89, 0.12); }
.history-filterbar {
  display: grid;
  grid-template-columns: 180px minmax(220px, 1fr) auto auto;
  gap: 12px;
  align-items: end;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(40, 49, 62, 0.72);
  background: rgba(12, 18, 27, 0.7);
}
.history-filterbar label { display: grid; gap: 5px; color: #8f99a8; font-size: 0.7rem; font-weight: 750; }
.history-filterbar select,
.history-filterbar input[type="search"] { height: 34px; border: 1px solid #334155; border-radius: 8px; background: #111927; color: #f2f5f8; padding: 0 10px; }
.history-filterbar .history-check { display: flex; align-items: center; gap: 7px; height: 34px; white-space: nowrap; }
#historyResultCount { align-self: center; color: #7f8a9b; font-size: 0.72rem; white-space: nowrap; }

.history-chart {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 18px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.chart-item { --chart-accent: #7c8798; min-width: 0; }
.chart-item[data-deck="jf"] { --chart-accent: #ff4655; }
.chart-item[data-deck="eng1"] { --chart-accent: #3187ff; }
.chart-item[data-deck="eng2"] { --chart-accent: #f0ad35; }
.chart-item[data-deck="eng3"] { --chart-accent: #9b6cff; }
.chart-item[data-deck="eng4"] { --chart-accent: #19c3cf; }
.chart-item[data-deck="eng5"] { --chart-accent: #33c676; }
.chart-meta { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-size: 0.72rem; }
.chart-meta span { color: #9aa5b5; font-family: "SFMono-Regular", Consolas, monospace; }
.chart-track { height: 7px; overflow: hidden; border-radius: 999px; background: #242d3a; }
.chart-track span { display: block; height: 100%; border-radius: inherit; background: var(--chart-accent); }

.history-table-wrap { overflow: auto; max-height: 420px; }
.history-table { width: 100%; border-collapse: collapse; font-size: 0.74rem; }
.history-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 12px;
  background: #171e28;
  color: #929daf;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.history-table td { padding: 10px 12px; border-top: 1px solid rgba(40, 49, 62, 0.72); color: #d7dde6; white-space: nowrap; }
.history-table tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
.history-file { max-width: 380px; overflow: hidden; text-overflow: ellipsis; font-family: "SFMono-Regular", Consolas, monospace; }
.history-live { color: #ff6974 !important; font-weight: 850; }
.history-open {
  min-width: 78px;
  min-height: 28px;
  border: 1px solid #3c4a60;
  border-radius: 7px;
  background: #1b2534;
  color: #e8edf5;
  font-size: 0.65rem;
  font-weight: 850;
  cursor: pointer;
}
.history-open:hover { border-color: #6e86a8; background: #253349; }
.is-phone .desktop-history { display: none !important; }

@media (max-width: 940px) {
  .deck-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-chart { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-header { align-items: flex-start; }
  .history-tools { flex-wrap: wrap; justify-content: flex-end; }
  .history-filterbar { grid-template-columns: 160px 1fr; }
}

@media (max-width: 699px) {
  .desktop-history { display: none; }
}

@media (max-width: 620px) {
  .monitor-shell { padding-top: max(14px, env(safe-area-inset-top)); padding-right: max(12px, env(safe-area-inset-right)); padding-left: max(12px, env(safe-area-inset-left)); }
  .monitor-header { align-items: flex-start; gap: 12px; margin-bottom: 12px; }
  .monitor-subtitle { display: none; }
  .header-actions { max-width: 158px; gap: 5px; }
  .system-state, .header-link { min-height: 32px; padding: 6px 8px; font-size: 0.61rem; }
  .summary-bar { grid-template-columns: repeat(3, 1fr); padding: 8px 10px; }
  .summary-bar > div { min-width: 0; justify-content: center; }
  .summary-bar p { grid-column: 1 / -1; justify-self: center; }
  .deck-grid { grid-template-columns: 1fr; gap: 10px; }
  .card-header { padding: 13px 14px 9px; }
  .timecode-block { padding: 5px 14px 12px; }
  .file-block { min-height: 82px; padding: 11px 14px 12px; }
  .previous-file-block { min-height: 96px; }
  .card-controls { padding: 9px 14px; }
  .card-footer { padding: 8px 14px; }
}

@media (orientation: landscape) and (max-height: 720px) and (min-width: 700px) {
  .monitor-shell { padding-top: max(10px, env(safe-area-inset-top)); }
  .monitor-header { margin-bottom: 10px; }
  .monitor-subtitle { display: none; }
  .summary-bar { margin-bottom: 10px; padding-top: 7px; padding-bottom: 7px; }
  .deck-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .card-header { padding-top: 11px; padding-bottom: 7px; }
  .timecode-block { padding-top: 3px; padding-bottom: 10px; }
  .file-block { min-height: 76px; padding-top: 8px; padding-bottom: 9px; }
  .previous-file-block { min-height: 88px; }
  .card-controls { padding-top: 7px; padding-bottom: 7px; }
  .card-footer { padding-top: 7px; padding-bottom: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  .monitor-card[data-state="recording"] .status-dot { animation: none; }
}
