/* OJournal - Main Stylesheet */

/* ============================================================================
   ACCESSIBILITY HELPERS (#235)
   ============================================================================ */

/* Skip-to-content link: off-screen until keyboard-focused. WCAG 2.4.1. */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-primary, #4f46e5);
    color: #fff;
    padding: 8px 16px;
    z-index: 10000;
    text-decoration: none;
    border-radius: 0 0 4px 0;
    font-weight: 600;
}
.skip-link:focus {
    top: 0;
    outline: 2px solid #fff;
    outline-offset: -4px;
}

/* Screen-reader-only helper for hidden labels / nav landmarks. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================================================
   CSS VARIABLES
   ============================================================================ */

:root {
    /* Colors */
    --color-primary: #4f46e5;
    --color-primary-dark: #4338ca;
    --color-primary-light: #818cf8;
    --color-secondary: #64748b;
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-danger-dark: #dc2626;

    /* Backgrounds */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-hover: #e2e8f0;

    /* Text */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    --text-inverse: #ffffff;

    /* Borders */
    --border-color: #e2e8f0;
    --border-focus: var(--color-primary);

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;

    /* Border radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;
    --radius-full: 9999px;

    /* Font sizes */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;

    /* Z-index */
    --z-nav: 100;
    --z-modal: 200;
    --z-toast: 300;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-tertiary: #334155;
        --bg-hover: #475569;

        --text-primary: #f8fafc;
        --text-secondary: #cbd5e1;
        --text-tertiary: #64748b;

        --border-color: #334155;
    }
}

/* ============================================================================
   RESET & BASE
   ============================================================================ */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: var(--text-base);
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    min-height: 100vh;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-dark);
}

img {
    max-width: 100%;
    height: auto;
}

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

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1.5;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--color-primary);
    color: var(--text-inverse);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--color-primary-dark);
}

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

.btn-secondary:hover:not(:disabled) {
    background-color: var(--bg-tertiary);
}

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

.btn-danger:hover:not(:disabled) {
    background-color: var(--color-danger-dark);
}

.btn-block {
    width: 100%;
}

.btn-small {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--text-xs);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

/* ============================================================================
   FORMS
   ============================================================================ */

.form-group {
    margin-bottom: var(--spacing-md);
}

.form-group label {
    display: block;
    margin-bottom: var(--spacing-xs);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--text-base);
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.form-hint {
    display: block;
    margin-top: var(--spacing-xs);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.form-error {
    color: var(--color-danger);
}

.form-row {
    display: flex;
    gap: var(--spacing-md);
}

.form-group-large {
    flex: 1;
}

.select-input {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--text-sm);
    color: var(--text-primary);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
}

/* ============================================================================
   NAVIGATION
   ============================================================================ */

.nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: var(--z-nav);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-lg);
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.nav-brand {
    display: flex;
    align-items: center;
}

.nav-logo {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--color-primary);
}

.nav-links {
    display: flex;
    gap: var(--spacing-sm);
}

.nav-link {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.nav-link:hover,
.nav-link.active {
    color: var(--color-primary);
    background-color: var(--bg-tertiary);
}

.nav-user {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

/* ============================================================================
   MAIN CONTENT
   ============================================================================ */

#main-content {
    min-height: 100vh;
}

.page-container {
    max-width: 900px;
    margin: 0 auto;
    padding: var(--spacing-xl);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-xl);
}

.page-header h1 {
    font-size: var(--text-2xl);
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.header-back {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

/* ============================================================================
   AUTH PAGES
   ============================================================================ */

.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--spacing-xl);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: var(--spacing-2xl);
    background-color: var(--bg-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
}

.auth-title {
    font-size: var(--text-3xl);
    font-weight: 700;
    text-align: center;
    color: var(--color-primary);
    margin-bottom: var(--spacing-xs);
}

.auth-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xl);
}

.auth-form {
    margin-bottom: var(--spacing-lg);
}

.auth-footer {
    text-align: center;
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

/* ============================================================================
   ENTRIES
   ============================================================================ */

.entries-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.entry-card {
    padding: var(--spacing-lg);
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.entry-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

/* Placeholder cards are rendered up-front for every entry so the page
   scrollbar reflects the whole journal (not just what's been loaded).
   Kept empty + a reserved height; the IntersectionObserver swaps in
   the real card once the placeholder enters the viewport. No hover /
   cursor affordance since there's nothing to click yet. */
.entry-card-placeholder {
    min-height: 120px;
    opacity: 0.35;
    cursor: default;
    background-image: linear-gradient(
        90deg,
        transparent 0%,
        rgba(127, 127, 127, 0.08) 50%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: entry-card-placeholder-shimmer 1.4s ease-in-out infinite;
}
.entry-card-placeholder:hover {
    box-shadow: var(--shadow-sm);
    transform: none;
}
@keyframes entry-card-placeholder-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* /scroll placeholders are block-level entry articles with a larger
   reserved height than the entries list (full bodies, not previews).
   Same shimmer animation for consistency. */
.scroll-entry-placeholder {
    opacity: 0.35;
    background-image: linear-gradient(
        90deg,
        transparent 0%,
        rgba(127, 127, 127, 0.08) 50%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: entry-card-placeholder-shimmer 1.4s ease-in-out infinite;
}

/* /tags page: row hover highlights the whole tag row (parent + rule
   sub-rows) so the eye can track which tag the action dropdown is
   about to operate on. Low-contrast background — just enough to
   separate from neighbours. */
.tag-row:hover {
    background: var(--ej-bg-warm, #f5f2ef);
}

/* #253: L0 (root) rows read as section headers. On a journal with
   dozens of roots + hundreds of descendants, the eye loses track of
   where each tree starts. Hairline top rule + slight padding lift
   make each root visually anchor the section below it; the accent
   stripe surfaces on hover so the at-rest view stays clean. Depth
   dots + bold weight already differentiate L1+, so this rule only
   targets depth=0. */
.tag-row[data-depth="0"] {
    border-top: 1px solid var(--ej-border, #e5dfd5);
    padding-top: .35rem;
    margin-top: .15rem;
    letter-spacing: .01em;
}
/* The very first L0 under a list container inherits the section
   boundary from the page heading above it, so suppressing the
   divider there avoids a doubled rule. */
ul > li:first-child > .tag-row[data-depth="0"] {
    border-top: none;
    padding-top: .15rem;
    margin-top: 0;
}
.tag-row[data-depth="0"]:hover {
    box-shadow: inset 3px 0 0 var(--ej-accent, #d97706);
}

/* Dropdown menu: small action list hanging off each tag row.
   Hover/focus highlights the item. Inline styles on the button
   can't express :hover. */
.tag-action-menu-item:hover,
.tag-action-menu-item:focus {
    background: var(--ej-bg-warm, #f5f2ef);
    outline: none;
}

/* Files page placeholders — grid (card) + compact (row) variants.
   The base classes (.file-card / .file-row) already set layout so we
   only need the shimmer + reserved-height overlay here. */
.file-card-placeholder,
.file-row-placeholder {
    opacity: 0.35;
    pointer-events: none;
    background-image: linear-gradient(
        90deg,
        transparent 0%,
        rgba(127, 127, 127, 0.08) 50%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: entry-card-placeholder-shimmer 1.4s ease-in-out infinite;
}

.entry-date {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    margin-bottom: var(--spacing-xs);
}

.entry-title {
    font-size: var(--text-lg);
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
}

.entry-preview {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    line-height: 1.6;
    margin-bottom: var(--spacing-sm);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.entry-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.entry-tags {
    display: flex;
    gap: var(--spacing-xs);
}

.entry-tag {
    padding: var(--spacing-xs) var(--spacing-sm);
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

/* Entry View */
.entry-view {
    padding: var(--spacing-xl);
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.entry-view-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.entry-date-badge {
    padding: var(--spacing-xs) var(--spacing-sm);
    background-color: var(--color-primary);
    color: var(--text-inverse);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 500;
}

.entry-content {
    font-size: var(--text-base);
    line-height: 1.8;
    white-space: pre-wrap;
}

.entry-content p {
    margin-bottom: var(--spacing-md);
}

.entry-attachments {
    margin-top: var(--spacing-xl);
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
}

/* Entry Form */
.entry-form textarea {
    font-family: inherit;
    line-height: 1.8;
}

.attachments-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
}

.attachment-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary);
    padding: 2px;
}

.attachment-remove:hover {
    color: var(--color-danger);
}

/* ============================================================================
   FILES
   ============================================================================ */

.files-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--spacing-md);
}

.file-card {
    padding: var(--spacing-md);
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.file-card:hover {
    box-shadow: var(--shadow-md);
}

.file-thumbnail {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: var(--radius-md);
    background-color: var(--bg-tertiary);
    margin-bottom: var(--spacing-sm);
}

.file-icon {
    width: 100%;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-sm);
    color: var(--text-tertiary);
}

.file-name {
    font-size: var(--text-sm);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-meta {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

/* ============================================================================
   SEARCH
   ============================================================================ */

.search-form {
    margin-bottom: var(--spacing-xl);
}

.search-input-wrapper {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.search-input-wrapper input {
    flex: 1;
    padding: var(--spacing-md);
    font-size: var(--text-lg);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.search-input-wrapper input:focus {
    border-color: var(--color-primary);
}

.search-filters {
    display: flex;
    gap: var(--spacing-md);
    flex-wrap: wrap;
}

.search-filters .form-group {
    flex: 1;
    min-width: 150px;
    margin-bottom: 0;
}

/* ============================================================================
   SETTINGS
   ============================================================================ */

.settings-sections {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
}

.settings-section h2 {
    font-size: var(--text-lg);
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    color: var(--text-secondary);
}

.settings-card {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.setting-row:last-child {
    border-bottom: none;
}

.setting-label {
    font-weight: 500;
}

.setting-value {
    color: var(--text-secondary);
}

.setting-description {
    display: block;
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    margin-top: var(--spacing-xs);
}

.setting-action {
    flex-wrap: wrap;
    gap: var(--spacing-sm);
}

.setting-action > div {
    flex: 1;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    text-align: center;
}

.stat-item {
    padding: var(--spacing-lg);
    border-right: 1px solid var(--border-color);
}

.stat-item:last-child {
    border-right: none;
}

.stat-value {
    display: block;
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--color-primary);
}

.stat-label {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
}

/* Danger Zone */
.settings-danger h2 {
    color: var(--color-danger);
}

.settings-danger .settings-card {
    border: 1px solid var(--color-danger);
}

/* ============================================================================
   ADMIN
   ============================================================================ */

.admin-tabs {
    display: flex;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-xl);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: var(--spacing-sm);
}

.tab-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    background: none;
    border: none;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

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

.tab-btn.active {
    color: var(--color-primary);
    background-color: rgba(79, 70, 229, 0.1);
}

.admin-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.admin-stat-card {
    padding: var(--spacing-lg);
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.admin-stat-card .stat-value {
    font-size: var(--text-3xl);
}

.admin-table {
    width: 100%;
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.admin-table th,
.admin-table td {
    padding: var(--spacing-md);
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.admin-table th {
    background-color: var(--bg-tertiary);
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.admin-table tr:last-child td {
    border-bottom: none;
}

.admin-table tr:hover td {
    background-color: var(--bg-secondary);
}

/* ============================================================================
   PAGINATION
   ============================================================================ */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-xl);
}

.pagination-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.pagination-btn:hover:not(:disabled) {
    background-color: var(--bg-tertiary);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-btn.active {
    background-color: var(--color-primary);
    color: var(--text-inverse);
    border-color: var(--color-primary);
}

.pagination-info {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* ============================================================================
   MODALS
   ============================================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.5);
    padding: var(--spacing-lg);
}

.modal-content {
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    background-color: var(--bg-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: var(--text-xl);
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: var(--text-xl);
    cursor: pointer;
    color: var(--text-tertiary);
    padding: var(--spacing-xs);
}

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

.modal-body {
    padding: var(--spacing-lg);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    padding: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
}

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

#toast-container {
    position: fixed;
    bottom: var(--spacing-lg);
    right: var(--spacing-lg);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s ease;
}

.toast.toast-out {
    animation: toast-out 0.3s ease forwards;
}

.toast-success {
    border-left: 4px solid var(--color-success);
}

.toast-error {
    border-left: 4px solid var(--color-danger);
}

.toast-warning {
    border-left: 4px solid var(--color-warning);
}

.toast-info {
    border-left: 4px solid var(--color-primary);
}

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

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

/* ============================================================================
   LOADING
   ============================================================================ */

.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-2xl);
    color: var(--text-tertiary);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: var(--spacing-md);
}

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

/* ============================================================================
   EMPTY STATE
   ============================================================================ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-2xl);
    text-align: center;
    color: var(--text-tertiary);
}

.empty-state svg {
    margin-bottom: var(--spacing-lg);
    opacity: 0.5;
}

.empty-state h3 {
    font-size: var(--text-xl);
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
}

.empty-state p {
    margin-bottom: var(--spacing-lg);
}

/* ============================================================================
   SCROLL SCRUBBER (#238)
   ============================================================================

   Transient drag-to-scrub overlay used by the entries page. Hidden by
   default (opacity: 0, pointer-events: none) so it does _not_ occupy
   layout space — the earlier permanent "year column" design was
   UX-rejected (reverted in ef266c9). The overlay fades in only while
   the page is being scrolled or the user is interacting with the
   track/thumb, and fades back out after a short idle delay.

   The track + thumb are position: fixed against the viewport; the
   scrubber is a shortcut on top of the natural document scroll, not a
   replacement for it, so content remains reachable via keyboard and
   normal wheel/touch scrolling. */
.scroll-scrubber {
    position: fixed;
    top: 0;
    right: 0;
    width: 28px;
    height: 100vh;
    height: 100dvh;
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms ease;
    z-index: 150;
}
.scroll-scrubber--visible,
.scroll-scrubber--dragging {
    opacity: 1;
    pointer-events: auto;
}
/* While actively dragging the thumb we suppress native scroll gestures
   on the whole overlay so the drag isn't hijacked by the page scroll.
   This _only_ applies during the drag, so tap-to-jump on the track
   still works and the overlay otherwise never blocks native swipe. */
.scroll-scrubber--dragging {
    touch-action: none;
}
.scroll-scrubber--hidden {
    display: none !important;
}
.scroll-scrubber-track {
    position: absolute;
    top: 4rem;
    bottom: 1rem;
    right: 8px;
    width: 4px;
    border-radius: 2px;
    background: var(--ej-border-subtle, rgba(0, 0, 0, 0.12));
}
.scroll-scrubber-thumb {
    position: fixed;
    right: 4px;
    top: 0;
    width: 12px;
    height: 36px;
    border-radius: 6px;
    background: var(--color-primary, #4f46e5);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.2));
    cursor: grab;
    touch-action: none;
    will-change: transform;
}
.scroll-scrubber--dragging .scroll-scrubber-thumb {
    cursor: grabbing;
    transform-origin: center;
}
.scroll-scrubber-bubble {
    position: fixed;
    right: 28px;
    top: 0;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: var(--color-primary, #4f46e5);
    color: #fff;
    font-size: 0.85em;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translateY(0);
    transition: opacity 150ms ease;
    will-change: transform;
    box-shadow: var(--shadow-md, 0 4px 6px rgba(0, 0, 0, 0.15));
}
.scroll-scrubber-bubble--show {
    opacity: 1;
}
/* Skip the fade animation when the user has asked for reduced motion. */
.scroll-scrubber--no-motion,
.scroll-scrubber--no-motion .scroll-scrubber-bubble {
    transition: none;
}
/* On narrow viewports give the thumb a larger tap target (44 px tall
   meets iOS HIG / WCAG touch-target recommendations). */
@media (max-width: 768px) {
    .scroll-scrubber {
        width: 36px;
    }
    .scroll-scrubber-thumb {
        width: 14px;
        min-height: 44px;
        right: 6px;
    }
    .scroll-scrubber-track {
        right: 12px;
    }
}

/* ============================================================================
   RESPONSIVE (#92)
   ============================================================================ */

/* Mobile drawer toggle — hidden on wide viewports, flipped visible on
   ≤768px below. */
.nav-mobile-toggle {
    display: none;
    background: none;
    border: 0;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--ej-text, currentColor);
    font-size: 1.5rem;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
}

/* Translucent backdrop shown behind the drawer; click closes the drawer. */
.nav-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 199;
    display: none;
}
body.nav-drawer-open .nav-drawer-backdrop {
    display: block;
}

@media (max-width: 768px) {
    /* Promote the hamburger to the visible state, collapse the nav
       links into a slide-in drawer. */
    .nav-mobile-toggle {
        display: inline-flex;
    }

    .nav {
        padding: var(--spacing-sm);
    }

    .nav-inner {
        align-items: center;
    }

    /* By default the link strip is hidden; the hamburger toggles a
       body class that reveals it as a full-height left drawer. */
    .nav-links {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(78vw, 280px);
        background: var(--ej-bg, #fff);
        flex-direction: column;
        align-items: stretch;
        padding: 4rem 1rem 1rem;
        gap: 0.5rem;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
        transform: translateX(-100%);
        transition: transform 0.22s ease-out;
        z-index: 200;
        overflow-y: auto;
    }
    body.nav-drawer-open .nav-links {
        transform: translateX(0);
        display: flex;
    }

    .nav-links .nav-link {
        padding: 0.75rem 0.5rem;
        min-height: 44px;
        font-size: 1rem;
        display: flex;
        align-items: center;
        gap: 0.5rem;
        border-radius: 8px;
    }

    /* The brand / create / search / profile cluster still fits on a
       narrow nav bar. Shrink the search box so a very short phone
       width can still reach the profile menu. */
    .nav-search {
        flex: 0 1 auto;
        min-width: 0;
    }
    .nav-search input {
        width: 100%;
        max-width: 140px;
    }

    .page-container {
        padding: var(--spacing-md);
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-md);
    }

    .form-row {
        flex-direction: column;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-item {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .stat-item:last-child {
        border-bottom: none;
    }

    .search-filters {
        flex-direction: column;
    }

    .admin-tabs {
        overflow-x: auto;
    }

    /* Filter sidebar (files/entries) becomes a stacked block above
       the main content rather than a left column — there's no room
       for a 13em aside on a 360px phone. Rendered by attachFilterSidebar. */
    .files-layout {
        flex-direction: column;
    }
    .files-sidebar {
        flex: 0 0 auto !important;
        width: 100%;
    }

    /* Touch-friendly button sizing: anything .btn-shaped gets at
       least 44 px of vertical tap area. */
    .btn,
    .btn-icon {
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    .auth-card {
        padding: var(--spacing-lg);
    }

    .files-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .setting-action {
        flex-direction: column;
        align-items: stretch;
    }

    .setting-action .btn {
        width: 100%;
    }

    /* Full-screen modal on the smallest viewports — there's no room
       for a centered card, and touching the backdrop on a 360 px
       screen often closes the dialog by accident. */
    .modal-overlay {
        padding: 0;
    }
    .modal-content {
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        margin: 0;
    }
}
