/* ===== Theme Variables =====

   Palette shared with the parent panel (`apps/parent/static/parent.css`) — the
   Figma "solarpunk" frames. Both panels are the same product, so the surfaces,
   accents and shadows are the same values; only this file's variable *names*
   differ, because the teacher templates were written against them.

   The theme follows the OS/browser preference. There is no manual switcher:
   declaring both schemes stops Chrome's Auto Dark Theme from re-colouring a
   panel that already ships its own dark palette. */
:root {
    color-scheme: light dark;

    --bg-primary: #fffcf7;
    --bg-secondary: #fff8ec;
    --bg-tertiary: #f3eee4;
    --bg-hover: #fff3d4;
    --bg-input: #fff;

    --text-primary: #272727;
    --text-secondary: #3c3c3c;
    --text-tertiary: #3c3c3c;
    --text-on-primary: #1f1f1f;

    --border-primary: #ffe08c;
    --border-secondary: #ffc85c;
    --border-focus: #7ed672;

    --accent: #7ed672;
    --accent-hover: #5fbd55;
    --accent-subtle: #e3fadc;
    --accent-muted: rgba(126, 214, 114, .12);

    --danger: #7f1d1d;
    --danger-hover: #5f1515;
    --danger-subtle: #fff1f2;
    /* --danger is a deep red in light mode, so the dark --text-on-primary
       used by other buttons only reaches 1.65:1 on it. White gives 10:1. */
    --text-on-danger: #ffffff;

    --success: #18794e;
    --success-subtle: #e3fadc;

    --warning: #ffc85c;
    --warning-subtle: #fff3d4;

    --shadow-sm: 0 1px 2px rgba(34, 37, 40, .08);
    --shadow-md: 0 4px 8px rgba(34, 37, 40, .16);
    --shadow-lg: 0 8px 16px rgba(34, 37, 40, .22);
    --shadow-focus: 0 0 0 3px rgba(126, 214, 114, .3);

    --sidebar-bg: #fff8ec;
    --sidebar-text: #3c3c3c;
    --sidebar-text-secondary: #3c3c3c;
    --sidebar-item-hover: #fff3d4;
    --sidebar-item-active: #e3fadc;
    --sidebar-item-active-text: #136c43;
    --sidebar-border: #ffe08c;

    --chat-user-bg: #7ed672;
    --chat-user-text: #1f1f1f;
    --chat-assistant-bg: #fffcf7;
    --chat-assistant-border: #ffe08c;
    --chat-assistant-code-bg: #dcf0fa;
    --chat-assistant-pre-bg: #dcf0fa;
    --chat-assistant-pre-border: #7dcef4;
    --chat-messages-bg: #fff8ec;

    --nav-bg: rgba(255, 248, 236, .92);
    --nav-border: #ffe08c;

    --overlay: rgba(34, 37, 40, .16);

    --error-border: #fecaca;
    --link: #136c43;
}

/* Dark tokens from the "solarpunk_dark_mode_panel" frame: #222528 canvas,
   #2D3035 cards, #FFC85C accents kept identical across themes. */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #2d3035;
        --bg-secondary: #222528;
        --bg-tertiary: #34383e;
        --bg-hover: #4a3d21;
        --bg-input: #34383e;

        --text-primary: #f1f1f1;
        --text-secondary: #d9d9d9;
        --text-tertiary: #b8b8b8;
        --text-on-primary: #1f1f1f;

        --border-primary: #635332;
        --border-secondary: #d4a13f;
        --border-focus: #9bf47d;

        --accent: #7ed672;
        --accent-hover: #9bf47d;
        --accent-subtle: #31432f;
        --accent-muted: rgba(155, 244, 125, .15);

        --danger: #ffb4b4;
        --danger-hover: #ff8f8f;
        --danger-subtle: #3a2828;
        /* Inverted here: --danger is a light red on dark, so it needs dark ink. */
        --text-on-danger: #1f1f1f;

        --success: #9bf47d;
        --success-subtle: #31432f;

        --warning: #ffd98a;
        --warning-subtle: #4a3d21;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
        --shadow-md: 0 4px 8px rgba(0, 0, 0, .4);
        --shadow-lg: 0 8px 16px rgba(0, 0, 0, .48);
        --shadow-focus: 0 0 0 3px rgba(155, 244, 125, .3);

        --sidebar-bg: #222528;
        --sidebar-text: #d9d9d9;
        --sidebar-text-secondary: #b8b8b8;
        --sidebar-item-hover: #34383e;
        --sidebar-item-active: #31432f;
        --sidebar-item-active-text: #9bf47d;
        --sidebar-border: #635332;

        --chat-user-bg: #7ed672;
        --chat-user-text: #1f1f1f;
        --chat-assistant-bg: #2d3035;
        --chat-assistant-border: #635332;
        --chat-assistant-code-bg: #2c3c45;
        --chat-assistant-pre-bg: #2c3c45;
        --chat-assistant-pre-border: #7dcef4;
        --chat-messages-bg: #222528;

        --nav-bg: rgba(34, 37, 40, .92);
        --nav-border: #635332;

        --overlay: rgba(0, 0, 0, .4);

        --error-border: #7f3b3b;
        --link: #9bf47d;
    }
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    margin: 0;
    transition:
        background-color 0.2s,
        color 0.2s;
}

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

/* Links had no rule at all, so they fell back to the browser default blue
   (#0000EE), the one colour guaranteed to clash with the palette. */
a {
    color: var(--link);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.5rem;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    line-height: 1.4;
    white-space: nowrap;
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--accent);
    color: var(--text-on-primary);
    border-color: var(--accent);
}

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

.btn-danger {
    background-color: var(--danger);
    color: var(--text-on-danger);
    border-color: var(--danger);
}

.btn-danger:hover:not(:disabled),
.btn-danger:focus-visible {
    color: var(--text-on-danger);
}

.btn-danger:hover:not(:disabled) {
    background-color: var(--danger-hover);
    border-color: var(--danger-hover);
    box-shadow: var(--shadow-sm);
}

.btn-secondary {
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    border-color: var(--border-primary);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-secondary);
}

.btn-ghost {
    background-color: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-sm {
    padding: 0.3rem 0.625rem;
    font-size: 0.8125rem;
    border-radius: 0.375rem;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-primary);
    border-radius: 0.75rem;
    border: 1px solid var(--border-primary);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1rem;
    transition:
        background-color 0.2s,
        border-color 0.2s;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ===== Lists ===== */
.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem 0;
    border-bottom: 1px solid var(--border-primary);
}

.list-item:last-child {
    border-bottom: none;
}

.list-item-info {
    flex: 1;
}

.list-item-title {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.list-item-subtitle {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 0.125rem;
}

.list-item-actions {
    display: flex;
    gap: 0.5rem;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
    letter-spacing: 0.01em;
}

.form-label a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.form-label a:hover {
    color: var(--accent-hover);
}

.form-input,
.form-select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    border: 1px solid var(--border-primary);
    border-radius: 0.5rem;
    background-color: var(--bg-input);
    color: var(--text-primary);
    transition:
        border-color 0.15s,
        box-shadow 0.15s;
    line-height: 1.5;
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

.form-input:hover,
.form-select:hover {
    border-color: var(--border-secondary);
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: var(--shadow-focus);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M4.47 5.97a.75.75 0 0 1 1.06 0L8 8.44l2.47-2.47a.75.75 0 1 1 1.06 1.06l-3 3a.75.75 0 0 1-1.06 0l-3-3a.75.75 0 0 1 0-1.06z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

.form-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
}

.form-checkbox input[type="checkbox"] {
    width: 1.125rem;
    height: 1.125rem;
    margin-top: 0.125rem;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.form-checkbox label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
    cursor: pointer;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.1875rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
    letter-spacing: 0.01em;
}

.badge-success {
    background-color: var(--success-subtle);
    color: var(--success);
}

.badge-warning {
    background-color: var(--warning-subtle);
    color: var(--warning);
}

.badge-info {
    background-color: var(--accent-subtle);
    color: var(--accent);
}

/* ===== Page Header ===== */
.page-header {
    padding: 1.75rem 0 1rem;
}

.page-title {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-tertiary);
}

/* ===== Autocomplete ===== */
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    max-height: 200px;
    overflow-y: auto;
    z-index: 10;
}

.autocomplete-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-primary);
    transition: background-color 0.1s;
}

.autocomplete-item:hover {
    background: var(--bg-tertiary);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item-name {
    font-weight: 500;
    color: var(--text-primary);
}

.autocomplete-item-city {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ===== Copy Button ===== */
.copy-btn {
    display: none;
    position: absolute;
    bottom: -0.5rem;
    right: 2.375rem;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: 1px solid var(--border-primary);
    border-radius: 0.25rem;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    cursor: pointer;
    line-height: 1;
    text-align: center;
    align-items: center;
    justify-content: center;
}

.copy-btn:hover {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: var(--accent);
}

.copy-btn.copied {
    display: flex;
    color: var(--success, #22c55e);
    border-color: var(--success, #22c55e);
}

/* ===== Utilities ===== */
.text-center {
    text-align: center;
}
.text-right {
    text-align: right;
}
.mt-1 {
    margin-top: 0.25rem;
}
.mt-2 {
    margin-top: 0.5rem;
}
.mt-4 {
    margin-top: 1rem;
}
.mb-2 {
    margin-bottom: 0.5rem;
}
.mb-4 {
    margin-bottom: 1rem;
}
.relative {
    position: relative;
}

/* ===== Error Message ===== */
.error-message {
    background: var(--danger-subtle);
    color: var(--danger);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    border: 1px solid var(--error-border);
}

/* ===== Error Modal ===== */
.error-modal[hidden] {
    display: none;
}

.error-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    padding: 1rem;
}

.error-modal-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay);
    border: 0;
    cursor: pointer;
}

.error-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(28rem, 100%);
    margin: 12vh auto 0;
    padding: 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-md);
}

.error-modal-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

/* ===== Success Message ===== */
.success-message {
    background: var(--success-subtle);
    color: var(--success);
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    margin-top: 0.5rem;
    margin-bottom: 1rem;
}

/* ===== Warning Message ===== */
.warning-message {
    background: var(--warning-subtle);
    color: var(--warning);
    padding: 0.75rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

/* ===== HTMX Indicators ===== */
.htmx-indicator {
    opacity: 0;
    transition: opacity 0.2s;
}
.htmx-request .htmx-indicator {
    opacity: 1;
}
.htmx-request.htmx-indicator {
    opacity: 1;
}

/* ===== Auth Pages ===== */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background-color: var(--bg-secondary);
}

.auth-card {
    background: var(--bg-primary);
    border-radius: 0.75rem;
    border: 1px solid var(--border-primary);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    transition:
        background-color 0.2s,
        border-color 0.2s;
}

.auth-card.auth-card-wide {
    max-width: 500px;
}

.auth-title {
    font-size: 1.375rem;
    font-weight: 700;
    text-align: center;
    color: var(--accent);
    margin-bottom: 0.375rem;
    letter-spacing: -0.02em;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.9375rem;
}

.auth-btn {
    width: 100%;
    padding: 0.6875rem 1rem;
    font-size: 0.9375rem;
    font-weight: 600;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    background-color: var(--accent);
    color: var(--text-on-primary);
    transition:
        background-color 0.15s,
        box-shadow 0.15s;
}

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

.auth-btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.auth-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.auth-link {
    display: block;
    text-align: center;
    margin-top: 1rem;
    color: var(--text-tertiary);
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.15s;
}

.auth-link:hover {
    color: var(--accent);
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .page-header {
        padding: 1rem 0 0.75rem;
    }

    .page-title {
        font-size: 1.125rem;
    }

    .card {
        padding: 1rem;
    }

    .container {
        padding: 0 0.75rem;
    }

    .auth-card {
        padding: 1.5rem;
    }

    .auth-card.auth-card-wide {
        max-width: 100%;
    }
}

/* ===== Small layout utilities =====
   Used instead of inline `style=` attributes, which outrank media queries
   and previously broke the mobile nav. */
.stack-sm {
    margin-top: 0.75rem;
}

.stack-md {
    margin-top: 1rem;
}

.text-muted {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.text-error {
    color: var(--danger);
    font-size: 0.9rem;
    margin: 0.75rem 0 0;
}

.form-textarea {
    /* Inline-block leaves a baseline gap under the box, which pushed the
       submit button off-alignment on the feedback form. */
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 0.75rem;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font: inherit;
    resize: vertical;
}

.error-message.is-tight {
    margin-top: 0.5rem;
    margin-bottom: 0;
}

.font-normal {
    font-weight: 400;
}

.feedback-submit {
    margin-top: 0.75rem;
}
