/* ==========================================================================
   MakeShift AI — "Ink & Signal" design system
   Shared tokens + primitives used by every page.
   Load order: theme.css first, then the page stylesheet (app/auth/admin).
   ========================================================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* ----- Type ----- */
    --font-display: 'Bricolage Grotesque', 'Instrument Sans', system-ui, sans-serif;
    --font-body: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', 'Monaco', monospace;

    /* ----- Ink (dark chrome) ----- */
    --ink-950: #060b16;
    --ink-900: #0a1322;
    --ink-850: #0d182c;
    --ink-800: #111f38;
    --ink-700: #1a2c4d;
    --ink-600: #273c63;
    --ink-text: #e9eff9;
    --ink-text-dim: #93a5c4;
    --ink-text-faint: #5d6f90;
    --ink-border: rgba(122, 162, 247, 0.16);

    /* ----- Surface (light content) ----- */
    --bg-primary: #ffffff;
    --bg-secondary: #f4f7fb;
    --bg-tertiary: #e9eef6;
    --text-primary: #101828;
    --text-secondary: #51617c;
    --text-tertiary: #8e9cb3;
    --border: #dfe6f0;
    --border-light: #e8edf5;
    --border-color: #dfe6f0; /* legacy alias — index.js injects styles using it */

    /* ----- Page stage — tinted background behind content (never flat) ----- */
    --page-base: #e9eff9;
    --page-glow-1: rgba(69, 193, 230, 0.22);   /* cyan, top-right */
    --page-glow-2: rgba(37, 99, 235, 0.13);    /* azure, bottom-left */
    --page-glow-3: rgba(130, 80, 255, 0.07);   /* violet whisper, bottom-right */

    /* ----- Rail (conversations sidebar) — themed: light here, ink in dark mode ----- */
    --rail-bg: #e7eefb;
    --rail-glow-1: rgba(69, 193, 230, 0.22);
    --rail-glow-2: rgba(37, 99, 235, 0.12);
    --rail-dots: rgba(16, 24, 40, 0.08);
    --rail-text: #101828;
    --rail-text-dim: #51617c;
    --rail-text-faint: #8e9cb3;
    --rail-border: #dfe6f0;
    --rail-hover: rgba(16, 24, 40, 0.05);
    --rail-card-bg: #ffffff;
    --rail-input-bg: #ffffff;
    --rail-input-focus-bg: #ffffff;

    /* ----- Signal (accent) ----- */
    --accent: #1583d6;
    --accent-hover: #106cb4;
    --accent-light: #e3f2fd;
    --accent-lighter: #f0f8ff;
    --signal: #45c1e6;
    --signal-deep: #172d8e;
    --grad-signal: linear-gradient(135deg, #45c1e6 0%, #2563eb 100%);
    --grad-brand: linear-gradient(135deg, #45c1e6 0%, #172d8e 100%);

    /* ----- Semantic ----- */
    --success: #0e9f6e;
    --success-bg: #e3f6ef;
    --success-border: #a7dcc6;
    --success-text: #14724f;
    --warning: #d97706;
    --warning-bg: #fdf3e3;
    --warning-border: #f1c478;
    --warning-text: #7a4a07;
    --danger: #e02d3c;
    --danger-hover: #c01f2d;
    --danger-bg: #fdebec;
    --danger-border: #f5c2c7;
    --danger-text: #99232f;

    /* ----- Geometry ----- */
    --radius-sm: 7px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    /* ----- Elevation ----- */
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 3px 8px -2px rgba(16, 24, 40, 0.1), 0 1px 3px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 12px 24px -6px rgba(16, 24, 40, 0.14), 0 4px 8px -4px rgba(16, 24, 40, 0.08);
    --shadow-xl: 0 24px 48px -12px rgba(16, 24, 40, 0.22);
    --shadow-glow: 0 0 0 1px rgba(69, 193, 230, 0.25), 0 4px 20px -2px rgba(69, 193, 230, 0.35);

    /* ----- Motion ----- */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==========================================================================
   Dark mode — flips the light "surface" tokens; the ink chrome (sidebar,
   top bars, auth pages) is already dark and stays constant.
   Toggled via html[data-theme="dark"] (see static/js/theme.js).
   ========================================================================== */

html[data-theme="dark"] {
    color-scheme: dark;

    --bg-primary: #101c33;
    --bg-secondary: #0b1426;
    --bg-tertiary: #1b2a4a;
    --text-primary: #e9eff9;
    --text-secondary: #a7b6d2;
    --text-tertiary: #6c7e9f;
    --border: #25375d;
    --border-light: #1d2c4b;
    --border-color: #25375d;

    --accent: #4cb8ec;
    --accent-hover: #6cc8f2;
    --accent-light: rgba(69, 193, 230, 0.15);
    --accent-lighter: rgba(69, 193, 230, 0.07);

    --page-base: #0b1426;
    --page-glow-1: rgba(69, 193, 230, 0.24);
    --page-glow-2: rgba(37, 99, 235, 0.34);
    --page-glow-3: rgba(130, 80, 255, 0.22);

    --rail-bg: var(--ink-900);
    --rail-glow-1: rgba(69, 193, 230, 0.2);
    --rail-glow-2: rgba(37, 99, 235, 0.26);
    --rail-dots: rgba(147, 165, 196, 0.13);
    --rail-text: var(--ink-text);
    --rail-text-dim: var(--ink-text-dim);
    --rail-text-faint: var(--ink-text-faint);
    --rail-border: var(--ink-border);
    --rail-hover: rgba(255, 255, 255, 0.05);
    --rail-card-bg: rgba(255, 255, 255, 0.03);
    --rail-input-bg: rgba(255, 255, 255, 0.05);
    --rail-input-focus-bg: rgba(255, 255, 255, 0.07);

    --success-bg: rgba(16, 185, 129, 0.13);
    --success-border: rgba(110, 231, 183, 0.32);
    --success-text: #7fe3bd;
    --warning-bg: rgba(217, 119, 6, 0.15);
    --warning-border: rgba(241, 196, 120, 0.32);
    --warning-text: #f5c87c;
    --danger-bg: rgba(224, 45, 60, 0.15);
    --danger-border: rgba(255, 140, 150, 0.32);
    --danger-text: #ff9aa3;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 3px 8px -2px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 24px -6px rgba(0, 0, 0, 0.55), 0 4px 8px -4px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 24px 48px -12px rgba(0, 0, 0, 0.7);
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    color: var(--text-primary);
    background: var(--bg-secondary);
}

/* ==========================================================================
   Dark chrome texture — dot grid + aurora glow, used on ink surfaces
   ========================================================================== */

.ink-surface {
    position: relative;
    background:
        radial-gradient(900px 500px at 85% -10%, rgba(69, 193, 230, 0.13), transparent 60%),
        radial-gradient(700px 600px at -15% 110%, rgba(37, 99, 235, 0.16), transparent 55%),
        var(--ink-900);
}

.ink-surface::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(147, 165, 196, 0.13) 1px, transparent 1px);
    background-size: 22px 22px;
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.25));
    -webkit-mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.25));
    pointer-events: none;
}

/* ==========================================================================
   Brand wordmark
   ========================================================================== */

/* The real MakeShift wordmark lettering (static/img/makeshift-wordmark.svg),
   rendered via mask so it takes the surrounding text colour in both themes.
   Height is em-based: it scales with the parent heading's font-size. */
.brand-wordmark {
    display: inline-block;
    height: 0.95em;
    aspect-ratio: 131.3 / 21.73;
    background: currentColor;
    mask: url('/static/img/makeshift-wordmark.svg') no-repeat center / contain;
    -webkit-mask: url('/static/img/makeshift-wordmark.svg') no-repeat center / contain;
    flex-shrink: 0;
}

.brand-ai {
    font-size: 1.22em;
    line-height: 1;
    font-weight: 800;
    background: var(--grad-signal);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 18px;
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.005em;
    color: #fff;
    background: var(--grad-signal);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    white-space: nowrap;
    transition: transform 0.15s var(--ease-out), box-shadow 0.2s, filter 0.2s;
    box-shadow: var(--shadow-sm);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
    filter: brightness(1.05);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    filter: none;
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    box-shadow: var(--shadow-md);
    color: var(--text-primary);
    filter: none;
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-hover);
    box-shadow: 0 4px 14px -2px rgba(224, 45, 60, 0.45);
    filter: none;
}

.btn-sm {
    padding: 5px 12px;
    font-size: 0.78rem;
    border-radius: var(--radius-sm);
}

/* ==========================================================================
   Forms
   ========================================================================== */

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 7px;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 0.01em;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="search"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 0.92rem;
    color: var(--text-primary);
    background: var(--bg-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--signal);
    box-shadow: 0 0 0 3px rgba(69, 193, 230, 0.18);
}

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

.form-hint {
    display: block;
    margin-top: 5px;
    font-size: 0.78rem;
    color: var(--text-tertiary);
    line-height: 1.45;
}

.mono {
    font-family: var(--font-mono);
}

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    line-height: 1.5;
}

/* ==========================================================================
   Modals — index pages toggle `.active`, admin pages toggle `.show`
   ========================================================================== */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(8, 14, 26, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal.active,
.modal.show {
    display: flex;
    animation: modal-fade 0.18s ease-out;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xl);
    padding: 28px 30px;
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    overflow-y: auto;
    animation: modal-rise 0.22s var(--ease-out);
}

.modal-content.large {
    max-width: 760px;
}

.modal-content h2 {
    font-family: var(--font-display);
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.015em;
    margin-bottom: 18px;
    color: var(--text-primary);
}

.modal .close {
    float: right;
    font-size: 1.5rem;
    line-height: 1;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-tertiary);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
}

.modal .close:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

@keyframes modal-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modal-rise {
    from { opacity: 0; transform: translateY(14px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ==========================================================================
   Toast — injected by index.js (showAlertPopup)
   ========================================================================== */

.alert-popup {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
    border-left: 4px solid var(--warning);
    color: var(--warning-text);
    padding: 14px 44px 14px 16px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    font-weight: 500;
    max-width: 420px;
    animation: toast-in 0.32s var(--ease-out);
}

.alert-popup .alert-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    color: inherit;
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.65;
}

.alert-popup .alert-close:hover {
    opacity: 1;
}

@keyframes toast-in {
    from { transform: translateX(110%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ==========================================================================
   Spinners & loading
   ========================================================================== */

.spinner {
    display: inline-block;
    width: 15px;
    height: 15px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.7s linear infinite;
    margin-left: 8px;
    vertical-align: -2px;
}

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

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 36px 16px;
    color: var(--text-tertiary);
    font-size: 0.875rem;
}

.loading-spinner::before {
    content: '';
    width: 26px;
    height: 26px;
    border: 3px solid var(--border);
    border-top-color: var(--signal);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ==========================================================================
   Shared utilities
   ========================================================================== */

.hidden {
    display: none !important;
}

.error-message {
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger-text);
    padding: 12px 14px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    line-height: 1.5;
}

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-tertiary);
}

.empty-state-icon {
    font-size: 2.2rem;
    margin-bottom: 12px;
    filter: grayscale(0.25);
}

.empty-state-text {
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(110, 130, 165, 0.35);
    border-radius: 99px;
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: rgba(110, 130, 165, 0.6);
}

::selection {
    background: rgba(69, 193, 230, 0.3);
}

/* ==========================================================================
   Mobile — tighten modal chrome so dialogs use the small screen well
   ========================================================================== */

@media (max-width: 768px) {
    .modal {
        padding: 12px;
    }

    .modal-content {
        padding: 22px 18px;
        max-height: 92vh;
        max-height: 92dvh;
    }
}
