/* Ley 60 Q&A — civic design system
   Design tokens (CSS custom properties) define the entire palette.
   Both light and dark modes are driven from this single source of truth.
*/

:root {
    /* Surfaces */
    --bg: #fafaf8;
    --surface: #ffffff;
    --surface-2: #f4f3ef;

    /* Text */
    --text: #1a1a1a;
    --text-muted: #525252;
    --text-subtle: #737373;

    /* Borders */
    --border: #e5e4e0;
    --border-strong: #d4d3ce;

    /* Accent — muted forest green */
    --accent: #2d5447;
    --accent-text: #1e3a30;
    --accent-bg: #e8f1ed;

    /* Warning — goldenrod */
    --warning-bg: #fdf6e3;
    --warning-border: #b8945a;
    --warning-text: #6b4e1a;

    /* Error — restrained red */
    --error-bg: #fdecea;
    --error-border: #c44545;
    --error-text: #8b2222;

    /* Layout */
    --radius: 4px;
    --radius-lg: 6px;
}

html.dark {
    --bg: #1c1b18;
    --surface: #25241f;
    --surface-2: #2e2d27;
    --text: #f5f4ef;
    --text-muted: #b8b6ad;
    --text-subtle: #8a8880;
    --border: #36352f;
    --border-strong: #4a4942;
    --accent: #6ba892;
    --accent-text: #a6cdb9;
    --accent-bg: #1f2e26;
    --warning-bg: #2a2418;
    --warning-border: #8a6f3a;
    --warning-text: #d4b87a;
    --error-bg: #2a1818;
    --error-border: #a64545;
    --error-text: #e8a8a8;
}

/* ---------- Base ---------- */

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

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

body {
    margin: 0;
    font-family: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.65;
}

h1, h2, h3 {
    font-family: 'Source Serif 4', Georgia, serif;
    letter-spacing: -0.01em;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

p { margin: 0; }

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

textarea {
    font-family: inherit;
    font-size: inherit;
    resize: vertical;
}

/* ---------- Layout ---------- */

.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

@media (min-width: 640px) {
    .container { padding: 3rem 1rem; }
}

.id-strip {
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 0.7rem;
    color: var(--text-subtle);
    padding-bottom: 0.75rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

header.main { margin-bottom: 2rem; }

h1.title {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

@media (min-width: 640px) {
    h1.title { font-size: 2.5rem; }
}

p.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1.5;
}

/* ---------- Buttons ---------- */

.btn-primary {
    background: var(--accent);
    color: white;
    border: 1px solid var(--accent);
    padding: 0.65rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: opacity 0.15s;
}

.btn-primary:hover:not(:disabled) { opacity: 0.92; }

.btn-ghost {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius);
    font-size: 0.75rem;
    transition: opacity 0.15s;
}

.btn-ghost:hover { opacity: 0.7; }

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
}

.btn-row-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-subtle);
    font-weight: 500;
    margin-right: 0.25rem;
}

/* ---------- Banners ---------- */

.banner-warning {
    background: var(--warning-bg);
    border-left: 4px solid var(--warning-border);
    color: var(--warning-text);
    padding: 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    line-height: 1.55;
}

.banner-warning strong { font-weight: 600; }

.banner-error {
    background: var(--error-bg);
    border-left: 4px solid var(--error-border);
    color: var(--error-text);
    padding: 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    border-radius: 0 var(--radius) var(--radius) 0;
}

.banner-error.hidden { display: none; }

/* ---------- Surface (cards, panels) ---------- */

.surface {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* ---------- Cómo funciona ---------- */

details.howto {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 2rem;
}

details.howto > summary {
    list-style: none;
    cursor: pointer;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

details.howto > summary::-webkit-details-marker { display: none; }

details.howto > summary .indicator {
    color: var(--text-subtle);
    font-weight: 400;
}

details.howto[open] > summary .indicator::before { content: "−"; }
details.howto:not([open]) > summary .indicator::before { content: "+"; }

details.howto > div {
    padding: 0 1rem 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

details.howto > div > p { margin-top: 0.75rem; margin-bottom: 0.5rem; line-height: 1.55; }
details.howto > div > p.lim-title { font-weight: 600; color: var(--text); margin-top: 0.75rem; }
details.howto > div ol,
details.howto > div ul {
    padding-left: 1.25rem;
    margin: 0.5rem 0 0.5rem;
    line-height: 1.55;
}
details.howto > div li { margin-bottom: 0.25rem; }

/* ---------- Question form ---------- */

.question-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 2rem;
}

.question-card label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.75rem;
}

.input-field {
    width: 100%;
    padding: 0.625rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text);
    border-radius: var(--radius);
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 0.75rem;
}

.input-field:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}

.input-field::placeholder { color: var(--text-subtle); }

/* ---------- Loading ---------- */

.loading {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.loading.hidden { display: none; }

.spinner {
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Answer section ---------- */

.answer-section { margin-bottom: 2rem; }
.answer-section.hidden { display: none; }

.answer-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.answer-header h2 { font-size: 1.25rem; }

.answer-meta {
    font-size: 0.75rem;
    color: var(--text-subtle);
}

.answer-body {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    line-height: 1.7;
    white-space: pre-wrap;
}

.answer-body p { margin-bottom: 0.75rem; }
.answer-body p:last-child { margin-bottom: 0; }

.citation {
    background: var(--accent-bg);
    color: var(--accent-text);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.88em;
    font-weight: 500;
    border: 1px solid var(--border);
    white-space: nowrap;
}

.llm-unavailable {
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
    border-radius: var(--radius);
    padding: 1rem;
    color: var(--warning-text);
}

.llm-unavailable p { margin: 0; }
.llm-unavailable p + p { margin-top: 0.5rem; }
.llm-unavailable .lead { font-weight: 600; }
.llm-unavailable .detail { font-size: 0.875rem; }

/* ---------- Sources ---------- */

.sources-section { margin-bottom: 2rem; }
.sources-section.hidden { display: none; }

.sources-header { margin-bottom: 0.5rem; }
.sources-header h2 { font-size: 1.25rem; }
.sources-count {
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--text-subtle);
    margin-left: 0.5rem;
}
.sources-intro {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.sources-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.source-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.source-card:hover { border-color: var(--border-strong); }

.source-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
}

.source-title {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text);
}

.source-pages {
    font-size: 0.75rem;
    color: var(--text-subtle);
    margin-top: 0.25rem;
    white-space: nowrap;
}

.source-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.source-meta {
    font-size: 0.75rem;
    color: var(--text-subtle);
    margin-bottom: 0.75rem;
}

.source-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    font-size: 0.75rem;
    flex-wrap: wrap;
}

.source-actions a,
.source-actions button {
    color: var(--accent-text);
    font-weight: 500;
    background: none;
    border: none;
    padding: 0;
    font-size: 0.75rem;
}

.source-actions a:hover,
.source-actions button:hover { text-decoration: underline; }

.source-actions .sep { color: var(--text-subtle); }

.source-text {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 0.9rem;
    line-height: 1.65;
    color: var(--text);
    white-space: pre-wrap;
}

.source-text.hidden { display: none; }

/* ---------- Footer ---------- */

footer.main {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-subtle);
    line-height: 1.55;
}

footer.main p { margin-bottom: 0.25rem; }

footer.main a { color: var(--accent-text); }

/* ---------- Theme toggle ---------- */

.theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 50;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.75rem;
    font-weight: 500;
    transition: opacity 0.15s;
}

.theme-toggle:hover { opacity: 0.8; }
