/* =====================================================================
   SCRIPTORIUM — Core theme
   Dark-blue gradient + glass morphism
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;1,400;1,500&family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,400;0,9..144,500;0,9..144,600;0,9..144,700;1,9..144,300;1,9..144,400&family=Inter+Tight:wght@300;400;500;600;700&family=JetBrains+Mono:wght@300;400;500&family=Space+Grotesk:wght@300;400;500;600;700&display=swap');

:root {
    /* dark-blue gradient palette */
    --bg-0:     #050a1a;
    --bg-1:     #0a1530;
    --bg-2:     #0e1e44;
    --bg-3:     #142b5c;
    --bg-glow:  #1d4ed8;

    /* surfaces (glass) */
    --glass-bg:        rgba(20, 35, 75, 0.45);
    --glass-bg-soft:   rgba(20, 35, 75, 0.28);
    --glass-bg-strong: rgba(15, 28, 65, 0.7);
    --glass-border:    rgba(120, 160, 230, 0.18);
    --glass-border-strong: rgba(140, 180, 240, 0.32);
    --glass-shadow:    0 18px 60px rgba(0, 8, 30, 0.5);

    /* type */
    --text:        #e6efff;
    --text-soft:   #a4b6d8;
    --text-mute:   #6b7da0;
    --text-faint:  #4a5b80;

    /* accents */
    --accent:        #60a5fa;
    --accent-strong: #3b82f6;
    --accent-soft:   #93c5fd;
    --gold:          #d4b465;
    --green:         #34d399;
    --rose:          #fb7185;
    --amber:         #fbbf24;

    /* fonts */
    --f-display: 'Fraunces', serif;
    --f-ui:      'Space Grotesk', 'Inter Tight', system-ui, sans-serif;
    --f-mono:    'JetBrains Mono', ui-monospace, monospace;
    --f-serif:   'Cormorant Garamond', serif;

    /* misc */
    --r-sm: 8px;
    --r-md: 14px;
    --r-lg: 20px;
    --r-xl: 28px;
    --transition: 0.32s cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background: var(--bg-0);
    color: var(--text);
    font-family: var(--f-ui);
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

body {
    background:
        radial-gradient(ellipse 80% 60% at 20% 0%, rgba(59, 130, 246, 0.22), transparent 60%),
        radial-gradient(ellipse 70% 50% at 90% 20%, rgba(124, 58, 237, 0.16), transparent 65%),
        radial-gradient(ellipse 90% 80% at 50% 100%, rgba(29, 78, 216, 0.18), transparent 70%),
        linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 35%, var(--bg-2) 70%, var(--bg-1) 100%);
    background-attachment: fixed;
    overflow-x: hidden;
}

/* subtle stars / noise overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image:
        radial-gradient(1px 1px at 17% 23%, rgba(255,255,255,0.4), transparent 50%),
        radial-gradient(1px 1px at 76% 14%, rgba(255,255,255,0.35), transparent 50%),
        radial-gradient(1px 1px at 32% 67%, rgba(255,255,255,0.3), transparent 50%),
        radial-gradient(1px 1px at 88% 79%, rgba(255,255,255,0.4), transparent 50%),
        radial-gradient(1px 1px at 53% 41%, rgba(255,255,255,0.25), transparent 50%),
        radial-gradient(1px 1px at 12% 88%, rgba(255,255,255,0.3), transparent 50%),
        radial-gradient(1px 1px at 65% 92%, rgba(255,255,255,0.25), transparent 50%);
    background-size: 1200px 1200px;
    opacity: 0.6;
}

/* =====================================================================
   GLASS PRIMITIVES
   ===================================================================== */

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(24px) saturate(150%);
    -webkit-backdrop-filter: blur(24px) saturate(150%);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-lg);
    box-shadow: var(--glass-shadow);
}

.glass-strong {
    background: var(--glass-bg-strong);
    backdrop-filter: blur(28px) saturate(160%);
    -webkit-backdrop-filter: blur(28px) saturate(160%);
    border: 1px solid var(--glass-border-strong);
    border-radius: var(--r-lg);
    box-shadow: var(--glass-shadow);
}

.glass-soft {
    background: var(--glass-bg-soft);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-md);
}

/* =====================================================================
   TYPOGRAPHY
   ===================================================================== */

h1, h2, h3, h4 {
    font-family: var(--f-display);
    font-weight: 400;
    letter-spacing: -0.02em;
    line-height: 1.1;
    margin: 0 0 0.4em;
}
h1 { font-size: clamp(28px, 4vw, 48px); }
h2 { font-size: clamp(22px, 3vw, 32px); }
h3 { font-size: clamp(18px, 2vw, 22px); }

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

.label {
    font-family: var(--f-mono);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-mute);
}

.muted { color: var(--text-mute); }
.soft  { color: var(--text-soft); }

/* =====================================================================
   BUTTONS
   ===================================================================== */

.btn {
    --b-bg: rgba(255, 255, 255, 0.06);
    --b-border: rgba(255, 255, 255, 0.14);
    --b-color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 22px;
    font-family: var(--f-ui);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.01em;
    color: var(--b-color);
    background: var(--b-bg);
    border: 1px solid var(--b-border);
    border-radius: 999px;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    user-select: none;
    position: relative;
    overflow: hidden;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}

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

.btn-primary {
    --b-bg: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
    --b-border: transparent;
    --b-color: #fff;
    box-shadow: 0 8px 28px rgba(59, 130, 246, 0.35);
}
.btn-primary:hover {
    background: linear-gradient(135deg, #4d8fff 0%, #7475f7 100%);
    box-shadow: 0 12px 36px rgba(59, 130, 246, 0.5);
}

.btn-ghost { --b-bg: transparent; --b-border: rgba(255, 255, 255, 0.18); }

.btn-danger {
    --b-bg: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
    --b-border: transparent;
    --b-color: #fff;
    box-shadow: 0 8px 28px rgba(244, 63, 94, 0.3);
}

.btn-success {
    --b-bg: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --b-border: transparent;
    --b-color: #fff;
}

.btn-sm  { padding: 8px 14px; font-size: 12px; }
.btn-lg  { padding: 16px 32px; font-size: 16px; }

.btn[disabled], .btn.is-loading {
    opacity: 0.55;
    pointer-events: none;
}

.btn .spin {
    width: 14px; height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* =====================================================================
   FORM ELEMENTS
   ===================================================================== */

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 18px;
}
.field > label {
    font-family: var(--f-mono);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-mute);
}
.field-hint {
    font-size: 12px;
    color: var(--text-faint);
    font-style: italic;
}

input[type="text"], input[type="password"], input[type="email"], input[type="number"],
textarea, select {
    width: 100%;
    padding: 14px 16px;
    background: rgba(10, 20, 50, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-md);
    color: var(--text);
    font-family: var(--f-ui);
    font-size: 15px;
    transition: all var(--transition);
    outline: none;
}
textarea { resize: vertical; min-height: 100px; line-height: 1.5; }
input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    background: rgba(10, 20, 50, 0.7);
    box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.15);
}

input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

/* Toggle */
.toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}
.toggle input { display: none; }
.toggle .track {
    position: relative;
    width: 42px; height: 22px;
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    transition: var(--transition);
}
.toggle .track::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 16px; height: 16px;
    background: var(--text-mute);
    border-radius: 50%;
    transition: var(--transition);
}
.toggle input:checked + .track {
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    border-color: transparent;
}
.toggle input:checked + .track::after {
    transform: translateX(20px);
    background: #fff;
}
.toggle .label-text { font-size: 14px; }

/* =====================================================================
   PRELOADER
   ===================================================================== */

.preloader {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 28px;
    background:
        radial-gradient(ellipse at center, rgba(20, 40, 90, 0.95), rgba(5, 10, 26, 1));
    backdrop-filter: blur(8px);
    transition: opacity 0.5s, visibility 0.5s;
}
.preloader.hide { opacity: 0; visibility: hidden; pointer-events: none; }

.preloader-ring {
    position: relative;
    width: 80px;
    height: 80px;
}
.preloader-ring::before, .preloader-ring::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: var(--accent);
}
.preloader-ring::before {
    animation: spin 1.4s cubic-bezier(.4, 0, .6, 1) infinite;
}
.preloader-ring::after {
    inset: 12px;
    border-top-color: var(--accent-soft);
    animation: spin 0.9s cubic-bezier(.4, 0, .6, 1) infinite reverse;
}

.preloader-text {
    font-family: var(--f-mono);
    font-size: 11px;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    color: var(--text-soft);
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid var(--accent);
    animation: typing 2s steps(20) infinite, blink 0.6s steps(2) infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes typing { 0% { width: 0; } 60% { width: 100%; } 100% { width: 100%; } }
@keyframes blink  { 50% { border-color: transparent; } }

/* =====================================================================
   AI THINKING SPINNER (used while AI is "thinking")
   ===================================================================== */

.thinking {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    padding: 36px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-lg);
    backdrop-filter: blur(20px);
}
.thinking-orbs {
    position: relative;
    width: 120px;
    height: 60px;
}
.thinking-orbs span {
    position: absolute;
    top: 50%;
    width: 14px; height: 14px;
    border-radius: 50%;
    transform: translateY(-50%);
    background: var(--accent);
    box-shadow: 0 0 20px var(--accent);
    animation: orb 1.4s cubic-bezier(.4, 0, .6, 1) infinite;
}
.thinking-orbs span:nth-child(1) { left: 0;  animation-delay: 0s;    background: #60a5fa; box-shadow: 0 0 20px #60a5fa; }
.thinking-orbs span:nth-child(2) { left: 40%; animation-delay: 0.18s; background: #818cf8; box-shadow: 0 0 20px #818cf8; }
.thinking-orbs span:nth-child(3) { left: 80%; animation-delay: 0.36s; background: #a78bfa; box-shadow: 0 0 20px #a78bfa; }
@keyframes orb {
    0%, 100% { transform: translateY(-50%) scale(1); opacity: 1; }
    50%      { transform: translateY(-180%) scale(0.6); opacity: 0.5; }
}

.thinking-progress {
    width: 240px;
    height: 4px;
    background: rgba(255,255,255,0.08);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}
.thinking-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #60a5fa, #a78bfa);
    border-radius: inherit;
    width: 0;
    transition: width 0.3s ease-out;
    box-shadow: 0 0 12px rgba(96,165,250,0.6);
}
.thinking-percent {
    font-family: var(--f-mono);
    font-size: 11px;
    letter-spacing: 0.2em;
    color: var(--text-soft);
}
.thinking-status {
    font-family: var(--f-display);
    font-style: italic;
    font-size: 18px;
    color: var(--text);
    text-align: center;
    min-height: 28px;
}
.thinking-substatus {
    font-family: var(--f-mono);
    font-size: 10px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-mute);
}

/* =====================================================================
   TOAST
   ===================================================================== */

#toast-stack {
    position: fixed;
    bottom: 24px; right: 24px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 360px;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    padding: 14px 18px;
    background: var(--glass-bg-strong);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border-strong);
    border-radius: var(--r-md);
    color: var(--text);
    font-size: 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: toast-in 0.32s cubic-bezier(.2, .8, .2, 1);
}
.toast.out { animation: toast-out 0.32s cubic-bezier(.2, .8, .2, 1) forwards; }
.toast .icon { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--rose); }
.toast.info    { border-left: 3px solid var(--accent); }
.toast.warn    { border-left: 3px solid var(--amber); }

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

/* =====================================================================
   MODAL
   ===================================================================== */

.modal-backdrop {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(5, 10, 26, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.32s, visibility 0.32s;
}
.modal-backdrop.show { opacity: 1; visibility: visible; }
.modal {
    background: var(--glass-bg-strong);
    backdrop-filter: blur(28px);
    border: 1px solid var(--glass-border-strong);
    border-radius: var(--r-xl);
    padding: 32px;
    max-width: 560px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(20px) scale(0.96);
    transition: transform 0.32s cubic-bezier(.2,.8,.2,1);
    box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.modal-backdrop.show .modal { transform: translateY(0) scale(1); }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; flex-wrap: wrap; }

/* =====================================================================
   APP HEADER (top nav)
   ===================================================================== */

.appbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: rgba(5, 12, 32, 0.55);
    backdrop-filter: blur(28px) saturate(170%);
    -webkit-backdrop-filter: blur(28px) saturate(170%);
    border-bottom: 1px solid var(--glass-border);
}
.appbar-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    font-family: var(--f-display);
    font-weight: 500;
    font-size: 22px;
    letter-spacing: -0.01em;
    color: var(--text);
}
.appbar-brand .mark {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--f-display);
    font-style: italic;
    color: #fff;
    font-size: 18px;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}
.appbar-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}
.appbar-nav a {
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-soft);
    border-radius: 999px;
    transition: var(--transition);
}
.appbar-nav a:hover { background: rgba(255,255,255,0.06); color: var(--text); }
.appbar-nav a.active {
    background: rgba(96, 165, 250, 0.15);
    color: var(--accent-soft);
}
.appbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-soft);
}
.appbar-user .avatar {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, #475569, #1e293b);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--f-mono);
    font-size: 12px;
    color: var(--text);
    border: 1px solid var(--glass-border);
}

/* =====================================================================
   UTILITIES
   ===================================================================== */

.container { max-width: 1280px; margin: 0 auto; padding: 32px; position: relative; z-index: 1; }
.container-narrow { max-width: 720px; margin: 0 auto; padding: 32px; position: relative; z-index: 1; }

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.text-center { text-align: center; }

.mt-8  { margin-top: 8px; }  .mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; } .mt-40 { margin-top: 40px; }
.mb-8  { margin-bottom: 8px; }  .mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; } .mb-40 { margin-bottom: 40px; }

.hidden { display: none !important; }

.divider {
    height: 1px;
    background: var(--glass-border);
    margin: 24px 0;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--glass-border);
    font-family: var(--f-mono);
    font-size: 10px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-soft);
}
.pill.green  { background: rgba(52, 211, 153, 0.12); border-color: rgba(52, 211, 153, 0.3); color: var(--green); }
.pill.amber  { background: rgba(251, 191, 36, 0.12); border-color: rgba(251, 191, 36, 0.3); color: var(--amber); }
.pill.rose   { background: rgba(251, 113, 133, 0.12); border-color: rgba(251, 113, 133, 0.3); color: var(--rose); }
.pill.accent { background: rgba(96, 165, 250, 0.12); border-color: rgba(96, 165, 250, 0.3); color: var(--accent-soft); }

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: rgba(5,10,26,0.4); }
::-webkit-scrollbar-thumb { background: rgba(120, 160, 230, 0.18); border-radius: 999px; border: 3px solid var(--bg-0); }
::-webkit-scrollbar-thumb:hover { background: rgba(140, 180, 240, 0.32); }

/* selection */
::selection { background: rgba(96, 165, 250, 0.4); color: #fff; }
