:root {
  --bg: #090d14;
  --panel: #111823;
  --panel-soft: #0d141e;
  --line: #27384d;
  --line-soft: #1b2939;
  --ink: #f4f7fb;
  --muted: #93a4b8;
  --gold: #e8c47c;
  --blue: #91bfff;
  --green: #76dea1;
  --red: #ff948d;
  --orange: #efb66d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { min-height: 100dvh; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell { width: min(1500px, 100%); margin: 0 auto; padding: calc(20px + var(--safe-top)) 18px calc(22px + var(--safe-bottom)); }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 16px; }
.brand-block { max-width: 900px; }
.home-link { display: inline-block; margin-bottom: 12px; color: var(--blue); text-decoration: none; font-size: .78rem; font-weight: 800; }
.eyebrow { margin: 0 0 6px; color: var(--gold); font-size: .66rem; font-weight: 900; letter-spacing: .15em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(1.65rem, 3vw, 2.65rem); letter-spacing: -.035em; }
h2 { margin-bottom: 5px; font-size: clamp(1.05rem, 2vw, 1.45rem); }
.subtitle, .muted, .helper { color: var(--muted); line-height: 1.5; }
.subtitle { margin: 0; font-size: .9rem; }
.top-status { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.badge, .source-count, .state-pill { display: inline-flex; align-items: center; min-height: 30px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .63rem; font-weight: 900; letter-spacing: .07em; white-space: nowrap; }
.badge.good, .state-pill.good { border-color: rgba(118,222,161,.55); color: var(--green); }
.badge.warn, .state-pill.warn { border-color: rgba(239,182,109,.55); color: var(--orange); }
.badge.bad, .state-pill.bad { border-color: rgba(255,148,141,.6); color: var(--red); }

.workflow-strip { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 1px; margin-bottom: 14px; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--line); }
.workflow-strip > div { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; padding: 13px 14px; background: var(--panel-soft); }
.workflow-strip > div > span { grid-row: 1 / 3; display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid rgba(232,196,124,.6); border-radius: 50%; color: var(--gold); font-size: .72rem; font-weight: 900; }
.workflow-strip strong { align-self: end; font-size: .78rem; }
.workflow-strip small { color: var(--muted); font-size: .66rem; line-height: 1.35; }

.panel { padding: 15px; border: 1px solid var(--line); border-radius: 16px; background: linear-gradient(145deg, rgba(19,27,39,.98), rgba(12,18,27,.98)); box-shadow: 0 18px 50px rgba(0,0,0,.18); }
.session-panel { display: grid; grid-template-columns: 1fr auto; gap: 14px 18px; margin-bottom: 16px; }
.session-copy label { display: block; margin-bottom: 7px; font-size: .8rem; font-weight: 850; }
.session-copy input { width: 100%; min-height: 44px; padding: 0 13px; border: 1px solid #30445f; border-radius: 10px; outline: none; background: #080e16; color: var(--ink); }
.session-copy input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(145,191,255,.12); }
.helper { margin: 7px 0 0; font-size: .68rem; }
.session-actions { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.session-meter { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 16px; padding: 10px 12px; border: 1px solid var(--line-soft); border-radius: 10px; background: rgba(5,11,18,.55); color: var(--muted); font-size: .72rem; }
.session-meter strong { color: var(--ink); }

.button { min-height: 42px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: #111a27; color: var(--ink); cursor: pointer; font-size: .7rem; font-weight: 900; letter-spacing: .035em; transition: transform .15s ease, border-color .15s ease, background .15s ease; }
.button:hover:not(:disabled) { border-color: var(--gold); background: #182438; }
.button:active:not(:disabled) { transform: translateY(1px); }
.button.primary { border-color: var(--gold); background: var(--gold); color: #101318; }
.button.primary:hover:not(:disabled) { background: #f0d28f; }
.button.danger { border-color: rgba(255,148,141,.65); color: var(--red); }
.button.ghost { color: var(--muted); }
.button.small { min-height: 36px; padding: 0 11px; font-size: .66rem; }
.button:disabled { opacity: .38; cursor: not-allowed; }
.button:focus-visible, .preview:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.windows-section { margin: 0 0 16px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-heading .muted { max-width: 900px; margin: 0; font-size: .76rem; }
.section-heading.compact { align-items: center; margin-bottom: 8px; }
.window-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.window-card { min-width: 0; padding: 10px; border: 1px solid var(--line); border-radius: 15px; background: linear-gradient(145deg, rgba(17,24,35,.98), rgba(9,14,22,.98)); box-shadow: 0 14px 38px rgba(0,0,0,.18); }
.window-card.live { border-color: rgba(118,222,161,.42); }
.window-card.marked { box-shadow: 0 0 0 1px rgba(232,196,124,.5), 0 14px 38px rgba(0,0,0,.2); }
.window-head, .window-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.window-head { margin-bottom: 8px; }
.window-head > div { display: grid; gap: 2px; }
.window-head strong { font-size: .8rem; }
.window-number { color: var(--gold); font-size: .58rem; font-weight: 900; letter-spacing: .12em; }
.window-foot { margin-top: 8px; color: var(--muted); font-size: .63rem; }
.window-foot strong { color: var(--gold); }
.preview { position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden; border: 1px solid #2d415a; border-radius: 11px; background: #02050a; cursor: crosshair; }
.preview video { width: 100%; height: 100%; object-fit: contain; background: #02050a; display: block; }
.placeholder { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 6px; padding: 16px; text-align: center; color: var(--muted); }
.placeholder > span { display: grid; place-items: center; width: 48px; height: 48px; border: 1px solid rgba(232,196,124,.5); border-radius: 50%; color: var(--gold); font-size: .74rem; font-weight: 900; }
.placeholder strong { color: var(--ink); font-size: .73rem; }
.placeholder small { font-size: .63rem; }
.preview-label { position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 5px 8px; border: 1px solid rgba(45,65,90,.9); border-radius: 999px; background: rgba(2,7,12,.82); color: var(--muted); font-size: .59rem; font-weight: 800; }
.marker-flash { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(232,196,124,.16); color: #fff4d6; font-size: clamp(1rem, 4vw, 2rem); font-weight: 950; letter-spacing: .08em; opacity: 0; pointer-events: none; transition: opacity .14s ease; }
.marker-flash.show { opacity: 1; }
.window-actions { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 7px; margin-top: 8px; }

.evidence-panel, .activity-panel { margin-top: 14px; }
.gallery-tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.empty-gallery { display: grid; place-items: center; gap: 5px; min-height: 125px; border: 1px dashed #344c67; border-radius: 11px; color: var(--muted); text-align: center; font-size: .72rem; }
.empty-gallery strong { color: var(--ink); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.gallery-item { padding: 9px; border: 1px solid #30445f; border-radius: 11px; background: rgba(6,12,20,.62); }
.gallery-item.selected { border-color: var(--blue); box-shadow: 0 0 0 1px rgba(145,191,255,.15); }
.gallery-thumb { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; border: 1px solid #24364c; background: #02050a; }
.gallery-meta { display: grid; gap: 3px; margin-top: 8px; }
.gallery-meta strong { font-size: .76rem; }
.gallery-meta span { color: var(--muted); font-size: .64rem; line-height: 1.35; }
.gallery-actions { display: flex; gap: 7px; margin-top: 8px; }
.gallery-actions .button { flex: 1; }
.activity-log { max-height: 180px; overflow: auto; padding: 3px 2px 0; color: var(--muted); font-size: .68rem; line-height: 1.45; }
.activity-log p { margin: 5px 0; }
.activity-log strong { color: var(--gold); }
.boundary-card { margin-top: 14px; padding: 12px 14px; border: 1px solid rgba(239,182,109,.38); border-radius: 12px; background: rgba(49,36,16,.15); }
.boundary-card strong { color: var(--orange); font-size: .74rem; }
.boundary-card p { margin: 5px 0 0; color: var(--muted); font-size: .68rem; line-height: 1.5; }
footer { padding-top: 15px; color: var(--muted); font-size: .64rem; text-align: center; }

.focus-backdrop { position: fixed; inset: 0; z-index: 50; padding: 12px; background: rgba(2,5,9,.94); }
.focus-backdrop[hidden] { display: none; }
.focus-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; height: 48px; }
.focus-stage { height: calc(100dvh - 72px); }
.focus-stage .window-card { height: 100%; display: grid; grid-template-rows: auto 1fr auto auto; }
.focus-stage .preview { aspect-ratio: auto; min-height: 0; height: 100%; }

@media (max-width: 920px) {
  .workflow-strip { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .session-panel { grid-template-columns: 1fr; }
  .session-actions { justify-content: flex-start; }
}

@media (max-width: 720px) {
  .app-shell { padding-left: 11px; padding-right: 11px; }
  .topbar, .section-heading { flex-direction: column; }
  .top-status, .gallery-tools { justify-content: flex-start; }
  .window-grid { grid-template-columns: 1fr; }
  .session-meter { flex-direction: column; gap: 3px; }
}

@media (max-width: 470px) {
  .workflow-strip { grid-template-columns: 1fr; }
  .session-actions { display: grid; grid-template-columns: 1fr; }
  .button { width: 100%; }
}
