:root {
  --bg: var(--spo-bg, #070c12);
  --surface: var(--spo-surface, #0d151d);
  --surface-raised: var(--spo-surface-raised, #111d27);
  --border: var(--spo-border, #28404d);
  --border-strong: var(--spo-border-strong, #3b6270);
  --text: var(--spo-text, #f4f8fb);
  --muted: var(--spo-muted, #9babb7);
  --accent: var(--spo-primary, #62c9ca);
  --success: var(--spo-success, #46c98b);
  --amber: var(--spo-amber, #f0b44c);
  --danger: var(--spo-danger, #f06d78);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1, h2, h3, p, dl, dd { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #081119;
  color: var(--text);
  padding: 0 12px;
}
textarea { min-height: 88px; padding: 10px 12px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #718290; }
[hidden] { display: none !important; }

.portal-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  grid-template-rows: 72px minmax(0, 1fr);
}
.portal-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  grid-column: 1 / -1;
  height: 72px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: #091018;
}
.portal-brand { display: flex; align-items: center; gap: 13px; min-width: 0; text-decoration: none; }
.portal-brand img { width: 86px; height: 42px; object-fit: contain; object-position: left center; }
.portal-brand span { display: grid; gap: 2px; min-width: 0; }
.portal-brand strong { font-size: 16px; white-space: nowrap; }
.portal-brand small { color: var(--muted); font-size: 11px; }
.portal-account { position: relative; margin-left: auto; display: flex; align-items: center; gap: 12px; }
.service-expiry { color: var(--success); font-size: 12px; white-space: nowrap; }
.account-menu-button {
  max-width: 260px;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
.account-menu-button span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  width: 168px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0b141d;
  box-shadow: 0 14px 30px rgba(0, 0, 0, .3);
}
.account-menu-popover a, .account-menu-popover button {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  text-align: left;
  text-decoration: none;
}
.account-menu-popover a:hover, .account-menu-popover button:hover { background: var(--surface-raised); color: var(--accent); }
.mobile-nav-button { display: none; border: 0; background: transparent; color: var(--text); font-size: 22px; }

.portal-sidebar {
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  border-right: 1px solid var(--border);
  background: #09121a;
}
.portal-sidebar nav { display: grid; gap: 4px; }
.portal-sidebar nav a {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-left: 3px solid transparent;
  border-radius: 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}
.portal-sidebar nav a:hover { color: var(--text); background: var(--surface); }
.portal-sidebar nav a[aria-current="page"] { border-left-color: var(--accent); background: #10222a; color: var(--accent); font-weight: 750; }
.sidebar-footer { margin-top: auto; padding: 16px 12px 4px; border-top: 1px solid var(--border); display: grid; gap: 4px; }
.sidebar-footer span { color: var(--accent); font-size: 12px; }
.sidebar-footer small { color: var(--muted); }

.portal-main { min-width: 0; padding: 30px clamp(20px, 3vw, 44px) 50px; }
.portal-auth-error { max-width: 560px; margin: 80px auto; padding: 28px; border: 1px solid var(--danger); border-radius: 8px; background: var(--surface); }
.portal-auth-error p { margin: 10px 0 20px; color: var(--muted); }
.page-header { min-height: 72px; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.page-header h1 { margin-top: 5px; font-size: clamp(26px, 3vw, 36px); line-height: 1.2; }
.page-header p { margin-top: 8px; color: var(--muted); line-height: 1.6; }
.eyebrow { color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .14em; }
.back-link { display: inline-block; margin-bottom: 8px; color: var(--accent); text-decoration: none; font-size: 13px; }
.header-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.header-actions a, .quick-actions a, .primary-link {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}
.header-actions a:hover, .quick-actions a:hover { border-color: var(--accent); color: var(--accent); }
.primary-link { border-color: var(--accent); background: var(--accent); color: #041113; font-weight: 800; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-grid > a, .stat-grid > div {
  min-height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
  border: 1px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  text-decoration: none;
}
.stat-grid > a:nth-child(2), .stat-grid > div:nth-child(2) { border-top-color: var(--success); }
.stat-grid > a:nth-child(3), .stat-grid > div:nth-child(3) { border-top-color: var(--amber); }
.stat-grid > a:nth-child(4), .stat-grid > div:nth-child(4) { border-top-color: #73a6ff; }
.stat-grid span { color: var(--muted); font-size: 13px; }
.stat-grid strong { font-size: 30px; }
.compact-stats { grid-template-columns: repeat(4, minmax(0, 180px)); }
.compact-stats > div { min-height: 94px; }
.compact-stats strong { font-size: 24px; }
.service-panel {
  min-height: 104px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
  padding: 20px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: 6px;
  background: var(--surface);
}
.service-panel h2 { margin-top: 4px; font-size: 18px; }
.service-panel p { margin-top: 6px; color: var(--muted); }
.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 26px; }

.data-section { border: 1px solid var(--border); border-radius: 6px; background: var(--surface); overflow: hidden; }
.section-title { min-height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.section-title h2 { margin-top: 3px; font-size: 17px; }
.section-title a, .section-title button { border: 0; background: transparent; color: var(--accent); text-decoration: none; }
.task-list { display: grid; }
.task-row { min-height: 58px; display: grid; grid-template-columns: minmax(140px, 1.4fr) 120px 170px 100px; align-items: center; gap: 16px; padding: 10px 18px; border-bottom: 1px solid var(--border); text-decoration: none; }
.task-row:last-child { border-bottom: 0; }
.task-row:hover { background: var(--surface-raised); }
.task-row span, .task-row time { color: var(--muted); font-size: 12px; }
.empty-copy { padding: 30px 18px; color: var(--muted); text-align: center; line-height: 1.6; }
.error-copy { color: var(--danger) !important; }
.status-badge { display: inline-flex; align-items: center; width: max-content; padding: 4px 8px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.status-active, .status-completed { border-color: rgba(70, 201, 139, .5); color: var(--success) !important; }
.status-failed, .status-cancelled, .status-timed_out, .status-disabled { border-color: rgba(240, 109, 120, .5); color: var(--danger) !important; }
.status-processing, .status-downloading, .status-uploading_result, .status-claimed { border-color: rgba(98, 201, 202, .5); color: var(--accent) !important; }
.status-queued, .status-retry_wait { border-color: rgba(240, 180, 76, .5); color: var(--amber) !important; }

.filter-bar { display: grid; grid-template-columns: minmax(220px, 1fr) 180px auto; gap: 10px; margin-bottom: 16px; }
.filter-bar button, .pagination button, .row-actions button, .row-actions a { min-height: 38px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); padding: 0 13px; text-decoration: none; }
.filter-bar button:hover, .pagination button:hover, .row-actions button:hover, .row-actions a:hover { border-color: var(--accent); color: var(--accent); }
.report-filters { grid-template-columns: minmax(150px, 1fr) 150px 150px 150px 150px auto; }
.source-notice { margin: 0 0 16px; padding: 12px 14px; border-left: 3px solid var(--amber); background: #211b0e; color: #f3d49b; font-size: 13px; }
.data-section > .source-notice { margin: 18px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 950px; border-collapse: collapse; }
th, td { height: 54px; padding: 9px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; font-size: 13px; }
th { height: 46px; color: var(--muted); background: #0a131b; font-size: 11px; font-weight: 700; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-raised); }
td > a { color: var(--text); text-decoration: none; font-weight: 700; }
.row-actions { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.row-actions button, .row-actions a { min-height: 30px; padding: 0 8px; font-size: 11px; font-weight: 500; }
.row-actions .danger-action { color: var(--danger); }

.primary-button { width: 100%; min-height: 44px; margin-top: 18px; border: 1px solid var(--accent); border-radius: 6px; background: var(--accent); color: #041113; font-weight: 850; }
.primary-button:hover { background: #78d9d7; }
.compact-button { width: auto; min-width: 116px; min-height: 40px; margin: 0; padding: 0 16px; }
.form-dialog { width: min(620px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); }
.form-dialog::backdrop { background: rgba(2, 6, 10, .78); }
.form-dialog form { display: grid; gap: 14px; padding: 20px; }
.form-dialog label, .settings-form label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; }
.dialog-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.dialog-title h2 { font-size: 20px; }
.dialog-title button { width: 34px; height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 24px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-message, .field-help { color: var(--muted); font-size: 12px; line-height: 1.5; }
.profile-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.profile-grid > div { min-height: 88px; padding: 16px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.profile-grid span { display: block; color: var(--muted); font-size: 12px; }
.profile-grid strong { display: block; margin-top: 8px; }

.workflow-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 18px; align-items: start; }
.workflow-controls { min-width: 0; padding: 18px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.field-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.field-help { margin: 7px 0 17px; }
.dropzone { min-height: 154px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 15px; border: 1px dashed var(--border-strong); border-radius: 6px; background: #0c1822; cursor: pointer; text-align: center; }
.dropzone:hover { border-color: var(--accent); }
.dropzone input { display: none; }
.dropzone span:last-child { max-width: 280px; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.compact-dropzone { min-height: 116px; margin-bottom: 10px; }
.upload-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: #143040; color: var(--accent); font-size: 24px; }
.recording-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 9px; }
.recording-controls button { min-height: 40px; border: 1px solid var(--border); border-radius: 6px; background: #0a141d; color: var(--text); }
.camera-preview { width: 100%; margin-top: 10px; border: 1px solid var(--border); border-radius: 6px; background: #000; }
.panel-section { margin-top: 20px; }
.panel-section h2, .event-log h2 { margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.joint-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.joint-grid label { min-height: 40px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; background: #0a141d; font-size: 12px; }
.joint-grid input { width: auto; min-height: 0; accent-color: var(--accent); }
.progress-card, .event-log { margin-top: 16px; padding: 14px; border: 1px solid var(--border); border-radius: 6px; background: #0a141d; }
.progress-copy { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.progress-copy strong { color: var(--accent); }
.progress-track { height: 6px; margin: 11px 0; overflow: hidden; border-radius: 999px; background: #20303e; }
#progressBar { width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .3s ease; }
#jobMessage { color: var(--muted); font-size: 12px; line-height: 1.5; }
.event-log ol { margin: 0; padding-left: 20px; color: var(--muted); font-size: 12px; line-height: 1.8; }

.result-workspace { min-width: 0; }
.empty-state { min-height: 590px; display: grid; place-content: center; justify-items: center; padding: 32px; border: 1px solid var(--border); border-radius: 6px; background: #090f16; text-align: center; }
.empty-state h2 { margin-top: 22px; font-size: 22px; }
.empty-state p { max-width: 560px; margin-top: 10px; color: var(--muted); line-height: 1.7; }
.empty-visual { position: relative; width: 132px; height: 132px; border: 1px solid var(--border); display: grid; place-items: center; background-color: #071019; background-image: linear-gradient(rgba(98, 201, 202, .08) 1px, transparent 1px), linear-gradient(90deg, rgba(98, 201, 202, .08) 1px, transparent 1px); background-size: 26px 26px; }
.empty-visual span { position: absolute; width: 8px; height: 8px; background: var(--accent); }
.empty-visual span:nth-child(1) { transform: translate(-26px, -18px); }
.empty-visual span:nth-child(2) { transform: translate(31px, 5px); }
.empty-visual span:nth-child(3) { transform: translate(-4px, 36px); }
.result-layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(270px, .65fr); gap: 14px; }
.video-card, .angle-panel, .metadata-panel, .metrics { border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.card-header { min-height: 60px; padding: 13px 16px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--border); }
.card-header h2 { margin-top: 3px; font-size: 17px; }
.card-header.compact { min-height: 48px; padding: 10px 12px; }
.card-header.compact h2 { font-size: 14px; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.download-link, .card-header button, .player-toolbar button, .player-toolbar select { min-height: 32px; padding: 0 9px; border: 1px solid var(--border); border-radius: 5px; background: #09131c; color: var(--accent); text-decoration: none; font-size: 11px; }
.video-stage { position: relative; min-height: 440px; display: grid; place-items: center; overflow: hidden; background: #020406; }
.video-stage video { display: block; width: 100%; max-height: 68vh; object-fit: contain; }
.video-stage canvas { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.video-stage.skeleton-only video { opacity: 0; }
.video-stage.original-only canvas { opacity: 0; }
.player-toolbar { display: grid; grid-template-columns: auto minmax(100px, 1fr) auto auto auto; align-items: center; gap: 7px; padding: 10px; border-top: 1px solid var(--border); }
.player-toolbar input[type="range"] { width: 100%; min-height: 22px; padding: 0; accent-color: var(--accent); }
.inspector { display: grid; align-content: start; gap: 12px; }
.metrics { padding: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.metrics div, .angle-list div { padding: 9px; border: 1px solid #213544; border-radius: 5px; background: #09131c; }
.metrics span, .angle-list span { display: block; color: var(--muted); font-size: 10px; }
.metrics strong, .angle-list strong { display: block; margin-top: 4px; font-size: 15px; }
.angle-list { padding: 9px; display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.angle-list strong { color: var(--success); }
#frameLabel { color: var(--muted); font-size: 11px; }
.metadata-panel pre { max-height: 260px; margin: 0; padding: 12px; overflow: auto; color: #bee9e7; font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }

.report-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 16px; align-items: start; }
.history-list { display: grid; }
.history-item { width: 100%; min-height: 74px; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--text); text-align: left; }
.history-item:hover { background: var(--surface-raised); }
.history-item span { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.pagination { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 9px; padding: 12px; border-top: 1px solid var(--border); }
.pagination span { color: var(--muted); font-size: 11px; white-space: nowrap; }
.report-progress { display: none; }
.settings-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, .7fr); gap: 16px; align-items: start; }
.detail-list { display: grid; padding: 5px 18px; }
.detail-list > div { min-height: 52px; display: grid; grid-template-columns: 120px minmax(0, 1fr); align-items: center; gap: 20px; border-bottom: 1px solid var(--border); }
.detail-list > div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-size: 12px; }
.detail-list dd { font-weight: 700; }
.settings-form { display: grid; gap: 14px; padding: 18px; }
.settings-form .primary-button { max-width: 180px; }

@media (max-width: 1180px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compact-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .workflow-layout, .report-layout { grid-template-columns: 310px minmax(0, 1fr); }
  .result-layout { grid-template-columns: 1fr; }
  .report-filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .portal-shell { grid-template-columns: 1fr; }
  .portal-topbar { padding: 0 16px; }
  .mobile-nav-button { display: block; }
  .portal-sidebar { position: fixed; top: 72px; left: 0; z-index: 25; width: 228px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 18px 0 30px rgba(0, 0, 0, .35); }
  .portal-sidebar.open { transform: translateX(0); }
  .portal-main { grid-column: 1; }
  .workflow-layout, .report-layout, .settings-layout { grid-template-columns: 1fr; }
  .empty-state { min-height: 380px; }
  .profile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .portal-topbar { height: 64px; gap: 10px; }
  .portal-brand img { width: 62px; }
  .portal-brand strong { font-size: 13px; }
  .portal-brand small, .service-expiry { display: none; }
  .account-menu-button { max-width: 120px; padding: 0 8px; font-size: 12px; }
  .portal-sidebar { top: 64px; height: calc(100vh - 64px); }
  .portal-main { padding: 22px 14px 36px; }
  .page-header { display: grid; margin-bottom: 20px; }
  .page-header h1 { font-size: 26px; }
  .header-actions { width: 100%; display: grid; grid-template-columns: 1fr; }
  .stat-grid, .compact-stats { grid-template-columns: 1fr 1fr; }
  .stat-grid > a, .stat-grid > div { min-height: 90px; padding: 14px; }
  .stat-grid strong { font-size: 24px; }
  .filter-bar, .report-filters { grid-template-columns: 1fr; }
  .form-grid, .profile-grid, .joint-grid { grid-template-columns: 1fr; }
  .task-row { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; }
  .task-row time { grid-column: 1; }
  .task-row .status-badge { grid-column: 2; grid-row: 1; }
  .player-toolbar { grid-template-columns: 1fr 1fr; }
  .player-toolbar input[type="range"] { grid-column: 1 / -1; }
  .video-stage { min-height: 250px; }
  .detail-list > div { grid-template-columns: 1fr; gap: 4px; padding: 10px 0; }
}
