/* Dark is the default theme; [data-theme="light"] (chosen in Settings) switches every token. */
:root {
  color-scheme: dark;
  --bg: #0f1420; --surface: #171e2c; --surface-2: #1f2838; --border: #2c3648; --text: #e7ecf5; --muted: #9aa6bb;
  --accent: #5b8cff; --accent-hover: #4775eb; --accent-text: #ffffff; --accent-soft: #22325a; --secondary-text: #d3dcf0;
  --error: #ff8a7a; --ok: #4fd18b; --warn: #f5c451; --bad: #ff6b6b; --backdrop: #000000aa;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text); background: var(--bg); font-synthesis: none; -webkit-font-smoothing: antialiased;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8fafc; --surface: #ffffff; --surface-2: #f1f4f9; --border: #dde5f1; --text: #172036; --muted: #5b6780;
  --accent: #2457e8; --accent-hover: #1842bd; --accent-text: #ffffff; --accent-soft: #eaf0ff; --secondary-text: #253b68;
  --error: #9c301e; --ok: #16804a; --warn: #a86b00; --bad: #c02b2b; --backdrop: #17203699;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
a { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }

/* Shell: sidebar on the left, pages on the right. */
.app-shell { min-height: 100svh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100svh; display: flex; flex-direction: column; gap: 20px; padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-size: 15px; font-weight: 650; letter-spacing: -0.3px; min-height: 44px; min-width: 0; overflow-wrap: anywhere; }
.brand img { border-radius: 9px; flex-shrink: 0; }
.menu-toggle { display: none; }
.sidebar-panel { flex: 1; display: flex; flex-direction: column; justify-content: space-between; gap: 20px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar-nav button { text-align: left; background: transparent; color: var(--muted); box-shadow: none; min-height: 44px; padding: 10px 14px; border-radius: 10px; }
.sidebar-nav button:hover { background: var(--surface-2); color: var(--text); }
.sidebar-nav button[aria-current="page"] { background: var(--accent-soft); color: var(--text); }
.sidebar-bottom { display: flex; flex-direction: column; gap: 12px; }
.compat-chip { display: flex; gap: 8px; align-items: center; margin: 0; padding: 0 14px; font-size: 12px; color: var(--muted); }
.compat-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.compat-dot[data-level="full"] { background: var(--ok); }
.compat-dot[data-level="basic"] { background: var(--warn); }
.compat-dot[data-level="unsupported"] { background: var(--bad); }
.install-button { width: 100%; }
.content { min-width: 0; display: flex; flex-direction: column; padding: 0 clamp(16px, 4vw, 56px); }

.eyebrow { color: var(--accent); font-size: 11px; letter-spacing: 2.4px; font-weight: 650; line-height: 1.8; margin: 0 0 12px; }
h1 { margin: 0; font-size: clamp(34px, 5vw, 60px); line-height: 1.08; letter-spacing: -0.05em; font-weight: 700; overflow-wrap: anywhere; }
h2 { font-size: 18px; margin: 0 0 14px; letter-spacing: -0.3px; }
.welcome { max-width: 600px; margin: 18px 0 0; color: var(--muted); font-size: clamp(15px, 1.4vw, 18px); line-height: 1.7; }
button { cursor: pointer; font: inherit; font-size: 14px; font-weight: 600; color: var(--accent-text); background: var(--accent); border: none; border-radius: 12px; padding: 13px 20px; min-height: 46px; transition: background 150ms; }
button:hover { background: var(--accent-hover); }
button:disabled { cursor: wait; opacity: 0.6; }
button span { margin-left: 14px; font-size: 18px; }
.secondary { background: var(--surface-2); color: var(--secondary-text); border: 1px solid var(--border); }
.secondary:hover { background: var(--accent-soft); }
.status { display: inline-flex; gap: 8px; align-items: center; margin: 0 14px; color: var(--muted); font-size: 11px; }
.status-dot { width: 5px; height: 5px; background: var(--accent); border-radius: 50%; flex-shrink: 0; }
.footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-block: 20px; border-top: 1px solid var(--border); font-size: 11px; color: var(--muted); }

main { flex: 1; display: block; padding: 8px 0 48px; }
.transfer-root { max-width: 980px; margin: auto; }
.transfer-heading { padding: 32px 0 26px; }
.transfer-card, .notice { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); padding: 22px; margin-bottom: 16px; }
.notice { background: var(--accent-soft); font-size: 14px; }
.notice p { margin: 8px 0 0; line-height: 1.6; }
.button-row, .card-heading { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-heading { justify-content: space-between; }
.badge { font-size: 12px; background: var(--accent-soft); border-radius: 20px; padding: 6px 12px; }
.help { font-size: 13px; color: var(--muted); line-height: 1.65; }

/* Home */
.feature-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.feature-card { display: flex; flex-direction: column; align-items: flex-start; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); padding: 22px; }
.feature-card .help { flex: 1; margin-top: 0; }
.compat-card { border-left: 4px solid var(--muted); }
.compat-card[data-level="full"] { border-left-color: var(--ok); }
.compat-card[data-level="basic"] { border-left-color: var(--warn); }
.compat-card[data-level="unsupported"] { border-left-color: var(--bad); }
.compat-card .eyebrow { margin-bottom: 6px; }
.compat-reasons { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); line-height: 1.7; }

.pairing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
#pairing-qr { width: 100%; max-width: 350px; height: auto; border: 1px solid var(--border); border-radius: 10px; image-rendering: pixelated; background: #fff; }
video { width: 100%; max-height: 300px; background: #000; border-radius: 12px; margin: 12px 0; }
details { margin-top: 16px; } summary { cursor: pointer; font-size: 14px; min-height: 40px; }
label { display: block; margin: 12px 0 8px; font-size: 14px; line-height: 1.6; }
textarea { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 12px; font: 12px ui-monospace, monospace; resize: vertical; margin-bottom: 10px; background: var(--surface-2); color: var(--text); }
input[type=file] { max-width: 100%; font-size: 14px; padding: 10px 0; color: var(--text); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); margin-right: 10px; vertical-align: middle; flex-shrink: 0; }
.file-checklist label { display: flex; gap: 4px; padding: 12px; background: var(--surface-2); border-radius: 10px; align-items: center; overflow-wrap: anywhere; }
.verification { padding: 18px; background: var(--accent-soft); border-radius: 12px; margin: 18px 0; }
.verification strong { display: block; font: 700 28px ui-monospace, monospace; letter-spacing: 3px; margin: 12px 0 20px; }
.session-actions { margin-top: 20px; }
.progress-list { list-style: none; padding: 0; }
.progress-list li { border-top: 1px solid var(--border); padding: 18px 0; overflow-wrap: anywhere; }
.progress-list strong { display: block; font-size: 15px; }
.progress-list span, .progress-list p { font-size: 13px; color: var(--muted); line-height: 1.6; }
progress { display: block; width: 100%; height: 12px; margin-top: 12px; accent-color: var(--accent); }
.transfer-status { font-size: 14px; line-height: 1.65; min-height: 48px; overflow-wrap: anywhere; }
.transfer-status[data-state=error], #organizer-status[data-state=error], #ai-status[data-state=error], #transcribe-model-status[data-state=error] { color: var(--error); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
input[type=text], select { width: 100%; min-width: 0; max-width: 100%; padding: 12px; font: inherit; font-size: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); }
select { display: block; margin-top: 8px; }
.proposal-row { padding: 16px 0; border-top: 1px solid var(--border); overflow-wrap: anywhere; }
.proposal-row strong { font-size: 14px; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); padding: 12px; border-radius: 10px; font: 12px/1.8 ui-monospace, monospace; }
dialog { border: 1px solid var(--border); border-radius: 16px; padding: 24px; max-width: 640px; width: calc(100% - 32px); max-height: 80vh; overflow: auto; background: var(--surface); color: var(--text); }
dialog::backdrop { background: var(--backdrop); }

.update-banner { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-top: 16px; padding: 12px 16px; border: 1px solid var(--border); background: var(--accent-soft); border-radius: 14px; font-size: 13px; }
.update-banner[hidden] { display: none; }
.update-banner button { min-height: 40px; padding: 10px 18px; }

/* Organization: until Local AI is ready (or basic organization is the fallback), only the setup pointer shows. */
#organizer-root[data-ai-state="checking"] .organizer-step, #organizer-root[data-ai-state="setup"] .organizer-step, #organizer-root[data-ai-state="unsupported"] .organizer-step { display: none; }
#organizer-root[data-ai-state="ready"] .organizer-gate, #organizer-root[data-ai-state="basic"] .organizer-gate { display: none; }

/* Transcription: steps stay hidden until the model is ready. */
#transcribe-root:not([data-transcribe-state="ready"]) .transcribe-step { display: none; }
#transcribe-root[data-transcribe-state="ready"] .transcribe-gate { display: none; }
.format-options { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 8px 0; }
fieldset { border: 1px solid var(--border); border-radius: 10px; }
.transcript pre { white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; }

/* Phones and narrow windows: the sidebar becomes a top bar with a menu. */
@media (max-width: 860px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: sticky; z-index: 10; height: auto; max-height: 100svh; padding: 10px 16px; border-right: none; border-bottom: 1px solid var(--border); gap: 12px; }
  .menu-toggle { display: inline-flex; align-items: center; min-height: 42px; padding: 8px 14px; }
  .app-shell[data-menu="closed"] .sidebar-panel { display: none; }
  .content { padding: 0 16px; }
  .feature-grid, .pairing-grid, .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-grid { gap: 0; }
  .transfer-card, .notice, .feature-card { padding: 18px; }
  .transfer-heading { padding: 24px 0 18px; }
  .brand span { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) { button { transition: none; } }

/* Organization page: inputs on the left, Proposed changes on the right. */
.organizer-page { max-width: 1240px; }
.organizer-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.proposal-panel { position: sticky; top: 16px; max-height: calc(100svh - 32px); overflow-y: auto; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dropzone { border: 2px dashed var(--border); border-radius: 14px; padding: 22px; text-align: center; background: var(--surface-2); transition: border-color 150ms; }
.dropzone[data-over] { border-color: var(--accent); background: var(--accent-soft); }
.dropzone p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.dropzone .button-row { justify-content: center; }
.file-button { display: inline-flex; align-items: center; margin: 0; min-height: 46px; padding: 12px 20px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 14px; cursor: pointer; }
.file-button.secondary-look { background: var(--surface); color: var(--secondary-text); border: 1px solid var(--border); }
input:focus-visible + .file-button, .file-button:has(+ input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 4px; }
input:disabled + .file-button, .file-button:has(+ input:disabled) { opacity: 0.6; cursor: wait; }
.inventory-details .file-checklist { display: grid; gap: 6px; max-height: 320px; overflow-y: auto; }
.segmented { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented label { margin: 0; position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.segmented span { display: flex; justify-content: center; align-items: center; min-height: 42px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); }
.segmented input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.segmented input:disabled + span { opacity: 0.45; }
.segmented input:disabled { cursor: not-allowed; }
.inline-choice { display: flex; align-items: center; gap: 6px; }
.inline-choice input { width: 18px; height: 18px; accent-color: var(--accent); }
h3 { font-size: 15px; margin: 0 0 6px; }
.export-box { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.tree-view { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; font-size: 13px; max-height: 420px; overflow: auto; }
.tree, .tree-view .tree { list-style: none; margin: 0; padding-left: 16px; }
.tree-view > .tree { padding-left: 0; }
.tree details { margin: 0; }
.tree summary { min-height: 30px; display: list-item; font-weight: 600; }
.tree summary .tree-count { float: right; margin-left: 8px; font-weight: 600; font-size: 12px; color: var(--warn); }
.tree-file { padding: 3px 6px; margin-left: -6px; border-radius: 6px; color: var(--text); overflow-wrap: anywhere; cursor: pointer; }
.tree-from { display: block; font-size: 12px; color: var(--muted); }
/* Before and After side by side in Proposed changes; stacked when the panel is narrow. */
.compare { container-type: inline-size; }
.compare-col { min-width: 0; }
.compare-col h3 { margin-bottom: 8px; }
@container (min-width: 420px) { .compare-inner { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; } }
.before-list { list-style: none; margin: 0 0 12px; padding: 12px 14px; background: var(--surface-2); border-radius: 12px; font-size: 13px; max-height: 420px; overflow: auto; }
.before-list li { padding: 3px 6px; margin: 0 -6px; border-radius: 6px; overflow-wrap: anywhere; cursor: pointer; }
.before-excluded { color: var(--muted); }
.before-list li:hover, .tree-file:hover { background: var(--surface); }
.before-list li[data-active], .tree-file[data-active] { background: var(--accent-soft); outline: 1px solid var(--accent); }
.before-list li:focus-visible, .tree-file:focus-visible { outline: 2px solid var(--accent); }
.inplace-box { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border); }
.move-list { margin: 12px 0; padding-left: 22px; font-size: 13px; line-height: 1.6; max-height: 45vh; overflow: auto; overflow-wrap: anywhere; }
.move-list span { color: var(--muted); }
.problem-list { margin: 8px 0; padding-left: 20px; color: var(--error); font-size: 14px; }
.problem-list:empty { display: none; }
@media (max-width: 1100px) {
  .organizer-layout { grid-template-columns: minmax(0, 1fr); }
  .proposal-panel { position: static; max-height: none; }
}

/* Assistant chat (the Description box) and its preview in Proposed changes. */
.chat-log { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.chat-log:empty { display: none; }
.chat-log li { padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.55; max-width: 88%; overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-user { align-self: flex-end; background: var(--accent); color: var(--accent-text); }
.chat-assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); }
.chat-input { display: flex; gap: 8px; align-items: flex-end; }
.chat-input textarea { margin: 0; font: inherit; font-size: 14px; min-height: 48px; }
.assistant-preview { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.assistant-preview ul { margin: 6px 0; padding-left: 18px; font-size: 13px; line-height: 1.6; }
.preview-list { max-height: 200px; overflow-y: auto; overflow-wrap: anywhere; }
