/* ===================================================
   PrepForge — Global CSS
   Design system: notebook / journal aesthetic
   =================================================== */

@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;600;700&family=Crimson+Pro:ital,wght@0,400;0,600;1,400&family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ─── Reset ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: var(--font-ui); background: var(--bg-main); color: var(--ink-primary); min-height: 100vh; transition: background 0.3s, color 0.3s; }
img, svg { display: block; max-width: 100%; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, textarea, select { font-family: inherit; }
a { text-decoration: none; color: inherit; }
ul, ol { list-style: none; }

/* ─── CSS Variables — Light Mode ────────────────────── */
:root {
    /* Paper */
    --bg-main:         #f5f1e8;
    --bg-paper:        #faf8f2;
    --bg-card:         #fffef9;
    --bg-sidebar:      #1e1b2e;
    --bg-topbar:       #fffef9;
    --bg-input:        #ffffff;
    --bg-hover:        #f0ece0;
    --bg-code:         #f4f0e4;
    --bg-modal:        rgba(10,8,20,0.55);

    /* Ruling */
    --rule-color:      #d4cfc0;
    --rule-margin:     #e8a0a0;
    --rule-spacing:    32px;

    /* Ink */
    --ink-primary:     #1a1530;
    --ink-secondary:   #4a4468;
    --ink-muted:       #8880a8;
    --ink-placeholder: #b0aacc;

    /* Accent palette */
    --accent-amber:    #d97706;
    --accent-amber-bg: #fef3c7;
    --accent-blue:     #2563eb;
    --accent-blue-bg:  #dbeafe;
    --accent-green:    #16a34a;
    --accent-green-bg: #dcfce7;
    --accent-red:      #dc2626;
    --accent-red-bg:   #fee2e2;
    --accent-purple:   #7c3aed;
    --accent-purple-bg:#ede9fe;
    --accent-teal:     #0d9488;
    --accent-teal-bg:  #ccfbf1;

    /* Primary accent (blue ink) */
    --accent:          #2563eb;
    --accent-hover:    #1d4ed8;
    --accent-light:    #dbeafe;

    /* Borders */
    --border:          #d4cfc0;
    --border-strong:   #b0a898;
    --border-focus:    #2563eb;

    /* Shadows */
    --shadow-sm:       0 1px 3px rgba(30,24,60,0.06), 0 1px 2px rgba(30,24,60,0.04);
    --shadow-md:       0 4px 12px rgba(30,24,60,0.10), 0 2px 4px rgba(30,24,60,0.06);
    --shadow-lg:       0 8px 32px rgba(30,24,60,0.14), 0 4px 8px rgba(30,24,60,0.08);
    --shadow-paper:    2px 4px 16px rgba(30,24,60,0.10);

    /* Radius */
    --radius-sm:       6px;
    --radius-md:       10px;
    --radius-lg:       16px;
    --radius-xl:       24px;
    --radius-full:     9999px;

    /* Typography */
    --font-ui:         'Inter', system-ui, sans-serif;
    --font-body:       'Crimson Pro', Georgia, serif;
    --font-mono:       'JetBrains Mono', monospace;
    --font-heading:    'Caveat', cursive;

    /* Transitions */
    --transition:      0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    /* Sidebar */
    --sidebar-width:   260px;
    --sidebar-collapsed: 0px;
    --topbar-height:   60px;
}

/* ─── Dark Mode ─────────────────────────────────────── */
[data-theme="dark"] {
    --bg-main:         #0f0d1a;
    --bg-paper:        #151225;
    --bg-card:         #1a1730;
    --bg-sidebar:      #0a0817;
    --bg-topbar:       #141122;
    --bg-input:        #1e1b30;
    --bg-hover:        #221f38;
    --bg-code:         #0d0b18;
    --bg-modal:        rgba(0,0,0,0.72);

    --rule-color:      #2a2640;
    --rule-margin:     #6b3535;

    --ink-primary:     #e8e4f8;
    --ink-secondary:   #a09cc0;
    --ink-muted:       #6860a0;
    --ink-placeholder: #4a4470;

    --accent-amber-bg: #2d1f00;
    --accent-blue-bg:  #0f1f4a;
    --accent-green-bg: #0a2018;
    --accent-red-bg:   #2d0a0a;
    --accent-purple-bg:#1a0f3d;
    --accent-teal-bg:  #002824;

    --border:          #2a2640;
    --border-strong:   #3d3860;

    --shadow-sm:       0 1px 3px rgba(0,0,0,0.3);
    --shadow-md:       0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg:       0 8px 32px rgba(0,0,0,0.5);
    --shadow-paper:    2px 4px 16px rgba(0,0,0,0.4);
}

/* ─── Utility Classes ───────────────────────────────── */
.hidden        { display: none !important; }
.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1         { gap: 0.25rem; }
.gap-2         { gap: 0.5rem; }
.gap-3         { gap: 0.75rem; }
.gap-4         { gap: 1rem; }
.gap-6         { gap: 1.5rem; }
.w-full        { width: 100%; }
.text-center   { text-align: center; }
.truncate      { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relative      { position: relative; }
.absolute      { position: absolute; }

/* ─── Typography ────────────────────────────────────── */
h1, h2, h3 { color: var(--ink-primary); line-height: 1.2; }
.heading-display {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    color: var(--ink-primary);
}
.heading-section {
    font-family: var(--font-ui);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--ink-primary);
}
.text-muted   { color: var(--ink-muted); font-size: 0.85rem; }
.text-sm      { font-size: 0.875rem; }
.text-xs      { font-size: 0.75rem; }
.font-mono    { font-family: var(--font-mono); }
.font-heading { font-family: var(--font-heading); }

/* ─── Buttons ───────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
    white-space: nowrap;
    border: 1px solid transparent;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-secondary {
    background: var(--bg-hover);
    color: var(--ink-primary);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--border); transform: translateY(-1px); }
.btn-danger {
    background: var(--accent-red-bg);
    color: var(--accent-red);
    border-color: var(--accent-red);
}
.btn-danger:hover { background: var(--accent-red); color: #fff; }
.btn-ghost {
    background: transparent;
    color: var(--ink-secondary);
    border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--ink-primary); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-icon { padding: 0.5rem; border-radius: var(--radius-sm); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ─── Inputs ────────────────────────────────────────── */
.input, .textarea, .select {
    width: 100%;
    padding: 0.6rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--ink-primary);
    font-size: 0.9rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}
.input:focus, .textarea:focus, .select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-placeholder); }
.textarea { resize: vertical; min-height: 100px; line-height: 1.6; }
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-label { font-size: 0.8rem; font-weight: 500; color: var(--ink-secondary); text-transform: uppercase; letter-spacing: 0.05em; }

/* ─── Badges ────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-full);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.badge-blue    { background: var(--accent-blue-bg);   color: var(--accent-blue);   }
.badge-green   { background: var(--accent-green-bg);  color: var(--accent-green);  }
.badge-red     { background: var(--accent-red-bg);    color: var(--accent-red);    }
.badge-amber   { background: var(--accent-amber-bg);  color: var(--accent-amber);  }
.badge-purple  { background: var(--accent-purple-bg); color: var(--accent-purple); }
.badge-teal    { background: var(--accent-teal-bg);   color: var(--accent-teal);   }
.badge-gray    { background: var(--bg-hover);         color: var(--ink-secondary); }

/* ─── Cards ─────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.75rem; }
.card-title { font-weight: 600; font-size: 1rem; color: var(--ink-primary); line-height: 1.3; }
.card-meta   { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
.card-body   { color: var(--ink-secondary); font-size: 0.9rem; line-height: 1.6; }
.card-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }

/* ─── Tag / Chip ─────────────────────────────────────── */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.5rem;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 0.72rem;
    color: var(--ink-secondary);
    cursor: default;
}
.tag-removable { cursor: pointer; }
.tag-removable:hover { background: var(--accent-red-bg); border-color: var(--accent-red); color: var(--accent-red); }

/* ─── Divider ────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 1rem 0; }

/* ─── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-muted); }

/* ─── Markdown Content ───────────────────────────────── */
.md-content { font-family: var(--font-body); font-size: 1.05rem; line-height: 1.8; color: var(--ink-primary); }
.md-content h1 { font-size: 1.8rem; margin: 1.5rem 0 0.75rem; font-family: var(--font-heading); }
.md-content h2 { font-size: 1.4rem; margin: 1.25rem 0 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.25rem; }
.md-content h3 { font-size: 1.15rem; margin: 1rem 0 0.4rem; color: var(--ink-secondary); }
.md-content p  { margin: 0.75rem 0; }
.md-content ul, .md-content ol { margin: 0.5rem 0 0.5rem 1.5rem; }
.md-content li { margin: 0.3rem 0; }
.md-content code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--bg-code);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    border: 1px solid var(--border);
}
.md-content pre {
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1rem;
    overflow-x: auto;
    margin: 1rem 0;
}
.md-content pre code { background: none; border: none; padding: 0; font-size: 0.875rem; }
.md-content blockquote {
    border-left: 3px solid var(--accent-amber);
    padding: 0.5rem 1rem;
    margin: 1rem 0;
    background: var(--accent-amber-bg);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    font-style: italic;
}
.md-content table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.md-content th, .md-content td { padding: 0.5rem 0.75rem; border: 1px solid var(--border); text-align: left; }
.md-content th { background: var(--bg-hover); font-weight: 600; }
.md-content a { color: var(--accent); text-decoration: underline; }
.md-content hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ─── Empty State ────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 4rem 2rem;
    text-align: center;
    color: var(--ink-muted);
}
.empty-state-icon { font-size: 3rem; opacity: 0.4; }
.empty-state h3   { font-size: 1.1rem; color: var(--ink-secondary); font-weight: 500; }
.empty-state p    { font-size: 0.9rem; max-width: 300px; }

/* ─── Section Header ─────────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.section-title {
    font-family: var(--font-heading);
    font-size: 2rem;
    color: var(--ink-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ─── Toast ──────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    min-width: 240px;
    animation: slideInRight 0.3s ease;
    color: var(--ink-primary);
}
.toast-success { border-left: 4px solid var(--accent-green); }
.toast-error   { border-left: 4px solid var(--accent-red); }
.toast-info    { border-left: 4px solid var(--accent-blue); }
.toast.leaving { animation: slideOutRight 0.3s ease forwards; }

/* ─── Modal ──────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-modal);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-title { font-family: var(--font-heading); font-size: 1.5rem; }
.modal-body  { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-lg { max-width: 900px; }
.modal-xl { max-width: 1100px; }

/* ─── Search Bar ─────────────────────────────────────── */
.search-bar {
    position: relative;
    flex: 1;
    max-width: 400px;
}
.search-bar input {
    width: 100%;
    padding: 0.55rem 0.9rem 0.55rem 2.4rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--bg-input);
    color: var(--ink-primary);
    font-size: 0.875rem;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.search-bar input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.search-bar .search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ink-muted);
    pointer-events: none;
    font-size: 0.875rem;
}

/* ─── Filter Row ─────────────────────────────────────── */
.filter-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.filter-chip {
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-full);
    border: 1.5px solid var(--border);
    background: var(--bg-card);
    color: var(--ink-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}
.filter-chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ─── Tab Bar ────────────────────────────────────────── */
.tab-bar {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.5rem;
    gap: 0;
}
.tab-btn {
    padding: 0.6rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition);
    white-space: nowrap;
}
.tab-btn:hover { color: var(--ink-primary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ─── Confirm Dialog ─────────────────────────────────── */
.confirm-dialog {
    max-width: 420px !important;
}
