/* ======================================================================
   Aria Web -- SPA stylesheet  (Task 33: modern minimalist "Salt & Pepper")
   ----------------------------------------------------------------------
   Visual language: a deliberately minimal, high-contrast neutral system.
   Palette (REQ-17.1): #FFFFFF, #D4D4D4, #B3B3B3, #2B2B2B, with #D14836 as
   the ONE warm accent, reserved exclusively for alerts / validation errors
   / destructive states.

   Theming (REQ-17.2): every color is a semantic token. The light theme is
   the default in :root; the dark theme overrides the SAME tokens under
   :root[data-theme="dark"], so components never need per-theme edits.
   A few derived neutral tints (e.g. #1C1C1C page-dark, alert backgrounds)
   extend the four-color palette where contrast/legibility require it;
   #B3B3B3 is kept off body text on white per REQ-17.6.

   Typography (REQ-17.5): a single sans stack + a shared type scale.
   Elements here are used by Tasks 14-18 + the Task 33 header theme toggle.
   ====================================================================== */

/* 1. Tokens ------------------------------------------------------------ */
:root,
:root[data-theme="light"] {
    /* Surfaces */
    --bg:             #ffffff;   /* page */
    --surface:        #ffffff;   /* cards, inputs */
    --surface-2:      #f1f1f1;   /* subtle fills: hover, output panel (derived tint of #D4D4D4) */
    --header-bg:      #2b2b2b;   /* distinctive charcoal header */
    --header-text:    #ffffff;
    --header-muted:   #b3b3b3;

    /* Ink */
    --text:           #2b2b2b;   /* primary ink */
    --text-muted:     #6e6e6e;   /* secondary text -- darker than #B3B3B3 for AA (REQ-17.6) */

    /* Lines */
    --border:         #d4d4d4;   /* default hairline */
    --border-strong:  #b3b3b3;   /* emphasized border (REQ-17.6: borders only, not text) */

    /* Interactive ink (buttons / selected chips). Charcoal in light, light in dark. */
    --accent:         #2b2b2b;
    --accent-hover:   #444444;
    --accent-contrast:#ffffff;

    /* The single warm accent -- alerts only (REQ-17.1) */
    --alert:          #d14836;
    --alert-bg:       #fbeae7;
    --alert-border:   #e2a89f;

    --ring:           rgba(43, 43, 43, 0.18);   /* focus ring */
    --shadow:         0 1px 2px rgba(43, 43, 43, 0.05), 0 10px 28px rgba(43, 43, 43, 0.06);
    --shadow-hover:   0 2px 6px rgba(43, 43, 43, 0.12);

    /* Shape & rhythm */
    --radius:         12px;
    --radius-sm:      8px;
    --space:          16px;

    /* Typography (REQ-17.5) */
    --font-sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --fs-display: 28px;
    --fs-title:   22px;
    --fs-body:    15px;
    --fs-label:   13px;
    --fs-small:   12px;
    --lh-tight:   1.2;
    --lh-body:    1.6;
    --fw-regular: 400;
    --fw-medium:  500;
    --fw-semibold:600;
    --fw-bold:    700;
    --tracking-tight: -0.01em;
    --tracking-caps:   0.08em;
}

/* Dark theme -- same token names, inverted values (REQ-17.2) */
:root[data-theme="dark"] {
    --bg:             #1c1c1c;   /* near-black page (derived) */
    --surface:        #2b2b2b;   /* cards */
    --surface-2:      #363636;   /* subtle fills (derived) */
    --header-bg:      #161616;   /* near-black header */
    --header-text:    #ffffff;
    --header-muted:   #b3b3b3;

    --text:           #f0f0f0;   /* near-white ink */
    --text-muted:     #b3b3b3;   /* #B3B3B3 reads AA on dark surfaces */

    --border:         #3d3d3d;
    --border-strong:  #565656;

    --accent:         #ffffff;   /* light interactive ink in dark mode */
    --accent-hover:   #d4d4d4;
    --accent-contrast:#2b2b2b;

    --alert:          #e5685a;   /* lightened for contrast on dark (derived from #D14836) */
    --alert-bg:       #3a2522;
    --alert-border:   #7a3a33;

    --ring:           rgba(255, 255, 255, 0.22);
    --shadow:         0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px rgba(0, 0, 0, 0.45);
    --shadow-hover:   0 2px 8px rgba(0, 0, 0, 0.5);
}

/* 2. Reset & base ------------------------------------------------------ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

button, input, textarea, select {
    font: inherit;
    color: inherit;
}

html { color-scheme: light dark; }

body {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-family: var(--font-sans);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    font-weight: var(--fw-regular);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background 0.2s ease, color 0.2s ease;
}

[hidden] { display: none !important; }

/* 3. Header & nav ------------------------------------------------------ */
.app-header {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    background: var(--header-bg);
    color: var(--header-text);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.app-logo {
    font-size: 20px;
    font-weight: var(--fw-bold);
    letter-spacing: var(--tracking-tight);
    color: var(--header-text);
}

.app-logo-accent { color: var(--header-muted); font-weight: var(--fw-medium); }

.app-header-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.app-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-link {
    color: var(--header-text);
    text-decoration: none;
    font-size: var(--fs-label);
    font-weight: var(--fw-medium);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    transition: background 0.15s ease;
}

.nav-link:hover { background: rgba(255, 255, 255, 0.12); }

.nav-logout { color: var(--header-muted); }

/* Theme toggle -- always visible (login + authed screens). REQ-17.3 */
.theme-toggle {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    background: transparent;
    color: var(--header-text);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover { background: rgba(255, 255, 255, 0.12); }

.theme-toggle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3);
}

.theme-toggle-icon { font-size: 16px; line-height: 1; }

/* Icon reflects the theme you switch TO: moon in light, sun in dark. */
:root[data-theme="dark"] .theme-toggle-icon::before { content: "\2600"; }       /* sun  -> go light */
:root[data-theme="light"] .theme-toggle-icon::before,
:root:not([data-theme]) .theme-toggle-icon::before { content: "\263E"; }         /* moon -> go dark  */

/* 4. Content & cards --------------------------------------------------- */
.app-content {
    max-width: 760px;
    margin: 40px auto;
    padding: 0 24px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
}

.card-title {
    font-size: var(--fs-title);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
    letter-spacing: var(--tracking-tight);
    margin-bottom: 8px;
}

.placeholder-note {
    color: var(--text-muted);
    font-size: var(--fs-label);
    margin-top: 8px;
}

/* 5. Login form -------------------------------------------------------- */
.login-card { max-width: 420px; margin: 60px auto; }

.form-field { margin-top: 18px; }

.form-field label {
    display: block;
    font-size: var(--fs-label);
    font-weight: var(--fw-semibold);
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-field input {
    width: 100%;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: var(--fs-body);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-field input:focus {
    outline: none;
    border-color: var(--text);
    box-shadow: 0 0 0 3px var(--ring);
}

.login-form { margin-top: 8px; }

.form-error {
    margin-top: 14px;
    padding: 10px 12px;
    background: var(--alert-bg);
    border: 1px solid var(--alert-border);
    border-radius: var(--radius-sm);
    color: var(--alert);
    font-size: var(--fs-label);
}

.field-hint {
    margin-top: 8px;
    font-size: var(--fs-small);
    color: var(--text-muted);
}

/* 6. Buttons ----------------------------------------------------------- */
.btn {
    padding: 12px 18px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: var(--fs-label);
    font-weight: var(--fw-semibold);
    color: var(--accent-contrast);
    background: var(--accent);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: var(--shadow-hover);
}

.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

.btn:disabled,
.btn-disabled {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--surface-2);
    border-color: var(--text);
    box-shadow: none;
}

.btn-block { width: 100%; margin-top: 24px; }

/* 7. Chip buttons (onboarding / preferences) --------------------------- */
.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.chip {
    padding: 9px 16px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font-size: var(--fs-label);
    cursor: pointer;
    transition: all 0.15s ease;
}

.chip:hover { border-color: var(--text); }

.chip.selected {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

.onboarding-question { margin-top: 22px; }

.question-label {
    font-size: var(--fs-body);
    font-weight: var(--fw-semibold);
    color: var(--text);
}

/* 8. Query output panel ------------------------------------------------ */
.output-panel {
    margin-top: 24px;
    padding: 20px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    white-space: pre-wrap;
    line-height: var(--lh-body);
}

.output-label {
    font-size: var(--fs-small);
    font-weight: var(--fw-bold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps);
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* 9. Feedback buttons -------------------------------------------------- */
.feedback-row {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.feedback-btn {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.feedback-btn:hover { border-color: var(--text); }

.feedback-btn.selected {
    border-color: var(--text);
    background: var(--surface-2);
}

.feedback-btn:disabled { cursor: default; opacity: 0.85; }

/* Multi-line text input (query task box + feedback note) */
.text-input {
    width: 100%;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: var(--fs-body);
    font-family: inherit;
    resize: vertical;
    margin-top: 8px;
}

.text-input:focus {
    outline: none;
    border-color: var(--text);
    box-shadow: 0 0 0 3px var(--ring);
}

/* 10. Loading spinner -------------------------------------------------- */
.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 24px auto;
}

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

/* 11. Inline banner (e.g. personalization unavailable) -----------------
   Informational, not an error -- kept neutral so #D14836 stays reserved
   for true alerts (REQ-17.1). */
.banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 16px 0;
    padding: 12px 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: var(--fs-label);
    color: var(--text-muted);
}

.banner-dismiss {
    border: none;
    background: transparent;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
}

/* 12. Character counter ------------------------------------------------ */
.char-counter {
    margin-top: 6px;
    font-size: var(--fs-small);
    color: var(--text-muted);
    text-align: right;
}

/* 13. Error panel ------------------------------------------------------ */
.error-panel {
    max-width: 760px;
    margin: 16px auto 0;
    padding: 12px 18px;
    background: var(--alert-bg);
    border: 1px solid var(--alert-border);
    border-radius: var(--radius-sm);
    color: var(--alert);
    font-size: var(--fs-label);
}

/* 14. Notification toast ----------------------------------------------- */
.toast {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 1100;
    max-width: 320px;
    padding: 14px 18px;
    background: var(--accent);
    color: var(--accent-contrast);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: var(--fs-label);
    animation: toast-in 0.25s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* 15. Preferences view (Task 18) -------------------------------------- */
.pref-list {
    display: flex;
    flex-direction: column;
    margin-top: 20px;
}

.pref-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.pref-question {
    font-size: var(--fs-body);
    font-weight: var(--fw-semibold);
    color: var(--text);
}

.pref-value {
    font-size: var(--fs-body);
    font-weight: var(--fw-medium);
    color: var(--text);
    text-align: right;
}

.pref-value-empty {
    color: var(--text-muted);
    font-weight: var(--fw-regular);
    font-style: italic;
}
