:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f7f7fa;
  --text: #1c1c1e;
  --muted: #6c6c70;
  --border: rgba(60, 60, 67, 0.16);
  --accent: #0f4c5c;
  --accent-text: #ffffff;
  --accent-soft: #e2eff1;
  --accent-soft-text: #0b3a46;
  --ok: #1f7a3d;
  --ok-soft: #e4f3e8;
  --warn: #8a5300;
  --warn-soft: #fdf1dc;
  --danger: #c0352b;
  --danger-soft: #fbe9e7;
  --bubble-bot: #ffffff;
  --bubble-me: #0f4c5c;
  --bubble-me-text: #ffffff;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f2f2f7;
    --muted: #a1a1a6;
    --border: rgba(235, 235, 245, 0.16);
    --accent: #5cb8c9;
    --accent-text: #00262e;
    --accent-soft: #12343b;
    --accent-soft-text: #bfe7ee;
    --ok: #6fd28c;
    --ok-soft: #14301d;
    --warn: #f3b552;
    --warn-soft: #3a2a0d;
    --danger: #ff6b5e;
    --danger-soft: #3b1512;
    --bubble-bot: #2c2c2e;
    --bubble-me: #5cb8c9;
    --bubble-me-text: #00262e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --surface: #1c1c1e; --surface-2: #2c2c2e; --text: #f2f2f7; --muted: #a1a1a6;
  --border: rgba(235, 235, 245, 0.16); --accent: #5cb8c9; --accent-text: #00262e; --accent-soft: #12343b;
  --accent-soft-text: #bfe7ee; --ok: #6fd28c; --ok-soft: #14301d; --warn: #f3b552; --warn-soft: #3a2a0d;
  --danger: #ff6b5e; --danger-soft: #3b1512; --bubble-bot: #2c2c2e; --bubble-me: #5cb8c9; --bubble-me-text: #00262e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.loading { padding: 40px 16px; text-align: center; color: var(--muted); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-top)) 8px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 0.5px solid var(--border);
}
.topbar-title { flex: 1; min-width: 0; text-align: center; }
.topbar h1 { margin: 0; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back, .back-spacer { width: 44px; height: 44px; flex: none; display: grid; place-items: center; color: var(--accent); }
.icon { display: inline-grid; width: 22px; height: 22px; flex: none; }
.icon svg { width: 100%; height: 100%; }

.content { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(32px + var(--safe-bottom)); }
.card { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 16px; }
.card-title { margin: 0 0 10px; font-size: 13px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; color: var(--muted); }
.sub { font-size: 15px; margin: 14px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.footnote { text-align: center; font-size: 13px; color: var(--muted); }
.error { color: var(--danger); font-size: 15px; min-height: 0; }
.error:empty { display: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 0;
  background: var(--accent-soft); color: var(--accent-soft-text); font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-outline { background: transparent; color: var(--danger); border: 1px solid var(--danger-soft); }
.btn.block { display: flex; width: 100%; margin: 10px 0 0; }
.btn.big { min-height: 52px; font-size: 17px; }
.content > .btn.block:first-child { margin: 0 0 16px; }
.btn:disabled { opacity: 0.5; }
.btn:active { transform: scale(0.98); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn-row .btn { flex: 1 1 auto; }
.icon-btn { width: 44px; padding: 0; }
.link { background: none; border: 0; padding: 8px; color: var(--accent); cursor: pointer; font-size: 16px; }
.link.strong { font-weight: 600; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
label.btn { position: relative; }

.banner { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); margin-bottom: 16px; font-size: 15px; }
.banner span { flex: 1; }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.empty { text-align: center; padding: 28px 8px; }
.empty h2 { font-size: 20px; margin: 0 0 6px; }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 0.5px solid var(--border); color: inherit; text-decoration: none; }
.card-title + .list-item { border-top: 0; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 600; }
.list-sub { font-size: 14px; color: var(--muted); }
.pill { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; width: 100%; padding: 10px 0; border: 0; border-top: 0.5px solid var(--border); background: none; text-align: left; }
.card-title + .row, .row:first-child { border-top: 0; }
.row.tappable { cursor: pointer; }
.row-label { color: var(--muted); font-size: 15px; flex: 1; }
.row-value { font-size: 15px; text-align: right; max-width: 55%; overflow-wrap: anywhere; }
.row-value.warn { color: var(--warn); }
.issue { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; color: var(--warn); font-size: 15px; }

/* Chat */
.progress { height: 3px; background: var(--border); }
.progress div { height: 100%; background: var(--accent); transition: width 0.2s; }
.chat-wrap { padding-bottom: 220px; }
.chat { display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 82%; padding: 9px 13px; border-radius: 18px; font-size: 16px; overflow-wrap: anywhere; }
.bubble.bot { align-self: flex-start; background: var(--bubble-bot); border-bottom-left-radius: 6px; }
.bubble.me { align-self: flex-end; background: var(--bubble-me); color: var(--bubble-me-text); border-bottom-right-radius: 6px; }
.bubble.me.skipped { background: var(--surface-2); color: var(--muted); font-style: italic; }
.bubble.current { font-weight: 600; }
.optional { font-weight: 400; color: var(--muted); font-size: 14px; }
.hint { font-weight: 400; font-size: 14px; margin-top: 4px; color: var(--muted); }
.hint.ok { color: var(--ok); }
.composer-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 0.5px solid var(--border);
}
.composer-bar > * { max-width: 720px; margin-left: auto; margin-right: auto; }
.composer { display: flex; gap: 8px; }
.composer input { flex: 1; min-width: 0; height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--border); background: var(--surface); font-size: 17px; }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chips:empty { display: none; }
.chip { min-height: 36px; padding: 6px 14px; border-radius: 18px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 15px; }
.chip.suggestion { border-color: var(--accent); color: var(--accent); }
.choices { display: flex; gap: 8px; }
.choices .btn { flex: 1; min-height: 48px; }
.choice.selected { outline: 2px solid var(--accent); }
.dictamen-step { max-height: 60vh; overflow-y: auto; }

/* Formularios y hojas */
.form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.field span { font-size: 14px; color: var(--muted); }
.field input, .field select { height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-size: 17px; }
.sheet-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; background: var(--bg); border-radius: 16px 16px 0 0; padding: 0 16px calc(16px + var(--safe-bottom)); }
.sheet-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 14px 0 8px; background: var(--bg); }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-actions { display: flex; gap: 8px; padding-top: 12px; }
.sheet-actions .btn { flex: 1; }
.photo-large { width: 100%; border-radius: 12px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translate(-50%, 20px); opacity: 0; transition: 0.25s; z-index: 60;
  max-width: min(92vw, 520px); padding: 12px 16px; border-radius: 14px; background: #1c1c1e; color: #fff; font-size: 15px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.update-bar { position: fixed; left: 12px; right: 12px; top: calc(8px + var(--safe-top)); z-index: 70; display: flex; justify-content: space-between; align-items: center;
  padding: 8px 8px 8px 16px; border-radius: 14px; background: var(--accent); color: var(--accent-text); }
.update-bar .link { color: var(--accent-text); }

/* Fotos */
.photo-row { padding: 10px 0; border-top: 0.5px solid var(--border); }
.card-title + .photo-row { border-top: 0; }
.photo-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.photo-label { font-weight: 600; font-size: 16px; }
.thumbs { display: flex; gap: 8px; margin-top: 8px; overflow-x: auto; }
.thumb { flex: none; width: 72px; height: 72px; padding: 0; border: 0; border-radius: 10px; overflow: hidden; background: var(--surface-2); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.logo-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo-thumb { max-height: 48px; max-width: 50%; background: #fff; border-radius: 6px; padding: 4px; }

/* Documentos */
.doc-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 0.5px solid var(--border); }
.doc-name { flex: 1; font-size: 15px; min-width: 0; }

/* Visor */
.viewer { position: fixed; inset: 0; z-index: 40; background: #8e8e93; display: flex; flex-direction: column; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--safe-top)) 8px 6px; background: var(--surface); }
.viewer-title { flex: 1; text-align: center; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-note { padding: 8px 12px; font-size: 13px; background: var(--surface-2); color: var(--muted); }
.viewer-pages { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 8px; }
.viewer-pages .docx-wrapper { background: transparent !important; padding: 0 !important; display: block !important; }
.viewer-pages section.docx { margin: 0 auto 12px !important; box-shadow: 0 2px 8px rgba(0,0,0,.25); }

@media print {
  @page { margin: 0; }
  body { background: #fff !important; }
  body > *:not(.viewer) { display: none !important; }
  .viewer { position: static; display: block; background: #fff; }
  .viewer-bar, .viewer-note { display: none !important; }
  .viewer-pages { overflow: visible; padding: 0; }
  .viewer-pages .docx-wrapper { zoom: 1 !important; }
  .viewer-pages section.docx { margin: 0 !important; box-shadow: none !important; break-after: page; page-break-after: always; }
  .viewer-pages .doc-holder:last-child section.docx:last-child { break-after: auto; page-break-after: auto; }
}
