/* === Custom Properties === */
:root {
    --bg: #f8f8f8;
    --bg-surface: #ffffff;
    --text: #1a1a1a;
    --text-muted: #666;
    --border: #ddd;
    --accent: #4a6fa5;
    --accent-hover: #3a5a8a;
    --mark-bg: #fff3a8;
    --mark-text: #1a1a1a;
    --flash-success-bg: #d4edda;
    --flash-error-bg: #f8d7da;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --radius: 6px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: "SF Mono", "Fira Code", monospace;
}

[data-theme="dark"] {
    --bg: #1a1a2e;
    --bg-surface: #222240;
    --text: #e0e0e0;
    --text-muted: #999;
    --border: #3a3a5a;
    --accent: #7b9fd4;
    --accent-hover: #9ab8e4;
    --mark-bg: #5a4e00;
    --mark-text: #fff;
    --flash-success-bg: #1e3a2a;
    --flash-error-bg: #3a1e1e;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #1a1a2e;
        --bg-surface: #222240;
        --text: #e0e0e0;
        --text-muted: #999;
        --border: #3a3a5a;
        --accent: #7b9fd4;
        --accent-hover: #9ab8e4;
        --mark-bg: #5a4e00;
        --mark-text: #fff;
        --flash-success-bg: #1e3a2a;
        --flash-error-bg: #3a1e1e;
        --shadow: 0 1px 3px rgba(0,0,0,0.3);
    }
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

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

mark {
    background: var(--mark-bg);
    color: var(--mark-text);
    padding: 0.1em 0.2em;
    border-radius: 2px;
}

/* === Layout === */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* === Navbar === */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-links a { font-size: 0.9rem; }

.nav-user {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

.btn-icon:hover { border-color: var(--accent); }

/* === Flash Messages === */
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.flash-success { background: var(--flash-success-bg); }
.flash-error { background: var(--flash-error-bg); }

/* === Search Page === */
.search-page h1 {
    margin-bottom: 1rem;
}

.search-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1.5rem;
}

.search-form input[type="search"] {
    flex: 1;
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    background: var(--bg-surface);
    color: var(--text);
}

.search-form select {
    padding: 0.6rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--bg-surface);
    color: var(--text);
}

.spinner {
    font-size: 1.2rem;
    animation: spin 1s linear infinite;
}

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-block; }

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

/* === Results === */
.result-list {
    list-style: none;
}

.result-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.result-link {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.75rem;
    align-items: baseline;
}

.result-heading {
    font-weight: 600;
    font-size: 1.05rem;
}

.result-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.result-snippet {
    margin-top: 0.3rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.no-results {
    color: var(--text-muted);
    font-style: italic;
}

/* === PDF Viewer Overlay === */
.pdf-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}

.pdf-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.pdf-overlay-content {
    position: relative;
    width: 92vw;
    height: 92vh;
    background: var(--bg-surface);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.pdf-close {
    position: absolute;
    top: -12px;
    right: -12px;
    z-index: 1001;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.pdf-close:hover {
    background: var(--accent-hover);
}

#pdf-frame {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: var(--radius);
}

/* === Forms === */
.login-form, .upload-form {
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-weight: 600;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

input[type="text"],
input[type="password"],
input[type="file"] {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: var(--bg-surface);
    color: var(--text);
}

.btn {
    display: inline-block;
    margin-top: 0.75rem;
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    cursor: pointer;
}

.btn:hover { background: var(--accent-hover); }

.btn-danger { background: #c0392b; }
.btn-danger:hover { background: #a93226; }

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    margin-top: 0;
}

/* === Book Table === */
.book-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    font-size: 0.9rem;
}

.book-table th, .book-table td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.book-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* === Upload Page === */
.upload-page h2 { margin-top: 2rem; }

/* === Modal Overlay === */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}

.modal-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 2.5rem 3rem;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.modal-spinner {
    display: inline-block;
    font-size: 2.5rem;
    animation: spin 1s linear infinite;
}

.modal-text {
    margin-top: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-subtext {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
