:root {
  --bg: #f4f5f6;
  --surface: #fff;
  --ink: #17191c;
  --muted: #687078;
  --line: #dfe3e6;
  --accent: #e64f3c;
  --teal: #167d78;
  --gold: #d99a17;
  --danger: #b42318;
  --sidebar: #1b1e20;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button { background: var(--accent); border: 1px solid var(--accent); border-radius: 6px; color: #fff; cursor: pointer; font-weight: 700; min-height: 38px; padding: 8px 13px; }
button:hover { filter: brightness(.96); }
button:disabled { cursor: not-allowed; opacity: .45; }
button.secondary { background: #fff; border-color: var(--line); color: var(--ink); }
button.danger { background: #fff; border-color: #efb1aa; color: var(--danger); }
button.iconButton { background: transparent; border-color: #555b5e; color: inherit; min-height: 32px; padding: 5px 9px; }
input, select, textarea { background: #fff; border: 1px solid #cbd1d5; border-radius: 5px; color: var(--ink); min-height: 40px; padding: 9px 10px; width: 100%; }
textarea { min-height: 92px; resize: vertical; }
label { color: #4f575e; display: block; font-size: 12px; font-weight: 700; margin: 0 0 6px; }
h1, h2, p { margin-top: 0; }
h1 { font-size: 26px; margin-bottom: 7px; }
h2 { font-size: 16px; margin-bottom: 8px; }
.subtle { color: var(--muted); font-size: 14px; margin-bottom: 0; }
.kicker { color: var(--teal); font-size: 11px; font-weight: 800; margin-bottom: 5px; text-transform: uppercase; }

.topbar { align-items: center; background: #111315; color: #fff; display: flex; height: 58px; justify-content: space-between; padding: 0 20px; }
.brand { color: #fff; font-size: 21px; font-weight: 800; text-decoration: none; }
.topbarMeta { align-items: center; display: flex; font-size: 12px; gap: 14px; }
.apiState { color: #e5b853; }
.apiState.ok { color: #83d9b2; }
.apiState.error { color: #ff9f94; }

.shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: calc(100vh - 58px); min-width: 0; width: 100%; }
.sidebar { background: var(--sidebar); color: #dce0e2; display: flex; flex-direction: column; min-width: 0; padding: 20px 12px; }
.sidebarTitle { color: #858d92; font-size: 11px; font-weight: 800; margin: 0 10px 10px; text-transform: uppercase; }
#resourceNav { display: grid; gap: 2px; min-width: 0; max-width: 100%; }
.navButton { background: transparent; border: 0; color: #dce0e2; display: flex; font-weight: 600; justify-content: space-between; min-height: 38px; padding: 9px 10px; text-align: left; width: 100%; }
.navButton:hover, .navButton.active { background: #303538; filter: none; }
.navCount { color: #9fa6aa; font-size: 11px; }
.sidebarLinks { border-top: 1px solid #34393c; display: grid; gap: 9px; margin-top: auto; padding: 18px 10px 0; }
.sidebarLinks a { color: #b9c0c4; font-size: 12px; text-decoration: none; }

.workspace, #adminView, #resourceView { max-width: 100%; min-width: 0; }
.workspace { padding: 28px 32px 48px; }
.loginView { align-items: center; display: flex; justify-content: center; min-height: 70vh; }
.loginBox { background: #fff; border: 1px solid var(--line); border-radius: 8px; max-width: 420px; padding: 28px; width: 100%; }
.loginBox label { margin-top: 18px; }
.loginBox button { margin-top: 20px; width: 100%; }
.formMessage { color: var(--danger); font-size: 13px; margin: 12px 0 0; min-height: 18px; }
.pageHeader { align-items: flex-start; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; margin-bottom: 22px; padding-bottom: 20px; }
.headerActions { display: flex; gap: 8px; }

.metrics { display: grid; gap: 1px; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--line); border: 1px solid var(--line); }
.metric { background: #fff; min-height: 105px; padding: 18px; }
.metric strong { display: block; font-size: 27px; margin-bottom: 7px; }
.metric span { color: var(--muted); font-size: 12px; }
.overviewBands { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; margin-top: 18px; }
.surface { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 18px; }
.surface p { color: var(--muted); font-size: 13px; line-height: 1.55; margin-bottom: 0; }
.warningSurface { border-left: 4px solid var(--gold); }

.toolbar { align-items: end; display: grid; gap: 12px; grid-template-columns: minmax(240px, 480px) 90px; margin-bottom: 12px; }
.tableStatus { color: var(--muted); font-size: 12px; margin: 8px 0; min-height: 18px; }
.tableWrap { background: #fff; border: 1px solid var(--line); overflow-x: auto; }
table { border-collapse: collapse; font-size: 13px; width: 100%; }
th, td { border-bottom: 1px solid var(--line); padding: 10px 11px; text-align: left; vertical-align: middle; }
th { background: #f8f9fa; color: #596168; font-size: 11px; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
td code { background: #f0f2f3; border-radius: 3px; font-size: 11px; padding: 2px 4px; }
.rowActions { display: flex; gap: 5px; justify-content: flex-end; white-space: nowrap; }
.rowActions button { min-height: 30px; padding: 4px 8px; }
.cellMain { font-weight: 700; }
.cellSub { color: var(--muted); display: block; font-size: 11px; margin-top: 3px; }
.pill { border-radius: 999px; display: inline-block; font-size: 10px; font-weight: 800; padding: 3px 7px; }
.pill.good { background: #dff4e9; color: #116941; }
.pill.warn { background: #fff0c7; color: #795600; }
.pill.bad { background: #fde3df; color: #a5291d; }
.pagination { align-items: center; display: flex; gap: 12px; justify-content: flex-end; margin-top: 12px; }
.pagination button { min-width: 90px; }
.pagination span { color: var(--muted); font-size: 12px; }
.emptyState { color: var(--muted); padding: 35px; text-align: center; }

.drawerBackdrop { background: rgba(17, 19, 21, .38); inset: 0; position: fixed; z-index: 10; }
.drawer { background: #fff; bottom: 0; box-shadow: -14px 0 30px rgba(0,0,0,.15); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; max-width: 680px; position: fixed; right: 0; top: 0; width: min(680px, 94vw); z-index: 11; }
.drawerHeader { align-items: center; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; padding: 18px 20px; }
.drawerHeader h2 { font-size: 20px; margin: 0; }
.drawerBody { overflow-y: auto; padding: 18px 20px 30px; }
.drawerTabs { border-bottom: 1px solid var(--line); display: flex; gap: 4px; margin-bottom: 18px; }
.drawerTab { background: transparent; border: 0; border-bottom: 3px solid transparent; border-radius: 0; color: var(--muted); }
.drawerTab.active { border-bottom-color: var(--teal); color: var(--ink); }
#recordForm { display: grid; gap: 14px 16px; grid-template-columns: 1fr 1fr; }
.field.full { grid-column: 1 / -1; }
.fieldHelp { color: var(--muted); font-size: 11px; margin: 5px 0 0; }
.adminVideoPreview { background: #111; border-radius: 6px; display: block; margin-top: 10px; max-height: 280px; width: 100%; }
#recordJson { background: #151719; border-radius: 5px; color: #d5eee2; font-size: 12px; margin: 0; min-height: 300px; overflow: auto; padding: 14px; white-space: pre-wrap; }
.drawerFooter { border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; }
.drawerFooter .danger { margin-right: auto; }
.toast { background: #17191c; border-radius: 5px; bottom: 22px; color: #fff; font-size: 13px; left: 50%; padding: 11px 16px; position: fixed; transform: translateX(-50%); z-index: 20; }
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { max-width: 100%; overflow: hidden; padding: 10px; position: static; width: 100%; }
  #resourceNav { display: flex; overflow-x: auto; width: 100%; }
  .navButton { white-space: nowrap; width: auto; }
  .sidebarLinks, .sidebarTitle { display: none; }
  .workspace { padding: 20px 14px 40px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .topbarMeta #sessionName { display: none; }
  .pageHeader { gap: 16px; }
  .headerActions { flex-direction: column; }
  .metrics, .overviewBands, #recordForm, .toolbar { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .drawerFooter { flex-wrap: wrap; }
}
