/* Digital Bridge RDC — Compare. Tokens follow Digital_Bridge_RDC_Web_App_Specification.md §9. */

:root {
  /* SOURCE: exact values from DIGITAL BRIDGE RDC THEME.md */
  --color-primary-accent: #41B6E6;
  --color-secondary-brand: #2E294E;
  --color-surface-white: #FFFFFF;
  --color-surface-subtle: #F8FAFC;
  --color-border-ui: #E2E8F0;
  --color-text-headers: #2E294E;
  --color-text-main: #0F172A;
  --color-text-secondary: #334155;
  --color-text-on-accent: #FFFFFF;
  --spacing-unit: 1rem;
  --border-radius-ui: 14px;
  --shadow-subtle: 0 8px 24px rgba(15, 23, 42, 0.08);

  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Space Grotesk', 'Poppins', sans-serif;
  --container-max: 1120px;
  --gutter: 24px;
  --action-hover: #2FA8D7;
  --icon-stroke-width: 1.5px;
  --logo-plate: #FFFFFF;
}

:root, :root[data-theme="light"] {
  color-scheme: light;
  --page: var(--color-surface-white);
  --surface: var(--color-surface-white);
  --surface-subtle: var(--color-surface-subtle);
  --border: var(--color-border-ui);
  --heading: var(--color-text-headers);
  --text: var(--color-text-main);
  --text-muted: var(--color-text-secondary);
  --action: var(--color-primary-accent);
  --icon: var(--color-secondary-brand);
  --card-shadow: var(--shadow-subtle);
  /* PROPOSED light accessibility extensions (spec §4) */
  --action-text: #2E294E;
  --action-border: #2E294E;
  --control-border: #64748B;
  --link: #2E294E;
  --highlight-text: #2E294E;
  --focus: #2E294E;
  --stage-bg: #0B1220;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0B1220;
  --surface: #111C2E;
  --surface-subtle: #18263D;
  --border: #334155;
  --control-border: #94A3B8;
  --heading: #F8FAFC;
  --text: #F1F5F9;
  --text-muted: #CBD5E1;
  --action: #41B6E6;
  --action-hover: #2FA8D7;
  --action-text: #2E294E;
  --action-border: #41B6E6;
  --link: #41B6E6;
  --highlight-text: #41B6E6;
  --icon: #CBD5E1;
  --focus: #F8FAFC;
  --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  --logo-plate: #FFFFFF;
  --stage-bg: #060B14;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}

h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--heading);
  margin: 0 0 var(--spacing-unit);
  letter-spacing: -0.02em;
}
h1 { font-size: 3rem; line-height: 1.1; }
h2 { font-size: 2.25rem; line-height: 1.2; }
h3 { font-size: 1.5rem; line-height: 1.3; }
.step-title { font-size: 1.5rem; line-height: 1.3; display: flex; align-items: center; gap: .65rem; }
p { color: var(--text); font-weight: 400; max-width: 75ch; margin: 0 0 var(--spacing-unit); }

.caption-tech { font-size: .85rem; color: var(--text-muted); font-weight: 500; margin: 0; }
.text-highlight {
  color: var(--highlight-text); font-weight: 600; text-transform: uppercase;
  font-size: .875rem; letter-spacing: .05em; display: block; margin-bottom: .5rem;
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.sr-only-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }

[hidden] { display: none !important; }

.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--icon); stroke-width: var(--icon-stroke-width); stroke-linecap: round; stroke-linejoin: round; }
.icon-lg { width: 32px; height: 32px; }

/* ---------- Layout ---------- */
.container, .container-minimal { max-width: var(--container-max); margin: 0 auto; padding: 0 var(--gutter); }

.skip-link {
  position: absolute; left: 8px; top: -80px; z-index: 100; background: var(--action); color: var(--action-text);
  padding: .75rem 1rem; border-radius: var(--border-radius-ui); border: 2px solid var(--action-border); font-weight: 600;
}
.skip-link:focus { top: 8px; }

/* ---------- Header ---------- */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 24px; padding-top: 14px; padding-bottom: 14px; }
.brand-block { display: flex; align-items: center; gap: 16px; min-width: 0; }
.brand { display: block; background: var(--logo-plate); padding: 8px; border-radius: 12px; line-height: 0; flex: none; }
.brand-logo { display: block; width: min(100%, 120px); height: auto; object-fit: contain; }
.brand-text { min-width: 0; }
.app-name { font-family: var(--font-heading); font-weight: 700; font-size: 1.35rem; line-height: 1.2; color: var(--heading); margin: 0; letter-spacing: -0.02em; }
.app-sub { font-size: .85rem; color: var(--text-muted); margin: 0; line-height: 1.4; }
.version-pill { font-size: .8rem; font-weight: 600; color: var(--text-muted); padding: .3rem .75rem; border: 1px solid var(--border); background: var(--surface-subtle); border-radius: 999px; }
.header-utils { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 20px; }

.lang-switch { border: 1px solid var(--control-border); border-radius: var(--border-radius-ui); padding: 3px; margin: 0; display: inline-flex; gap: 2px; min-width: 0; }
.lang-opt { position: relative; display: inline-flex; }
.lang-opt input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.lang-opt span {
  display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 36px;
  padding: 0 .75rem; border-radius: calc(var(--border-radius-ui) - 4px); font-weight: 600; color: var(--text);
}
.lang-opt input:checked + span { background: var(--action); color: var(--action-text); box-shadow: inset 0 0 0 2px var(--action-border); }
.lang-opt input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.theme-switch { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.theme-text { display: flex; flex-direction: column; line-height: 1.2; }
.theme-name { font-weight: 600; color: var(--text); }
.theme-state { font-size: .8rem; color: var(--text-muted); }

.switch {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0; cursor: pointer;
  width: 52px; height: 30px; border-radius: 15px; position: relative;
  border: 2px solid var(--control-border); background: var(--surface-subtle);
  transition: background-color .2s ease;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--color-secondary-brand); transition: transform .2s ease, background-color .2s ease;
}
.switch:checked { background: var(--action); border-color: var(--action-border); }
.switch:checked::after { transform: translateX(22px); background: var(--action-text); }

/* ---------- Hero ---------- */
.hero { background: var(--surface-subtle); text-align: center; padding: 3rem 2rem; border-bottom: 1px solid var(--border); }
.hero p { margin-left: auto; margin-right: auto; color: var(--text-muted); }
.hero h1 { margin-bottom: .75rem; }

/* ---------- Buttons & controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .7rem 1.4rem; min-height: 44px; border-radius: var(--border-radius-ui);
  font: 600 1rem/1.2 var(--font-body); cursor: pointer; text-decoration: none;
  transition: background-color .2s ease, transform .1s ease, opacity .2s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--action); color: var(--action-text); border: 2px solid var(--action-border); box-shadow: 0 4px 6px -1px rgba(65, 182, 230, 0.2); }
.btn-primary:hover { background: var(--action-hover); }
.btn-primary .icon { stroke: var(--action-text); }
.btn-secondary { background: var(--surface); color: var(--heading); border: 1px solid var(--control-border); }
.btn-secondary:hover { background: var(--surface-subtle); }
.btn-icon { padding-left: 1rem; padding-right: 1rem; }
.btn-block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-secondary[aria-pressed="true"] { background: var(--action); color: var(--action-text); border-color: var(--action-border); }
.btn-secondary[aria-pressed="true"] .icon { stroke: var(--action-text); }

.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--link); text-decoration: underline; cursor: pointer; }

label { font-weight: 600; font-size: .95rem; color: var(--text); }
select, input[type="number"], input[type="text"] {
  width: 100%; min-height: 44px; padding: .55rem .75rem; font: 500 1rem var(--font-body); color: var(--text);
  background: var(--surface); border: 1px solid var(--control-border); border-radius: calc(var(--border-radius-ui) - 4px);
}
.field { display: flex; flex-direction: column; gap: .35rem; margin: 0 0 .9rem; border: 0; padding: 0; min-width: 0; }
.field legend { font-weight: 600; font-size: .95rem; padding: 0; margin-bottom: .35rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.check-row { display: flex; align-items: flex-start; gap: .6rem; margin: 0 0 .9rem; font-weight: 500; cursor: pointer; }
.check-row input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--color-primary-accent); flex: none; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }

input[type="range"] { width: 100%; min-height: 44px; accent-color: var(--color-primary-accent); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--control-border); border-radius: var(--border-radius-ui); padding: 3px; gap: 2px; }
.seg-opt { position: relative; display: flex; }
.seg-opt input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg-opt span { flex: 1; text-align: center; padding: .55rem .4rem; min-height: 44px; display: flex; align-items: center; justify-content: center; border-radius: calc(var(--border-radius-ui) - 4px); font-weight: 600; font-size: .95rem; }
.seg-opt input:checked + span { background: var(--action); color: var(--action-text); box-shadow: inset 0 0 0 2px var(--action-border); }
.seg-opt input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Cards / steps ---------- */
.workspace { padding-top: 2rem; padding-bottom: 3rem; display: flex; flex-direction: column; gap: 1.5rem; }
.card-ui { background: var(--surface); border: 1px solid var(--border); border-radius: var(--border-radius-ui); box-shadow: var(--card-shadow); }
.step, .stage-card, .settings-card { padding: 1.5rem; min-width: 0; }
.step-num {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--action); color: var(--action-text); border: 2px solid var(--action-border); font-size: 1rem; flex: none;
}

/* Dropzone */
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: .75rem; text-align: center;
  padding: 1.75rem 1rem; border: 2px dashed var(--control-border); border-radius: var(--border-radius-ui); background: var(--surface-subtle);
  transition: border-color .2s ease, background-color .2s ease;
}
.dropzone.is-over { border-color: var(--action); background: color-mix(in srgb, var(--action) 14%, var(--surface-subtle)); }
.dropzone:has(.sr-only-input:focus-visible) #browse-btn { outline: 3px solid var(--focus); outline-offset: 3px; }
.drop-title { font-weight: 600; margin: 0; color: var(--heading); }
.drop-actions { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: center; }
.dropzone .caption-tech { margin: 0; }

.media-empty { margin-top: 1rem; }
.media-count { margin: 1rem 0 .5rem; }
.media-list { list-style: none; padding: 0; margin: .75rem 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.media-card { border: 1px solid var(--border); border-radius: var(--border-radius-ui); overflow: hidden; background: var(--surface); display: flex; flex-direction: column; min-width: 0; }
.media-card.is-used { border-color: var(--action); box-shadow: 0 0 0 1px var(--action); }
.thumb { position: relative; aspect-ratio: 16 / 9; background: var(--stage-bg); }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: contain; display: block; }
.badge {
  position: absolute; top: 8px; left: 8px; display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px;
  border-radius: 999px; background: rgba(46, 41, 78, .9); color: #fff; font-size: .75rem; font-weight: 600;
}
.badge .icon { width: 14px; height: 14px; stroke: #fff; }
.badge.role { left: auto; right: 8px; background: var(--action); color: var(--action-text); border: 1px solid var(--action-border); }
.media-body { padding: .75rem; display: flex; flex-direction: column; gap: .5rem; }
.media-name { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 0; max-width: none; }
.media-meta { font-size: .8rem; color: var(--text-muted); margin: 0; }
.media-actions { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: calc(var(--border-radius-ui) - 4px); border: 1px solid transparent; background: transparent; cursor: pointer; }
.icon-btn:hover { background: var(--surface-subtle); border-color: var(--border); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.media-actions .check-row { margin: 0; flex: 1 1 100%; align-items: center; min-height: 36px; font-size: .85rem; }
.media-actions .spacer { flex: 1; }

/* Mode choice */
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.mode-card { position: relative; display: block; cursor: pointer; }
.mode-card input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.mode-body { display: flex; gap: .9rem; align-items: flex-start; padding: 1rem; border: 2px solid var(--control-border); border-radius: var(--border-radius-ui); background: var(--surface); height: 100%; }
.mode-card input:checked + .mode-body { border-color: var(--action-border); background: color-mix(in srgb, var(--action) 14%, var(--surface)); box-shadow: 0 0 0 1px var(--action-border); }
.mode-card input:focus-visible + .mode-body { outline: 3px solid var(--focus); outline-offset: 3px; }
.mode-text { display: flex; flex-direction: column; gap: .15rem; }
.mode-title { font-family: var(--font-heading); font-weight: 700; font-size: 1.15rem; color: var(--heading); }
.mode-desc { font-size: .9rem; color: var(--text-muted); font-weight: 400; }

/* Studio */
.studio { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); gap: 1.5rem; align-items: start; }
.stage { position: relative; background: var(--stage-bg); border-radius: calc(var(--border-radius-ui) - 2px); overflow: hidden; line-height: 0; }
.stage canvas { display: block; width: 100%; height: auto; touch-action: pan-y; }
.stage canvas.is-vertical { touch-action: pan-x; }
.stage canvas.is-slider { cursor: ew-resize; }
.stage canvas.is-slider.is-vertical { cursor: ns-resize; }
.stage-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 1.5rem; color: #E2E8F0; background: var(--stage-bg); margin: 0; max-width: none; line-height: 1.5; font-weight: 500;
}
@media (min-width: 1024px) { .stage-card { position: sticky; top: 16px; } }
#swap-btn { margin-bottom: .9rem; }
.stage-controls { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.range-row { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; align-items: center; margin-top: .75rem; }
.range-row output { grid-column: 1 / -1; }
#grid-count { margin-top: .75rem; }

.settings-card .step-title { margin-bottom: 1rem; }
.need-media { color: var(--text); margin-bottom: .75rem; }
.export-actions { margin-top: .5rem; }

.progress-wrap { margin-top: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.progress { height: 12px; border-radius: 6px; background: var(--surface-subtle); border: 1px solid var(--control-border); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--action); transition: width .15s linear; }

.result { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: .75rem; }
.result-title { font-size: 1.15rem; margin: 0; }
.result-media { background: var(--stage-bg); border-radius: calc(var(--border-radius-ui) - 2px); overflow: hidden; line-height: 0; }
.result-media img, .result-media video { width: 100%; height: auto; display: block; max-height: 360px; object-fit: contain; }

.lockable[inert] { opacity: .55; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); background: var(--surface-subtle); padding: 1.5rem 0 2rem; }
.footer-inner { display: flex; flex-direction: column; gap: .35rem; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: var(--color-secondary-brand); color: #fff; padding: .75rem 1.1rem; border-radius: var(--border-radius-ui);
  border: 1px solid var(--action); box-shadow: var(--card-shadow); max-width: min(92vw, 520px); font-weight: 500;
  pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive (proposed breakpoints, spec §8) ---------- */
@media (max-width: 1023.98px) {
  .studio { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 767.98px) {
  :root { --gutter: 16px; }
  h1 { font-size: 2rem; }
  h2 { font-size: 1.75rem; }
  .hero { padding: 2.25rem 1rem; }
  .brand-logo { width: 96px; max-width: 100%; }
  .app-name { font-size: 1.1rem; }
  .version-pill { display: none; }
  .header-inner { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .mode-grid { grid-template-columns: 1fr; }
  .step, .stage-card, .settings-card { padding: 1.1rem; }
  .media-list { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
@media (max-width: 400px) {
  .field-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media (forced-colors: active) {
  .btn-primary, .btn-secondary, .lang-opt input:checked + span, .seg-opt input:checked + span { border: 2px solid ButtonText; }
  .switch::after { background: ButtonText; }
}

/* ---------- Compact header (matches SmartFrame Extractor reference) ---------- */
.header-inner { padding-top: 10px; padding-bottom: 10px; gap: 8px 20px; }
.brand-block { gap: 14px; }
.brand { padding: 4px; border-radius: 10px; }
.brand-logo { width: 108px; max-width: none; }
.app-name { font-size: 1.15rem; }
.app-sub { font-size: .8rem; }
.header-utils { gap: 10px 14px; flex-wrap: nowrap; }
.version-pill { font-size: .72rem; padding: .15rem .6rem; }
.lang-switch { border-radius: 999px; padding: 2px; gap: 0; }
.lang-opt span { min-width: 34px; min-height: 26px; padding: 0 .55rem; font-size: .75rem; border-radius: 999px; }
.lang-opt input:checked + span { box-shadow: none; }
.theme-switch { min-height: 32px; gap: 8px; }
.switch { width: 38px; height: 22px; border-radius: 11px; border-width: 0; background: var(--control-border); }
.switch::after { top: 3px; left: 3px; width: 16px; height: 16px; }
.switch:checked { background: var(--action); }
.switch:checked::after { transform: translateX(16px); }
.theme-state { font-size: .75rem; font-weight: 600; color: var(--text); }
@media (max-width: 767.98px) {
  .brand-logo { width: 84px; }
  .header-utils { flex-wrap: wrap; }
}

/* ---------- Compact scale: first card visible above the fold ---------- */
html { font-size: 14px; }
h1 { font-size: 1.9rem; margin-bottom: .35rem; }
.step-title { font-size: 1.15rem; margin-bottom: .6rem; }
.hero { padding: 1rem 1rem 1.1rem; }
.hero .text-highlight { font-size: .7rem; margin-bottom: .2rem; }
.hero p { font-size: .9rem; margin-bottom: 0; line-height: 1.5; }
.workspace { padding-top: 1rem; gap: 1rem; padding-bottom: 2rem; }
.step, .stage-card, .settings-card { padding: 1rem 1.25rem; }
.step-num { width: 26px; height: 26px; font-size: .8rem; }
.dropzone { padding: .9rem 1rem; gap: .5rem; flex-direction: row; flex-wrap: wrap; justify-content: center; }
.dropzone .icon-lg { width: 24px; height: 24px; }
.drop-title { font-size: .95rem; }
.dropzone .caption-tech { flex-basis: 100%; }
.btn { padding: .5rem 1rem; min-height: 36px; font-size: .9rem; }
select, input[type="number"], input[type="text"] { min-height: 36px; padding: .35rem .6rem; font-size: .9rem; }
.media-empty { margin-top: .6rem; }
@media (max-width: 767.98px) {
  html { font-size: 14px; }
  h1 { font-size: 1.5rem; }
  .hero { padding: .9rem 1rem; }
  .dropzone { flex-direction: column; }
}
