@font-face {
  font-family: 'Inter';
  src: url('/static/fonts/InterVariable.woff2') format('woff2-variations'),
       url('/static/fonts/InterVariable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f7f7fb;
  --bg-elevated: #ffffff;
  --bg-subtle: #f1f1f6;
  --text: #16161f;
  --text-muted: #6b6b7b;
  --border: #e4e4ec;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eeedfd;
  --accent-contrast: #ffffff;
  --success-bg: #eafaf1; --success-text: #0f7a4a; --success-border: #34c076;
  --error-bg: #fdecec; --error-text: #b3261e; --error-border: #f26a63;
  --warning-bg: #fff6e0; --warning-text: #8a5a00; --warning-border: #f0ad2e;
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.04), 0 1px 4px rgba(20, 20, 40, 0.04);
  --shadow-lg: 0 8px 24px rgba(20, 20, 40, 0.10), 0 2px 6px rgba(20, 20, 40, 0.06);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d13;
  --bg-elevated: #16161f;
  --bg-subtle: #1c1c28;
  --text: #f2f2f7;
  --text-muted: #9a9aad;
  --border: #2a2a38;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-soft: #23234a;
  --accent-contrast: #0d0d13;
  --success-bg: #103322; --success-text: #4ade95; --success-border: #1f7a4d;
  --error-bg: #331515; --error-text: #ff8a82; --error-border: #7a2620;
  --warning-bg: #332708; --warning-text: #f5c76a; --warning-border: #8a6300;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 4px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.45), 0 4px 10px rgba(0, 0, 0, 0.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d13;
    --bg-elevated: #16161f;
    --bg-subtle: #1c1c28;
    --text: #f2f2f7;
    --text-muted: #9a9aad;
    --border: #2a2a38;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: #23234a;
    --accent-contrast: #0d0d13;
    --success-bg: #103322; --success-text: #4ade95; --success-border: #1f7a4d;
    --error-bg: #331515; --error-text: #ff8a82; --error-border: #7a2620;
    --warning-bg: #332708; --warning-text: #f5c76a; --warning-border: #8a6300;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 4px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.45), 0 4px 10px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

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

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.55;
  font-size: 16px;
  transition: background-color .2s ease, color .2s ease;
}

h1, h2, h3 { font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
h1 { font-size: 1.7rem; margin: 0 0 1.1rem; }
h2 { font-size: 1.15rem; margin: 1.75rem 0 0.6rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
.muted { color: var(--text-muted); }

/* ---------- topbar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.55rem 1.1rem; border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky; top: 0; z-index: 20;
  gap: 0.5rem;
}
.brand { display: inline-flex; align-items: center; gap: 0.55rem; color: var(--text); font-weight: 700;
  font-size: 1.05rem; letter-spacing: -0.01em; }
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark { display: block; transition: transform .25s ease; }
.brand:hover .brand-mark { transform: rotate(-8deg) scale(1.05); }
.topbar nav { display: flex; align-items: center; flex-wrap: nowrap; gap: 0.4rem; flex-shrink: 0; }
.topbar nav a:not(.icon-button) { font-size: 0.92rem; white-space: nowrap; }

.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.1rem; height: 2.1rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-subtle); color: var(--text); cursor: pointer; flex-shrink: 0;
  transition: background-color .15s ease, transform .1s ease, border-color .15s ease;
}
.icon-button:hover { border-color: var(--accent); transform: translateY(-1px); }
.icon-button:active { transform: translateY(0) scale(0.94); }
.icon-button svg { width: 1.05rem; height: 1.05rem; }

/* ---------- circulos de tema (dentro de ajustes de lectura) ---------- */
.theme-circles { display: flex; gap: 0.6rem; }
.theme-circle {
  width: 1.7rem; height: 1.7rem; border-radius: 50%; cursor: pointer; padding: 0;
  transition: transform .1s ease, box-shadow .15s ease;
}
.theme-circle-light { background: #ffffff; border: 1px solid #d4d4dc; }
.theme-circle-dark { background: #16161f; border: 1px solid #16161f; }
.theme-circle:hover { transform: scale(1.08); }
.theme-circle.is-active { box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 4px var(--accent); }

/* ---------- layout ---------- */
.container {
  max-width: 760px; margin: 0 auto; padding: 2rem 1.25rem 4rem;
  animation: fade-in-up .45s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes fade-in-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  .container, .brand-mark, * { animation: none !important; transition: none !important; }
}

.page-center { display: flex; justify-content: center; padding: 3rem 1rem; min-height: calc(100vh - 4.2rem); align-items: center; }

/* ---------- cards ---------- */
.card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 2rem; width: 100%; max-width: 380px;
}
.card-header { text-align: center; margin-bottom: 1.5rem; }
.card-header .brand-mark { margin: 0 auto 0.85rem; }
.card-header h1 { margin-bottom: 0.25rem; }
.card-header p { margin: 0; }
.card-section { background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem 1.4rem; margin: 1.25rem 0; }

.divider { display: flex; align-items: center; gap: 0.75rem; margin: 1.35rem 0; color: var(--text-muted); font-size: 0.85rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 1rem; }
.form label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.88rem; font-weight: 550; }
input[type="email"], input[type="password"], input[type="text"], input[type="search"],
input[type="file"], select {
  font: inherit; padding: 0.65rem 0.8rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- toolbar (biblioteca: buscar + ordenar) ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1.75rem; }
.toolbar-search { flex: 1; min-width: 160px; }

/* ---------- titulo editable ---------- */
.title-edit-form { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 1.1rem; flex-wrap: wrap; }
.title-input {
  flex: 1; min-width: 200px; font-size: 1.6rem; font-weight: 650; letter-spacing: -0.01em;
  border: 1px solid transparent; background: transparent; padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm); font-family: inherit;
}
.title-input:hover { border-color: var(--border); }
.title-input:focus { background: var(--bg-elevated); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

button, .button {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-weight: 600; padding: 0.7rem 1.1rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--accent); color: var(--accent-contrast);
  cursor: pointer; transition: background-color .15s ease, transform .08s ease, box-shadow .15s ease;
}
button:hover, .button:hover { background: var(--accent-hover); text-decoration: none; color: var(--accent-contrast); }
button:active, .button:active { transform: scale(0.98); }
button.secondary, .button.secondary { background: var(--bg-subtle); color: var(--text); border-color: var(--border); }
button.secondary:hover, .button.secondary:hover { background: var(--bg-elevated); border-color: var(--accent); color: var(--text); }

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

.form-footer { text-align: center; margin-top: 1.25rem; font-size: 0.9rem; color: var(--text-muted); }

/* ---------- flashes / callouts ---------- */
.flash { padding: 0.65rem 0.9rem; border-radius: var(--radius-sm); margin-bottom: 1.1rem;
  border: 1px solid transparent; font-size: 0.92rem; }
.flash-error { background: var(--error-bg); color: var(--error-text); border-color: var(--error-border); }
.flash-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.callout-warning { background: var(--warning-bg); color: var(--warning-text); padding: 0.7rem 1rem;
  border-radius: var(--radius-sm); border: 1px solid var(--warning-border); }

/* ---------- status badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; font-weight: 650;
  padding: 0.2rem 0.6rem; border-radius: 999px; letter-spacing: 0.01em; text-transform: uppercase; }
.badge-uploaded, .badge-pending { background: var(--warning-bg); color: var(--warning-text); }
.badge-extracting, .badge-processing { background: var(--accent-soft); color: var(--accent); }
.badge-extracted, .badge-done { background: var(--success-bg); color: var(--success-text); }
.badge-error { background: var(--error-bg); color: var(--error-text); }

/* ---------- spinner ---------- */
.spinner {
  width: 1.3rem; height: 1.3rem; border-radius: 50%; flex-shrink: 0;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- panel generico (disclosure) ---------- */
.panel { margin: 1.4rem 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elevated); overflow: hidden; }
.panel > summary {
  cursor: pointer; font-weight: 600; padding: 0.85rem 1.1rem; list-style: none;
  display: flex; align-items: center; gap: 0.5rem; user-select: none;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::before {
  content: "›"; display: inline-block; font-size: 1.2rem; color: var(--text-muted);
  transition: transform .2s ease; transform: rotate(0deg);
}
.panel[open] > summary::before { transform: rotate(90deg); }
.panel-body { padding: 0 1.1rem 1.1rem; }

/* ---------- citas ---------- */
.citations-list { list-style: none; padding: 0 1.1rem 1.1rem; margin: 0; display: flex; flex-direction: column; gap: 1rem; }
.citations-list li { padding-top: 1rem; border-top: 1px solid var(--border); }
.citations-list li:first-child { padding-top: 0; border-top: none; }
.citation-badge { display: inline-block; font-size: 0.76rem; font-weight: 650; padding: 0.15rem 0.55rem;
  border-radius: 999px; margin-bottom: 0.4rem; }
.citation-verified .citation-badge { background: var(--success-bg); color: var(--success-text); }
.citation-unverified .citation-badge { background: var(--error-bg); color: var(--error-text); }
.citation-claim { margin: 0.2rem 0; font-weight: 550; }
.citation-quote { margin: 0.4rem 0 0; padding-left: 0.85rem; border-left: 3px solid var(--border); font-style: italic; color: var(--text-muted); }
.citation-quote cite { display: block; font-style: normal; font-size: 0.82rem; opacity: 0.75; margin-top: 0.25rem; }

/* ---------- ajustes de lectura ---------- */
.reading-settings-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.85rem;
}
.reading-settings-grid label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.82rem; font-weight: 550; color: var(--text-muted); }
.reading-settings-grid select { padding: 0.45rem 0.6rem; }

.reading-content { text-align: justify; -webkit-hyphens: auto; hyphens: auto; }
.reading-content[data-align="left"] { text-align: left; -webkit-hyphens: none; hyphens: none; }
.reading-content[data-align="justify"] { text-align: justify; -webkit-hyphens: auto; hyphens: auto; }

.reading-content[data-font="serif"] { font-family: Georgia, 'Times New Roman', serif; }
.reading-content[data-font="sans"] { font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif; }

.reading-content[data-size="sm"] { font-size: 0.92rem; }
.reading-content[data-size="md"] { font-size: 1rem; }
.reading-content[data-size="lg"] { font-size: 1.15rem; }
.reading-content[data-size="xl"] { font-size: 1.3rem; }

.reading-content[data-spacing="compact"] { line-height: 1.4; }
.reading-content[data-spacing="normal"] { line-height: 1.7; }
.reading-content[data-spacing="relaxed"] { line-height: 2; }
.reading-content h2 { text-align: left; }

/* ---------- chat del resumen ---------- */
.chat-thread { display: flex; flex-direction: column; gap: 0.85rem; margin-bottom: 1.1rem; max-height: 32rem; overflow-y: auto; }
.chat-bubble { max-width: 85%; padding: 0.65rem 0.9rem; border-radius: var(--radius); line-height: 1.5; font-size: 0.94rem; }
.chat-bubble p { margin: 0; }
.chat-bubble p + p { margin-top: 0.5rem; }
.chat-bubble-user { align-self: flex-end; background: var(--accent); color: var(--accent-contrast); border-bottom-right-radius: 4px; }
.chat-bubble-assistant { align-self: flex-start; background: var(--bg-subtle); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-bubble-error { align-self: flex-start; background: var(--error-bg); color: var(--error-text); border: 1px solid var(--error-border); }
.chat-form { display: flex; gap: 0.6rem; align-items: flex-end; }
.chat-form textarea { flex: 1; resize: vertical; min-height: 2.6rem; max-height: 8rem; font-family: inherit; }
.chat-indicator { display: none; align-items: center; gap: 0.5rem; margin-top: 0.6rem; color: var(--text-muted); font-size: 0.85rem; }
.htmx-request .chat-indicator { display: flex; }
.htmx-request.chat-indicator { display: flex; }

/* ---------- misc ---------- */
ul { padding-left: 1.3rem; }
li { margin-bottom: 0.3rem; }
section + section { margin-top: 1.75rem; padding-top: 1.75rem; border-top: 1px solid var(--border); }

@media (max-width: 480px) {
  .container { padding: 1.25rem 1rem 3rem; }
  h1 { font-size: 1.4rem; }
  .card { padding: 1.5rem; }
  .topbar { padding: 0.5rem 0.85rem; }
}
