/* ─────────────────────────────────────────────
   DasNote · base.css
   Shared design tokens, resets, and components
   ───────────────────────────────────────────── */

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

/* ── DESIGN TOKENS — LIGHT ──────────────────── */
:root {
    /* Brand */
    --brand:          #4338ca;
    --brand-light:    #eef2ff;
    --brand-mid:      #818cf8;
    --brand-dark:     #312e81;

    /* Surface */
    --surface:        #ffffff;
    --bg:             #f8f7f4;
    --bg-warm:        #faf9f6;
    --cream:          #f5f0e8;
    --cream-dark:     #ebe4d6;

    /* Text */
    --text:           #1e1b18;
    --text-muted:     #6b6760;
    --text-faint:     #a09d97;

    /* Border */
    --border:         #e5e3dc;
    --border-mid:     #d1cec4;
    --border-dark:    #b8b4aa;

    /* Semantic */
    --danger:         #dc2626;
    --danger-light:   #fef2f2;
    --danger-border:  #fca5a5;
    --success:        #059669;
    --success-light:  #ecfdf5;
    --highlight:      #fbbf24;

    /* Shadows */
    --shadow-sm:  0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:  0 4px 12px rgba(0,0,0,.09), 0 2px 4px rgba(0,0,0,.05);
    --shadow-lg:  0 12px 32px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.06);

    /* Typography */
    --font-ui:    'DM Sans', system-ui, sans-serif;
    --font-serif: 'Lora', Georgia, serif;

    /* Radii */
    --r-sm:  6px;
    --r-md:  10px;
    --r-lg:  14px;
    --r-xl:  20px;
}

/* ── DESIGN TOKENS — DARK ───────────────────── */
[data-theme="dark"] {
    --brand:          #6366f1;
    --brand-light:    #1e1b2e;
    --brand-mid:      #818cf8;
    --brand-dark:     #4338ca;

    --surface:        #1c1917;
    --bg:             #141210;
    --bg-warm:        #1a1816;
    --cream:          #252220;
    --cream-dark:     #2e2b28;

    --text:           #e8e4df;
    --text-muted:     #9d9893;
    --text-faint:     #6b6760;

    --border:         #2a2825;
    --border-mid:     #363330;
    --border-dark:    #46433f;

    --danger:         #f87171;
    --danger-light:   #2a1515;
    --danger-border:  #7f1d1d;
    --success:        #34d399;
    --success-light:  #052e16;
    --highlight:      #fbbf24;

    --shadow-sm:  0 1px 3px rgba(0,0,0,.35), 0 1px 2px rgba(0,0,0,.25);
    --shadow-md:  0 4px 12px rgba(0,0,0,.45), 0 2px 4px rgba(0,0,0,.30);
    --shadow-lg:  0 12px 32px rgba(0,0,0,.60), 0 4px 8px rgba(0,0,0,.40);
}

/* Smooth theme transitions — skip on initial load via .no-transition class */
html:not(.no-transition) *,
html:not(.no-transition) *::before,
html:not(.no-transition) *::after {
    transition: background-color .25s ease, border-color .25s ease, color .15s ease !important;
}

/* ── BASE ──────────────────────────────────── */
html, body {
    height: 100%;
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ── SCROLLBARS ────────────────────────────── */
::-webkit-scrollbar            { width: 6px; }
::-webkit-scrollbar-track      { background: transparent; }
::-webkit-scrollbar-thumb      { background: var(--border-mid); border-radius: 99px; }

/* ── SITE HEADER ────────────────────────────── */
.site-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 20px;
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Center slot — book title/author in the reader, empty everywhere else */
.site-header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
}

.site-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    text-decoration: none;
    color: var(--brand-dark);
}
.site-brand-icon {
    width: 28px;
    height: 28px;
    background: var(--brand);
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.site-brand-icon svg { color: white; }
.site-brand-name {
    font-family: var(--font-serif);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--brand-dark);
}

/* Compact brand variant used in the reader header */
.site-brand-sm .site-brand-icon { width: 24px; height: 24px; border-radius: 5px; }
.site-brand-sm .site-brand-icon svg { width: 13px; height: 13px; }
.site-brand-sm .site-brand-name { font-size: 17px; letter-spacing: -0.3px; }

/* Center metadata (book title / author) */
.site-header-title {
    font-family: var(--font-serif);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 380px;
}
.site-header-author { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }

.site-nav {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}
/* The <form> wrapping Sign out is block-level by default; collapse it so it
   participates in flexbox exactly like the adjacent inline items. */
.site-nav form { display: inline-flex; margin: 0; }
.site-nav .btn-ghost { padding-left: 6px; padding-right: 6px; }

/* ── BUTTONS ────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: var(--r-md);
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-ui);
    cursor: pointer;
    text-decoration: none;
    border: 1px solid transparent;
    transition: background .15s, color .15s, border-color .15s, transform .1s;
    white-space: nowrap;
}
.btn:active { transform: scale(.98); }

.btn-primary {
    background: var(--brand);
    color: white;
    border-color: var(--brand);
}
.btn-primary:hover {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
}

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

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

.btn-sm  { padding: 5px 12px;  font-size: 13px; }
.btn-lg  { padding: 12px 28px; font-size: 15px; font-weight: 600; }

/* ── FORMS ──────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 9px 13px;
    background: var(--bg-warm);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: 14px;
    font-family: var(--font-ui);
    color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    appearance: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
    border-color: var(--brand-mid);
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
    background: var(--surface);
}

input[type="file"] {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
}

.form-help  { font-size: 12px; color: var(--text-faint); }
.form-error { font-size: 12px; color: var(--danger); }

/* ── ALERTS ─────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--r-md);
    font-size: 13.5px;
    line-height: 1.5;
    border: 1px solid transparent;
}
.alert-danger  { background: var(--danger-light);  color: var(--danger);  border-color: var(--danger-border); }
.alert-success { background: var(--success-light); color: var(--success); border-color: #6ee7b7; }

/* ── CARD ───────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
}

/* ── PAGE WRAPPER ───────────────────────────── */
.page-wrap {
    min-height: calc(100vh - 60px);
    display: flex;
    flex-direction: column;
}

/* ── UTILITIES ──────────────────────────────── */
.hidden  { display: none !important; }
.sr-only {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip: rect(0,0,0,0);
}

/* ── THEME TOGGLE ───────────────────────────── */
.theme-toggle {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: var(--r-sm);
    background: var(--surface); cursor: pointer; color: var(--text-muted);
    transition: all .15s; flex-shrink: 0;
}
.theme-toggle:hover { background: var(--bg); color: var(--text); border-color: var(--border-mid); }

/* Show sun in dark mode, moon in light mode */
.icon-sun  { display: none; }
.icon-moon { display: block; }
[data-theme="dark"] .icon-sun  { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* ── PLAN BADGE ─────────────────────────────── */
.plan-badge {
    font-size: 11px; font-weight: 600; font-family: var(--font-ui);
    padding: 0 9px; height: 22px; line-height: 1;
    border-radius: 99px; letter-spacing: .04em; border: 1px solid;
    text-decoration: none; white-space: nowrap;
    display: inline-flex; align-items: center;
}
.plan-badge-premium {
    background: var(--brand-light); color: var(--brand); border-color: #c7d2fe;
}
.plan-badge-free {
    background: var(--cream); color: var(--text-muted); border-color: var(--border);
}

/* ── SCROLLBARS (dark mode aware) ───────────── */
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--border-mid); }

/* ─────────────────────────────────────────────
   AUTH PAGES (login, signup)
   ───────────────────────────────────────────── */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 60px);
    padding: 40px 24px;
    background: var(--bg-warm);
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-md);
    padding: 40px 44px;
    width: 100%;
    max-width: 420px;
    animation: fadeUp .35s ease both;
}
.auth-card.wide { max-width: 480px; }
.auth-card h1 {
    font-family: var(--font-serif);
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
    letter-spacing: -.3px;
}
.auth-card .sub { font-size: 14px; color: var(--text-muted); margin-bottom: 28px; }
.remember-row { display: flex; align-items: center; justify-content: space-between; }
.remember-row label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); cursor: pointer; }
.remember-row input[type=checkbox] { width: auto; accent-color: var(--brand); }
.forgot-link { font-size: 13px; color: var(--brand); text-decoration: none; }
.forgot-link:hover { text-decoration: underline; }
.auth-footer { text-align: center; font-size: 13px; color: var(--text-faint); margin-top: 20px; }
.auth-footer a { color: var(--brand); text-decoration: none; font-weight: 500; }
.auth-footer a:hover { text-decoration: underline; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: none; }
}

@media (max-width: 540px) {
    .auth-card { padding: 28px 20px; }
}

/* ─────────────────────────────────────────────
   PROFILE PAGE
   ───────────────────────────────────────────── */

.profile-wrap { max-width: 600px; margin: 0 auto; padding: 48px 32px 80px; }
.profile-wrap h1 {
    font-family: var(--font-serif);
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.4px;
    margin-bottom: 8px;
}
.profile-wrap .sub { font-size: 14px; color: var(--text-muted); margin-bottom: 32px; }
.profile-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 32px;
    box-shadow: var(--shadow-sm);
}
.profile-card h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.plan-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
}
.plan-chip.free    { background: var(--cream); color: var(--text-muted); border: 1px solid var(--border); }
.plan-chip.premium { background: var(--brand-light); color: var(--brand); border: 1px solid #c7d2fe; }

@media (max-width: 540px) {
    .profile-wrap { padding: 24px 16px 56px; }
}

/* ─────────────────────────────────────────────
   BILLING PAGE
   ───────────────────────────────────────────── */

.billing-wrap { max-width: 760px; margin: 0 auto; padding: 48px 32px 80px; }
.billing-wrap h1 {
    font-family: var(--font-serif);
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.4px;
    margin-bottom: 32px;
}

.plan-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 36px; }
.plan-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--r-lg);
    padding: 28px;
    position: relative;
}
.plan-card.current       { border-color: var(--brand-mid); box-shadow: 0 0 0 4px rgba(99,102,241,.08); }
.plan-card.premium-card  { background: var(--brand-dark); border-color: var(--brand-dark); }
.plan-card .plan-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    padding: 3px 9px;
    border-radius: 99px;
    margin-bottom: 16px;
}
.plan-card .plan-badge.free    { background: var(--cream); color: var(--text-muted); border: 1px solid var(--border); }
.plan-card .plan-badge.premium { background: rgba(255,255,255,.15); color: rgba(255,255,255,.9); }
.plan-name { font-family: var(--font-serif); font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.plan-card.premium-card .plan-name { color: white; }
.plan-price { font-family: var(--font-serif); font-size: 36px; font-weight: 700; color: var(--text); margin: 12px 0; }
.plan-card.premium-card .plan-price { color: white; }
.plan-price span { font-size: 14px; font-weight: 400; font-family: var(--font-ui); color: var(--text-muted); }
.plan-card.premium-card .plan-price span { color: rgba(255,255,255,.55); }
.plan-features { list-style: none; padding: 0; margin: 16px 0 24px; display: flex; flex-direction: column; gap: 10px; }
.plan-features li { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-muted); }
.plan-card.premium-card .plan-features li { color: rgba(255,255,255,.75); }
.plan-features li svg { flex-shrink: 0; }
.check-free    { color: var(--brand); }
.check-premium { color: #a78bfa; }

.usage-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 24px 28px; margin-bottom: 28px; }
.usage-section h2 { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 18px; }
.usage-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.usage-row:last-child { margin-bottom: 0; }
.usage-meta { display: flex; justify-content: space-between; font-size: 13px; }
.usage-label { color: var(--text); font-weight: 500; }
.usage-val   { color: var(--text-faint); }
.usage-track { height: 6px; background: var(--cream); border-radius: 99px; overflow: hidden; }
.usage-fill  { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--brand-mid), var(--brand)); transition: width .6s cubic-bezier(.4,0,.2,1); }
.usage-fill.at-limit { background: linear-gradient(90deg, #f87171, #dc2626); }

.feature-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 99px; }
.feature-tag.on  { background: #ecfdf5; color: #059669; border: 1px solid #6ee7b7; }
.feature-tag.off { background: var(--danger-light); color: var(--danger); border: 1px solid var(--danger-border); }

@media (max-width: 600px) {
    .plan-cards { grid-template-columns: 1fr; }
    .billing-wrap { padding: 24px 16px 56px; }
}

/* ─────────────────────────────────────────────
   UPLOAD PAGE
   ───────────────────────────────────────────── */

.upload-wrap {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 48px;
    max-width: 900px;
    margin: 0 auto;
    padding: 56px 32px 80px;
    width: 100%;
}
.upload-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-md);
    padding: 36px 40px;
    width: 100%;
    max-width: 440px;
    flex-shrink: 0;
    animation: fadeUp .35s ease both;
}
.upload-card-header { margin-bottom: 28px; }
.upload-card-header h2 {
    font-family: var(--font-serif);
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.3px;
    margin-bottom: 6px;
}
.upload-card-header p { font-size: 14px; color: var(--text-muted); line-height: 1.5; }
.upload-form { display: flex; flex-direction: column; gap: 20px; }

.file-drop-area {
    border: 2px dashed var(--border-mid);
    border-radius: var(--r-lg);
    padding: 28px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
    background: var(--bg-warm);
    position: relative;
}
.file-drop-area:hover,
.file-drop-area.drag-over { border-color: var(--brand-mid); background: var(--brand-light); }
.file-drop-area input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
    padding: 0;
}
.file-drop-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--r-md);
    background: var(--cream);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    color: var(--text-muted);
    transition: background .2s, color .2s;
}
.file-drop-area:hover .file-drop-icon { background: rgba(99,102,241,.12); color: var(--brand); }
.file-drop-label { font-size: 14px; font-weight: 500; color: var(--text-muted); margin-bottom: 4px; }
.file-drop-label strong { color: var(--brand); }
.file-drop-formats { font-size: 12px; color: var(--text-faint); }
.file-selected-name { font-size: 13px; font-weight: 500; color: var(--brand-dark); margin-top: 8px; display: none; }
.upload-submit { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
.upload-back { font-size: 13px; color: var(--text-faint); text-align: center; }
.upload-back a { color: var(--brand); text-decoration: none; font-weight: 500; }
.upload-back a:hover { text-decoration: underline; }

.upload-info { flex: 1; padding-top: 8px; min-width: 0; animation: fadeUp .35s .08s ease both; }
.upload-info-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-faint);
    margin-bottom: 16px;
}
.format-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 32px; }
.format-item { display: flex; align-items: flex-start; gap: 12px; }
.format-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .05em;
    padding: 3px 7px;
    border-radius: 4px;
    flex-shrink: 0;
    margin-top: 1px;
}
.format-badge-pdf  { background: #fff1f2; color: #e11d48; border: 1px solid #fecdd3; }
.format-badge-epub { background: #ecfeff; color: #0891b2; border: 1px solid #a5f3fc; }
.format-badge-docx { background: #eff6ff; color: #2563eb; border: 1px solid #bfdbfe; }
.format-badge-txt  { background: #f9fafb; color: #6b7280; border: 1px solid #e5e7eb; }
.format-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.format-desc strong { color: var(--text); font-weight: 500; }

@media (max-width: 700px) {
    .upload-wrap  { flex-direction: column; align-items: center; padding: 32px 16px 64px; }
    .upload-info  { display: none; }
    .upload-card  { padding: 28px 24px; }
}

/* ── SHARED FORM GRID ─────────────────────────── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 540px) { .form-row { grid-template-columns: 1fr; } }

/* ── UPGRADE MODAL (shared — used in reader + dashboard) ── */
.upgrade-modal-backdrop {
    position: fixed; inset: 0; z-index: 500;
    background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(3px);
    animation: upgrade-backdrop-in .15s ease;
}
.upgrade-modal-backdrop.hidden { display: none; }
@keyframes upgrade-backdrop-in { from { opacity: 0; } to { opacity: 1; } }
.upgrade-modal {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-xl); padding: 32px 28px 24px;
    max-width: 360px; width: calc(100% - 32px);
    box-shadow: var(--shadow-lg); text-align: center;
    animation: upgrade-modal-in .18s cubic-bezier(.34,1.56,.64,1);
}
@keyframes upgrade-modal-in { from { opacity: 0; transform: scale(.93) translateY(8px); } to { opacity: 1; transform: none; } }
.upgrade-modal-icon {
    width: 48px; height: 48px; background: var(--brand-light);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px; color: var(--brand);
}
.upgrade-modal-title { font-size: 17px; font-weight: 700; color: var(--text); margin-bottom: 8px; font-family: var(--font-ui); }
.upgrade-modal-body  { font-size: 13.5px; color: var(--text-muted); line-height: 1.6; margin-bottom: 22px; }
.upgrade-modal-actions { display: flex; flex-direction: column; gap: 8px; }
.upgrade-modal-cta {
    display: block; padding: 10px 20px; background: var(--brand); color: white;
    border-radius: var(--r-md); border: none; font-size: 14px; font-weight: 600;
    font-family: var(--font-ui); cursor: pointer; text-decoration: none; transition: background .15s;
}
.upgrade-modal-cta:hover { background: var(--brand-dark); }
.upgrade-modal-cancel {
    padding: 9px 20px; background: none; color: var(--text-faint);
    border: 1px solid var(--border); border-radius: var(--r-md);
    font-size: 13px; font-family: var(--font-ui); cursor: pointer; transition: all .15s;
}
.upgrade-modal-cancel:hover { background: var(--bg); color: var(--text-muted); }