:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  --bg: #090a0d;
  --bg-soft: #0e1014;
  --panel: #14171c;
  --panel-high: #1a1d23;
  --line: #2a2e36;
  --line-soft: #20242b;
  --text: #f7f4ef;
  --muted: #9299a5;
  --red: #ef4037;
  --red-dark: #941e1a;
  --amber: #f5a623;
  --green: #42d392;
  --blue: #5aa9ff;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }
body { min-width: 1180px; margin: 0; background: radial-gradient(circle at 100% 0, rgba(102, 23, 18, .22), transparent 36rem), var(--bg); }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 26px; letter-spacing: -.025em; }
h2 { margin-bottom: 0; font-size: 18px; letter-spacing: -.015em; }
h3 { margin-bottom: 4px; font-size: 15px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.danger-text { color: #ff746d !important; }

.app-frame { display: grid; grid-template-columns: 246px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; border-right: 1px solid var(--line-soft); background: rgba(9, 10, 13, .96); }
.brand { display: flex; align-items: center; gap: 11px; height: 88px; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); }
.brand-mark { width: 48px; height: 48px; object-fit: contain; filter: drop-shadow(0 0 14px rgba(239, 64, 55, .24)); }
.brand strong { display: block; font-size: 20px; letter-spacing: -.025em; }
.brand span { display: block; color: var(--muted); font-size: 11px; letter-spacing: .09em; text-transform: uppercase; }
.primary-nav { display: grid; gap: 5px; padding: 18px 12px; }
.nav-item { appearance: none; display: grid; grid-template-columns: 25px 1fr auto; align-items: center; gap: 10px; width: 100%; min-height: 45px; padding: 0 12px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: #b6bbc4; text-align: left; cursor: pointer; }
.nav-item:hover { background: #14171c; color: #fff; }
.nav-item.active { border-color: #4a2927; background: linear-gradient(90deg, rgba(126, 28, 24, .48), rgba(38, 21, 21, .3)); color: #fff; box-shadow: inset 3px 0 var(--red); }
.nav-icon { color: var(--amber); text-align: center; font-size: 17px; }
.nav-badge { min-width: 22px; padding: 2px 6px; border-radius: 999px; background: var(--red-dark); text-align: center; font-size: 11px; font-weight: 800; }
.sidebar-foot { margin-top: auto; padding: 18px 20px 22px; border-top: 1px solid var(--line-soft); color: var(--muted); }
.sidebar-foot small { display: block; margin-top: 8px; }
.connection { display: flex; align-items: center; gap: 8px; color: #d5d9df; font-size: 13px; }
.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px rgba(66, 211, 146, .8); }

.workspace { min-width: 0; padding: 0 28px 40px; }
.command-bar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; min-height: 88px; border-bottom: 1px solid var(--line-soft); background: rgba(9, 10, 13, .9); backdrop-filter: blur(16px); }
.command-actions, .row-actions { display: flex; align-items: center; gap: 9px; }
.eyebrow { margin-bottom: 4px; color: var(--amber); font-size: 10px; font-weight: 900; letter-spacing: .15em; text-transform: uppercase; }
.status-chip { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 13px; border: 1px solid var(--line); border-radius: 999px; background: #101216; color: #c8cdd5; font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.status-chip.warning .status-dot { background: var(--amber); }
.status-chip.critical .status-dot { background: var(--red); }
.icon-button { display: inline-grid; width: 38px; height: 38px; place-items: center; border: 1px solid var(--line); border-radius: 9px; background: #111318; cursor: pointer; font-size: 20px; }
.icon-button:hover { border-color: #555c68; background: #1b1e24; }

.view { display: none; padding-top: 22px; }
.view.active { display: block; }
.classification-banner { margin-bottom: 16px; padding: 7px; border: 1px solid #762723; border-radius: 7px; background: linear-gradient(90deg, #5f1714, #2e1110, #5f1714); color: #fff; text-align: center; font-size: 11px; font-weight: 900; letter-spacing: .18em; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric-card { position: relative; overflow: hidden; min-height: 112px; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: linear-gradient(145deg, #181b21, #101216); }
.metric-card::after { position: absolute; right: -22px; bottom: -36px; width: 100px; height: 100px; border: 18px solid rgba(239, 64, 55, .06); border-radius: 50%; content: ""; }
.metric-card strong { display: block; margin: 6px 0 2px; font-size: 30px; letter-spacing: -.04em; }
.metric-label { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.metric-detail { color: #bcc1c9; font-size: 12px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(600px, 1.6fr) minmax(350px, 1fr); gap: 16px; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 13px; background: linear-gradient(150deg, rgba(24, 27, 33, .98), rgba(15, 17, 21, .98)); box-shadow: 0 18px 45px rgba(0, 0, 0, .2); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 70px; padding: 14px 17px; border-bottom: 1px solid var(--line-soft); }
.panel-heading p { margin-bottom: 0; }
.live-indicator { display: flex; align-items: center; gap: 7px; color: #c9ced6; font-size: 12px; }
.live-indicator i, .record-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); box-shadow: 0 0 10px rgba(239, 64, 55, .9); }
.mission-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; padding: 18px; }
.field { display: grid; align-content: start; gap: 6px; min-width: 0; color: #cbd0d8; font-size: 12px; font-weight: 800; }
.field.wide, .wide { grid-column: 1 / -1; }
.field-help { color: var(--muted); font-size: 10px; font-weight: 500; line-height: 1.45; }
input, select, textarea { width: 100%; min-height: 41px; border: 1px solid #343944; border-radius: 8px; outline: none; background: #0b0d10; color: var(--text); padding: 9px 11px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #b53932; box-shadow: 0 0 0 3px rgba(239, 64, 55, .09); }
input[readonly] { color: var(--muted); }
.source-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; max-height: 230px; overflow: auto; }
.source-choice { display: flex; align-items: center; gap: 10px; min-height: 55px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #101216; cursor: pointer; }
.source-choice:has(input:checked) { border-color: #a6322c; background: #271514; }
.source-choice input { width: 17px; min-height: 17px; }
.source-choice strong, .source-choice span { display: block; }
.source-choice small { display: block; margin-top: 2px; color: var(--muted); font-weight: 500; overflow-wrap: anywhere; }
.launch-footer { display: flex; grid-column: 1 / -1; align-items: center; justify-content: space-between; gap: 12px; padding-top: 4px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 0 14px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; font-weight: 800; font-size: 12px; text-decoration: none; }
.button.primary { border-color: #f0554c; background: linear-gradient(180deg, #ec453d, #a7221d); color: #fff; box-shadow: 0 8px 20px rgba(151, 28, 23, .23); }
.button.primary:hover { filter: brightness(1.1); }
.button.secondary { border-color: var(--line); background: #15181d; color: #e3e6ea; }
.button.danger { border-color: #70201c; background: #481715; color: #ffb0ab; }
.button.large { min-height: 45px; padding: 0 20px; }
.button.small { min-height: 30px; padding: 0 9px; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.text-button { border: 0; background: transparent; color: var(--amber); cursor: pointer; font-size: 12px; }

.stack-list { max-height: 540px; overflow: auto; }
.stack-item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 14px 17px; border-bottom: 1px solid var(--line-soft); }
.stack-icon { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid #48302a; border-radius: 9px; background: #251613; color: var(--amber); }
.stack-item strong { display: block; font-size: 13px; }
.stack-item small { color: var(--muted); }
.recent-panel { margin-top: 16px; }
.mission-table { width: 100%; }
.table-row { display: grid; grid-template-columns: minmax(220px, 1.6fr) repeat(4, minmax(100px, .7fr)) auto; align-items: center; gap: 12px; padding: 13px 17px; border-bottom: 1px solid var(--line-soft); font-size: 12px; }
.table-row:hover { background: rgba(255, 255, 255, .018); }
.table-row strong { display: block; font-size: 13px; }
.table-row small { color: var(--muted); }
.status-pill { display: inline-flex; align-items: center; min-height: 23px; padding: 3px 8px; border-radius: 999px; background: #262a32; color: #d4d8de; font-size: 10px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; }
.status-active, .product-generating { background: #562520; color: #ff9c95; }
.status-completed, .product-ready { background: #153a2c; color: #7de2ae; }
.status-failed, .status-corrupt, .status-missing, .product-failed { background: #4b1d1a; color: #ff817a; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 15px; margin-bottom: 16px; }
.live-grid, .card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(370px, 1fr)); gap: 14px; }
.live-card { border-top: 3px solid var(--red); }
.live-card-body { padding: 16px; }
.live-card-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.health-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.health-cell { padding: 10px; border: 1px solid var(--line-soft); border-radius: 8px; background: #0d0f13; }
.health-cell strong, .health-cell span { display: block; }
.health-cell span { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.source-health { display: grid; gap: 8px; margin-top: 14px; }
.health-row { display: grid; grid-template-columns: 1fr repeat(3, 90px); align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line-soft); border-radius: 8px; background: #101216; font-size: 11px; }
.bookmark-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 14px; }

.library-layout { display: grid; grid-template-columns: minmax(360px, 440px) minmax(650px, 1fr); gap: 16px; min-height: calc(100vh - 132px); }
.library-list-panel { overflow: hidden; }
.library-tools { display: grid; grid-template-columns: 1fr 130px; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line-soft); }
.recording-list { max-height: calc(100vh - 265px); overflow: auto; }
.recording-item { appearance: none; display: grid; gap: 8px; width: 100%; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--line-soft); background: transparent; color: inherit; text-align: left; cursor: pointer; }
.recording-item:hover, .recording-item.selected { background: #191c22; }
.recording-item.selected { box-shadow: inset 3px 0 var(--red); }
.recording-title-row, .recording-meta-row, .detail-title-row, .product-row, .profile-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.recording-meta-row { color: var(--muted); font-size: 11px; }
.detail-panel { overflow: auto; max-height: calc(100vh - 132px); }
.empty-state { display: grid; min-height: 600px; place-items: center; align-content: center; padding: 40px; color: var(--muted); text-align: center; }
.empty-state h2 { margin: 12px 0 6px; color: var(--text); }
.empty-state p { max-width: 460px; }
.empty-icon { font-size: 48px; color: var(--red); }
.detail-stack { display: grid; gap: 15px; padding: 17px; }
.detail-title-row { align-items: flex-start; padding-bottom: 14px; border-bottom: 1px solid var(--line-soft); }
.detail-title-row h2 { margin-bottom: 5px; font-size: 23px; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(100px, 1fr)); gap: 8px; }
.summary-metric { padding: 12px; border: 1px solid var(--line-soft); border-radius: 9px; background: #0d0f13; }
.summary-metric strong { display: block; font-size: 21px; }
.summary-metric span { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.detail-section { display: grid; gap: 9px; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; }
.product-list, .analysis-box, .event-list { overflow: hidden; border: 1px solid var(--line-soft); border-radius: 9px; }
.product-row { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.product-row:last-child { border-bottom: 0; }
.product-row small { display: block; margin-top: 3px; color: var(--muted); }
.analysis-box { padding: 13px; background: #0d0f13; }
.analysis-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.analysis-tab { border: 1px solid var(--line); border-radius: 999px; background: #121419; padding: 7px 11px; cursor: pointer; font-size: 11px; }
.analysis-tab.active { border-color: #99322c; background: #3a1715; }
.analysis-panel { display: none; margin-top: 10px; }
.analysis-panel.active { display: block; }
.analysis-list { margin: 0; padding-left: 20px; color: #d1d5dc; }
.analysis-list li { margin: 7px 0; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 10px; }
.media-card { overflow: hidden; border: 1px solid var(--line-soft); border-radius: 9px; background: #090a0d; }
.media-card video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; }
.media-label { padding: 8px 10px; color: #d9dde3; font-size: 12px; font-weight: 700; }
.key-values { display: grid; grid-template-columns: 150px 1fr; gap: 0; }
.key-values dt, .key-values dd { margin: 0; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.key-values dt { color: var(--muted); }

.profile-card, .schedule-card { padding: 16px; }
.profile-card p, .schedule-card p { margin-bottom: 8px; }
.profile-source { min-height: 40px; color: var(--muted); font: 11px ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.card-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 13px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.discovery-strip { margin-bottom: 14px; padding: 13px; border: 1px solid #584321; border-radius: 10px; background: #211a0e; }
.discovery-items { display: flex; gap: 8px; overflow-x: auto; }
.discovered-source { min-width: 280px; padding: 10px; border: 1px solid #684e25; border-radius: 8px; background: #15110a; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(420px, 1fr)); gap: 15px; }
.settings-card:last-child { grid-column: 1 / -1; }
.settings-body { display: grid; gap: 13px; padding: 16px; }
.documentation-view { height: calc(100vh - 88px); padding-top: 16px; }
.documentation-frame { display: block; width: 100%; height: 100%; border: 1px solid var(--line); border-radius: 13px; background: #0d0f13; }
.inline-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; min-height: 46px; padding: 9px 0; }
.switch-row span, .switch-row strong, .switch-row small { display: block; }
.switch-row small { margin-top: 3px; color: var(--muted); font-weight: 500; }
.switch-row input { width: 42px; min-height: 22px; accent-color: var(--red); }
.weekday-picker { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.weekday-picker label { display: grid; place-items: center; gap: 4px; padding: 7px 4px; border: 1px solid var(--line); border-radius: 7px; background: #0d0f13; font-size: 10px; }
.weekday-picker input { width: 16px; min-height: 16px; accent-color: var(--red); }

.modal { max-width: none; border: 0; padding: 0; background: transparent; color: inherit; }
.modal::backdrop { background: rgba(2, 3, 5, .8); backdrop-filter: blur(7px); }
.modal-card { width: min(760px, calc(100vw - 50px)); max-height: calc(100vh - 50px); overflow: auto; border: 1px solid #414650; border-radius: 14px; background: #12151a; box-shadow: 0 35px 90px rgba(0, 0, 0, .6); }
.modal.compact .modal-card { width: 480px; }
.modal-heading { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); background: #15181e; }
.modal-body { padding: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.modal-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 9px; padding: 13px 18px; border-top: 1px solid var(--line); background: #15181e; }
.toast-region { position: fixed; top: 100px; right: 28px; z-index: 100; display: grid; gap: 8px; }
.toast { min-width: 300px; max-width: 460px; padding: 12px 14px; border: 1px solid #3b424d; border-radius: 9px; background: #171a20; box-shadow: 0 14px 40px rgba(0, 0, 0, .5); }
.toast.error { border-color: #7d2a25; background: #2a1413; }

@media (max-width: 1300px) {
  body { min-width: 1024px; }
  .app-frame { grid-template-columns: 220px minmax(0, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .activity-panel { max-height: 420px; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .library-layout { grid-template-columns: 360px minmax(0, 1fr); }
}

@media (max-width: 1024px) {
  body { min-width: 760px; }
  .app-frame { grid-template-columns: 78px minmax(0, 1fr); }
  .brand { justify-content: center; padding: 12px; }
  .brand div, .nav-item > span:not(.nav-icon), .sidebar-foot { display: none; }
  .nav-item { grid-template-columns: 1fr; justify-items: center; padding: 0; }
  .nav-icon { font-size: 21px; }
  .workspace { padding-right: 18px; padding-left: 18px; }
}
