/* ============================================================
   Chronology - complete stylesheet
   Single source of truth - replaces all previous styles.css
   ============================================================ */

* { box-sizing: border-box; }

:root {
    --bg: #f5f4f0;
    --surface: #ffffff;
    --border: #e5e3dd;
    --text: #1a1a1a;
    --text-muted: #6b6b6b;
    --primary: #2c5f4e;
    --primary-hover: #234c3e;
    --danger: #c73e3e;
    --success: #2c7d5f;
    --info: #2c5f8e;
    --focus: #2c5f4e;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
}

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

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

/* Header */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}
.main-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.main-nav a {
    text-decoration: none;
    color: var(--text);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
}
.main-nav a:hover { background: var(--bg); }
.btn-add { background: var(--primary) !important; color: white !important; }
.btn-add:hover { background: var(--primary-hover) !important; }
.user-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
}
.user-name { color: var(--text-muted); }
.logout-link { color: var(--text-muted); text-decoration: none; }
.logout-link:hover { color: var(--text); text-decoration: underline; }

.site-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

/* Flash messages */
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border-left: 4px solid;
}
.flash-success { background: #e8f5f0; border-color: var(--success); color: #1a5238; }
.flash-error { background: #fce9e9; border-color: var(--danger); color: #7a2020; }
.flash-info { background: #e6eff8; border-color: var(--info); color: #1a3c5a; }
.flash ul { margin: 0.5rem 0 0 1.5rem; }

/* Login page */
.login-page { background: var(--bg); }
.login-main { max-width: 400px; margin: 0 auto; padding: 3rem 1rem 1rem; }
.login-container {
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}
.login-container h1 { margin: 0 0 0.25rem; text-align: center; color: var(--primary); }
.login-subtitle { text-align: center; color: var(--text-muted); margin: 0 0 1.5rem; font-size: 0.9rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 500;
    font-size: 0.95rem;
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group input[type="time"],
.form-group input[type="number"],
.form-group input[type="search"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: 2px solid var(--focus);
    outline-offset: -1px;
    border-color: var(--focus);
}
.form-group textarea { resize: vertical; min-height: 100px; line-height: 1.5; }
.form-group small {
    display: block;
    margin-top: 0.35rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
@media (max-width: 600px) {
    .form-row { grid-template-columns: 1fr; }
}
.form-container {
    max-width: 700px;
    margin: 0 auto;
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.form-container h1 { margin-top: 0; }
.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}
.form-note {
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    line-height: 1.4;
    transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); color: white; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-block { display: block; width: 100%; }
.btn-small { padding: 0.35rem 0.75rem; font-size: 0.9rem; }

/* Dashboard */
.dashboard-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.dashboard-header h1 { margin: 0; }
.dashboard-count { margin: 0; color: var(--text-muted); }

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* Filter bar */
.filter-bar {
    background: var(--surface);
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}
.filter-search-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.filter-search-input {
    flex: 1;
    min-width: 200px;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
}
.filter-search-input:focus {
    outline: 2px solid var(--focus);
    outline-offset: -1px;
    border-color: var(--focus);
}
.advanced-filters {
    display: none;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.advanced-filters.open { display: block; }
.filter-group { margin-bottom: 1rem; }
.filter-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 500;
    font-size: 0.9rem;
}
.filter-group input,
.filter-group select {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
}
.filter-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}
.filter-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Timeline */
.timeline-year {
    margin: 2rem 0 1rem;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 1.1rem;
    letter-spacing: 0.05em;
}
.timeline-year:first-child { margin-top: 0; }
.timeline-entry {
    display: grid;
    grid-template-columns: 70px 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: start;
}
.timeline-date {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 0;
    text-align: center;
    box-shadow: var(--shadow);
}
.date-day { font-size: 1.5rem; font-weight: 700; line-height: 1; color: var(--primary); }
.date-month {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}
.date-year {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    margin-top: 0.1rem;
}
.timeline-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.entry-link {
    display: block;
    padding: 1rem 1.25rem;
    text-decoration: none;
    color: inherit;
}
.entry-link:hover { background: var(--bg); }
.entry-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.entry-title { margin: 0; font-size: 1.1rem; color: var(--text); }
.category-tag {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    color: white;
    font-weight: 500;
    white-space: nowrap;
}
.entry-excerpt { margin: 0.5rem 0; color: var(--text-muted); font-size: 0.95rem; }
.entry-meta {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.meta-police { color: var(--danger); font-weight: 500; }
.meta-visibility {
    background: var(--bg);
    padding: 0.1rem 0.5rem;
    border-radius: 3px;
    font-size: 0.8rem;
}
.entry-thumb-preview { margin: 0.75rem 0; }
.entry-thumb-preview img {
    max-width: 200px;
    max-height: 120px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    object-fit: cover;
    display: block;
}

/* Entry detail page */
.entry-detail { max-width: 800px; margin: 0 auto; }
.entry-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.back-link { color: var(--text-muted); text-decoration: none; font-size: 0.9rem; }
.back-link:hover { color: var(--primary); }
.entry-actions { display: flex; gap: 0.5rem; }
.entry-detail-main {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 2rem;
    box-shadow: var(--shadow);
}
.entry-detail-meta-top {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.entry-date { color: var(--text-muted); font-size: 0.95rem; }
.entry-detail-title { margin: 0 0 1.5rem; }
.entry-detail-description {
    font-size: 1.05rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}
.entry-detail-meta-list {
    background: var(--bg);
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin: 1.5rem 0;
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.5rem 1rem;
    align-items: baseline;
}
.entry-detail-meta-list dt {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.entry-detail-meta-list dd { margin: 0; }
.police-ref { color: var(--danger); font-weight: 500; font-family: monospace; }
.entry-notes {
    background: #fff9e6;
    border: 1px solid #f0e0a0;
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin: 1.5rem 0;
}
.entry-notes h3 { margin-top: 0; font-size: 1rem; }
.entry-evidence {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}
.evidence-list { list-style: none; padding: 0; margin: 0; }
.evidence-list li {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 0.5rem;
    justify-content: flex-start !important;
}
.evidence-file-icon { font-size: 1.5rem; line-height: 1; flex-shrink: 0; }
.evidence-file-info { flex: 1; }
.evidence-name a { font-weight: 500; }
.evidence-desc { font-style: italic; font-size: 0.9rem; margin: 0.25rem 0; }
.evidence-file-meta { color: var(--text-muted); font-size: 0.85rem; }
.entry-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.muted { color: var(--text-muted); font-size: 0.9rem; }

/* Evidence display sections */
.evidence-section { margin-top: 1.5rem; }
.evidence-section h4 {
    color: var(--text-muted);
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}
.evidence-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}
.evidence-image-item {
    background: var(--bg);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}
.evidence-image-item img {
    display: block;
    width: 100%;
    height: 160px;
    object-fit: cover;
    background: #eee;
}
.evidence-caption { padding: 0.6rem 0.75rem; font-size: 0.85rem; }
.evidence-caption-name { font-weight: 500; word-break: break-word; margin-bottom: 0.2rem; }
.evidence-caption-meta { color: var(--text-muted); font-size: 0.8rem; }
.evidence-caption-desc { color: var(--text); margin-top: 0.35rem; font-size: 0.85rem; font-style: italic; }
.evidence-actions { margin-top: 0.5rem; display: flex; gap: 0.5rem; }
.evidence-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
    font-size: 0.85rem;
    font-family: inherit;
}
.evidence-link:hover { color: var(--primary-hover); }
.evidence-link-danger { color: var(--danger); }
.evidence-link-danger:hover { color: #7a2020; }
.evidence-media-item {
    background: var(--bg);
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 1rem;
}
.evidence-media-name { font-weight: 500; margin-bottom: 0.25rem; }
.evidence-media-desc {
    color: var(--text);
    font-size: 0.9rem;
    font-style: italic;
    margin-bottom: 0.5rem;
}
.evidence-media-item audio,
.evidence-media-item video {
    width: 100%;
    margin: 0.5rem 0;
    display: block;
}
.evidence-media-meta { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.5rem; }

/* Upload progress */
.upload-status {
    background: var(--bg);
    padding: 1rem;
    border-radius: var(--radius);
    margin: 1rem 0;
    border-left: 4px solid var(--info);
}
.progress-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 0.5rem;
}
.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s;
    animation: progressPulse 1.5s ease-in-out infinite;
}
@keyframes progressPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* User role tags */
.role-tag {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.role-admin { background: #2c5f4e; color: white; }
.role-editor { background: #2c5f8e; color: white; }
.role-solicitor { background: #6c757d; color: white; }
.user-role-tag {
    margin-left: 0.4rem;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Users / audit tables */
.users-table-wrapper {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow-x: auto;
    box-shadow: var(--shadow);
}
.users-table { width: 100%; border-collapse: collapse; }
.users-table th,
.users-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.users-table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.users-table tbody tr:last-child td { border-bottom: none; }
.users-table tbody tr:hover { background: var(--bg); }
.user-cell-name { font-weight: 500; }
.user-cell-meta {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-family: monospace;
    margin-top: 0.15rem;
}
.status-active { color: var(--success); font-weight: 500; }
.status-inactive { color: var(--danger); font-weight: 500; }

.audit-table { font-size: 0.9rem; }
.audit-table .log-time {
    font-family: monospace;
    font-size: 0.85rem;
    white-space: nowrap;
    color: var(--text-muted);
}
.audit-table .log-ip {
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.audit-table .log-details { max-width: 400px; word-wrap: break-word; font-size: 0.9rem; }
.action-tag {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    background: var(--bg);
    color: var(--text);
    font-family: monospace;
}
.action-create, .action-upload { background: #d4edda; color: #155724; }
.action-update, .action-password_change, .action-password_reset { background: #d1ecf1; color: #0c5460; }
.action-delete { background: #f8d7da; color: #721c24; }
.action-login, .action-logout { background: #e2e3e5; color: #383d41; }
.action-export { background: #fff3cd; color: #856404; }

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
}
.pagination-info { color: var(--text-muted); font-size: 0.9rem; }

/* Checkbox styling */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: normal !important;
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: 0.9rem;
}
.checkbox-label:hover { background: var(--surface); }
.checkbox-label input[type="checkbox"] {
    width: auto !important;
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* Info box for how-to */
.info-box {
    background: #f0f7ff;
    border-left: 4px solid var(--info);
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin: 1rem 0;
}
.info-box h3 { margin-top: 0; }
.info-box ol { margin: 0.5rem 0; padding-left: 1.5rem; }
.info-box kbd {
    background: white;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 0.1rem 0.35rem;
    font-family: monospace;
    font-size: 0.9em;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}

/* Settings nav cards - the important bit */
.nav-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}
.nav-card {
    display: block;
    background: var(--surface);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, transform 0.15s;
}
.nav-card:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}
.nav-card h3 {
    margin: 0 0 0.35rem;
    color: var(--primary);
    font-size: 1.1rem;
}
.nav-card p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Profile page detail list */
.profile-details {
    background: var(--bg);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.detail-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.75rem 1.5rem;
    align-items: baseline;
    margin: 0;
}
.detail-list dt {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.detail-list dd { margin: 0; font-size: 1rem; }

/* Stat cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
}
.stat-card {
    background: var(--surface);
    padding: 1.25rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    text-align: center;
}
.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
    margin-bottom: 0.35rem;
}
.stat-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.stat-bar-container {
    height: 20px;
    background: var(--bg);
    border-radius: 10px;
    overflow: hidden;
    max-width: 300px;
}
.stat-bar { height: 100%; border-radius: 10px; }

/* Backup status card */
.backup-status-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}
.backup-status-card h2 { margin-top: 0; }
.backup-status-card code {
    background: var(--bg);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.9em;
    word-break: break-all;
}

/* Install page */
.install-container {
    max-width: 500px;
    margin: 2rem auto;
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.install-container code {
    background: var(--bg);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.9em;
}

/* Inline forms in tables */
.inline-form { display: inline; }

/* Mobile */
@media (max-width: 640px) {
    .header-inner { padding: 0.5rem; }
    .site-main { padding: 1rem 0.5rem; }
    .timeline-entry { grid-template-columns: 55px 1fr; gap: 0.75rem; }
    .form-container,
    .entry-detail-main,
    .login-container { padding: 1.25rem; }
    .date-day { font-size: 1.25rem; }
    .btn { padding: 0.7rem 1rem; }
    .evidence-image-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .evidence-image-item img { height: 120px; }
    .filter-search-input { width: 100%; }
    .filter-search-row { flex-direction: column; }
    .filter-search-row .btn { width: 100%; }
    .audit-table .log-details { max-width: 200px; font-size: 0.8rem; }
    .stat-number { font-size: 1.5rem; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .users-table th:nth-child(4),
    .users-table td:nth-child(4),
    .users-table th:nth-child(5),
    .users-table td:nth-child(5) { display: none; }
    .users-table th, .users-table td { padding: 0.6rem 0.5rem; }
}



.timeline-year {
    margin: 2.5rem 0 1rem;
    padding-bottom: 0.5rem;
    color: var(--primary);
    font-weight: 700;
    font-size: 2rem;
    letter-spacing: -0.02em;
    border-bottom: 3px solid var(--primary);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 5;
}

.timeline-year:first-child {
    margin-top: 0;
}

.timeline-month {
    margin: 1.5rem 0 0.75rem;
    color: var(--text);
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: 0.02em;
    padding-left: 0.75rem;
    border-left: 4px solid var(--primary);
}

/* First month heading straight after year - remove excess top margin */
.timeline-year + .timeline-month {
    margin-top: 0.5rem;
}

@media (max-width: 640px) {
    .timeline-year {
        font-size: 1.5rem;
        margin: 2rem 0 0.75rem;
    }
    .timeline-month {
        font-size: 1rem;
    }
}


.timeline-year {
    margin: 2.5rem 0 1rem;
    padding-bottom: 0.75rem;
    color: var(--primary);
    font-weight: 700;
    font-size: 2rem;
    letter-spacing: -0.02em;
    text-align: center;
    border-bottom: 3px solid var(--primary);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 5;
}

.timeline-year:first-child {
    margin-top: 0;
}

.timeline-month {
    margin: 1.75rem 0 1rem;
    color: var(--text);
    font-weight: 600;
    font-size: 1.25rem;
    letter-spacing: 0.02em;
    text-align: center;
    position: relative;
}

/* Horizontal line either side of the month header */
.timeline-month::before,
.timeline-month::after {
    content: '';
    display: inline-block;
    width: 60px;
    height: 1px;
    background: var(--border);
    vertical-align: middle;
    margin: 0 1rem;
}

.timeline-year + .timeline-month {
    margin-top: 1rem;
}

@media (max-width: 640px) {
    .timeline-year {
        font-size: 1.5rem;
        margin: 2rem 0 0.75rem;
    }
    .timeline-month {
        font-size: 1.1rem;
    }
    .timeline-month::before,
    .timeline-month::after {
        width: 30px;
        margin: 0 0.5rem;
    }
}



/* Override the flex layout so category always sits under title */
.entry-header {
    display: block;
}

.entry-header .entry-title {
    display: block;
    margin: 0 0 0.5rem;
}

.entry-header .category-tag {
    display: inline-block;
    margin-bottom: 0.5rem;
}




/* Drag and drop zone */
.dropzone {
    background: var(--bg);
    border: 3px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 1.5rem;
    text-align: center;
    transition: all 0.15s;
    cursor: pointer;
    margin-bottom: 1rem;
}
.dropzone:hover {
    border-color: var(--primary);
    background: var(--surface);
}
.dropzone.dragging {
    border-color: var(--primary);
    background: #e8f5f0;
    transform: scale(1.01);
}
.dropzone-inner {
    pointer-events: none;
}
.dropzone-inner button {
    pointer-events: auto;
}
.dropzone-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}
.dropzone p {
    margin: 0.5rem 0;
}

/* Staged files list */
.staged-files-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.staged-file-row {
    display: grid;
    grid-template-columns: 100px 1fr auto;
    gap: 1rem;
    background: var(--bg);
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    align-items: start;
}

.staged-file-preview img {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: block;
    background: #eee;
}

.file-icon-large {
    width: 100px;
    height: 100px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
}

.staged-file-info { min-width: 0; }
.staged-file-name {
    font-weight: 600;
    word-break: break-all;
    margin-bottom: 0.25rem;
}
.staged-file-meta {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}
.staged-file-meta strong {
    color: var(--primary);
}

.staged-file-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}
.staged-file-controls .form-group {
    margin: 0;
}
.staged-file-controls label {
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
}
.staged-file-controls select,
.staged-file-controls input[type="text"] {
    padding: 0.4rem 0.6rem;
    font-size: 0.9rem;
}

.staged-file-actions {
    display: flex;
    align-items: flex-start;
}

@media (max-width: 640px) {
    .staged-file-row {
        grid-template-columns: 80px 1fr;
    }
    .staged-file-actions {
        grid-column: 1 / -1;
        justify-content: flex-end;
    }
    .staged-file-controls {
        grid-template-columns: 1fr;
    }
    .staged-file-preview img,
    .file-icon-large {
        width: 80px;
        height: 80px;
    }
}



/* AI suggestion panel inside staged file rows */
.ai-suggestion-panel {
    background: #f0f7ff;
    border-left: 4px solid var(--info);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}
.ai-result strong {
    display: block;
    margin-bottom: 0.25rem;
}
.ai-reasoning {
    margin: 0.5rem 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding-left: 0.5rem;
    border-left: 2px solid var(--border);
}
.ai-cost {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.4rem;
}
.ai-actions {
    margin-top: 0.5rem;
}
.ai-accepted {
    color: var(--success);
    font-weight: 500;
    margin: 0;
}
.ai-error {
    color: var(--danger);
    font-weight: 500;
    margin: 0;
}

/* AI provenance indicator on evidence */
.ai-provenance-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    background: #f0f7ff;
    color: var(--info);
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-left: 0.5rem;
    border: 1px solid #cfe2f3;
}

/* AI log page */
.ai-log-entry {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}
.ai-log-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
    flex-wrap: wrap;
}
.ai-log-details {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.4rem 1rem;
    align-items: baseline;
    margin: 0.5rem 0;
    font-size: 0.9rem;
}
.ai-log-details dt {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.ai-log-details dd { margin: 0; }
.ai-log-entry details {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}
.ai-log-entry summary {
    cursor: pointer;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 500;
}
.ai-log-entry h4 {
    margin: 1rem 0 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.ai-log-code {
    background: var(--bg);
    padding: 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 0.8rem;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
    font-family: 'Menlo', 'Monaco', 'Consolas', monospace;
}



.ai-batch-controls {
    background: #f0f7ff;
    border: 1px solid #cfe2f3;
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
.ai-batch-controls p { margin: 0 0 0.5rem; }
.ai-batch-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.ai-batch-status {
    font-size: 0.9rem;
    margin-left: 0.5rem;
}

.ai-duplicate-warning {
    background: #fff3cd;
    border: 1px solid #f0e0a0;
    color: #856404;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    margin: 0.5rem 0;
    font-size: 0.9rem;
}
.ai-duplicate-warning strong { color: #7a5c00; }


============================================================ */

/* Thumb strip on timeline entries */
.entry-thumb-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.75rem 0;
}
.thumb-link {
    display: block;
    width: 90px;
    height: 90px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    background: var(--bg);
    cursor: zoom-in;
    transition: transform 0.15s, border-color 0.15s;
}
.thumb-link:hover {
    transform: scale(1.03);
    border-color: var(--primary);
}
.thumb-link img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.thumb-more {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 90px;
    height: 90px;
    border-radius: var(--radius);
    border: 1px dashed var(--border);
    background: var(--bg);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.15s;
}
.thumb-more:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Make title and excerpt links look natural */
.entry-title a {
    color: var(--text);
    text-decoration: none;
}
.entry-title a:hover {
    color: var(--primary);
}
.excerpt-link {
    color: var(--text-muted);
    text-decoration: none;
}
.excerpt-link:hover {
    color: var(--text);
}

/* Lightbox modal */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.lightbox-content img {
    max-width: 100%;
    max-height: calc(90vh - 100px);
    object-fit: contain;
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    background: white;
}

.lightbox-caption {
    text-align: center;
    color: white;
    max-width: 700px;
}
.lightbox-filename {
    font-weight: 600;
    font-size: 0.95rem;
    word-break: break-all;
    margin-bottom: 0.25rem;
}
.lightbox-description {
    font-size: 0.9rem;
    color: rgba(255,255,255,0.8);
    font-style: italic;
    margin-bottom: 0.5rem;
}
.lightbox-counter {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.6);
}

.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255,255,255,0.15);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
}
.lightbox-close:hover {
    background: rgba(255,255,255,0.3);
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.15);
    color: white;
    border: none;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    font-size: 2.5rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
}
.lightbox-nav:hover {
    background: rgba(255,255,255,0.3);
}
.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }

@media (max-width: 640px) {
    .thumb-link, .thumb-more {
        width: 70px;
        height: 70px;
    }
    .lightbox { padding: 0.5rem; }
    .lightbox-nav {
        width: 44px;
        height: 44px;
        font-size: 2rem;
    }
    .lightbox-prev { left: 0.5rem; }
    .lightbox-next { right: 0.5rem; }
}



.entry-thumb-strip {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.5rem;
    margin: 0.75rem 0;
    padding-bottom: 0.5rem;
    scrollbar-width: thin;
}

.entry-thumb-strip::-webkit-scrollbar {
    height: 6px;
}
.entry-thumb-strip::-webkit-scrollbar-track {
    background: var(--bg);
    border-radius: 3px;
}
.entry-thumb-strip::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
.entry-thumb-strip::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.thumb-link {
    flex-shrink: 0;
    display: block;
    width: 90px;
    height: 90px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    background: var(--bg);
    cursor: zoom-in;
    transition: transform 0.15s, border-color 0.15s;
}

@media (max-width: 640px) {
    .thumb-link {
        width: 70px;
        height: 70px;
    }
}



.entry-links-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.entry-links-section h3 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    color: var(--text);
}

.entry-links-list {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.entry-link-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.entry-link-incoming {
    border-left: 3px solid var(--info);
}

.entry-link-body {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.link-type-tag {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    color: white;
    font-weight: 500;
    white-space: nowrap;
}

.link-target {
    text-decoration: none;
    color: var(--text);
}
.link-target:hover strong {
    color: var(--primary);
    text-decoration: underline;
}

.link-note {
    width: 100%;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-style: italic;
    margin-top: 0.25rem;
    padding-left: 0.25rem;
}

.link-remove-form {
    margin: 0;
}

.link-remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.25rem;
    border-radius: 3px;
}
.link-remove-btn:hover {
    color: var(--danger);
    background: rgba(199, 62, 62, 0.1);
}

.entry-links-divider {
    height: 1px;
    background: var(--border);
    margin: 1rem 0;
}

.add-link-container {
    margin-top: 1rem;
}

.add-link-form {
    display: none;
    background: var(--surface);
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-top: 0.75rem;
}
.add-link-form.open {
    display: block;
}

.add-link-form .form-actions {
    margin-top: 1rem;
    margin-bottom: 0;
}

@media (max-width: 640px) {
    .entry-link-body {
        gap: 0.35rem;
    }
    .link-target strong {
        display: block;
        width: 100%;
    }
}


.visual-timeline-wrapper {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 0.5rem;
    box-shadow: var(--shadow);
    overflow-x: auto;
    margin-bottom: 1rem;
    position: relative;
}

.tl-svg {
    display: block;
    min-width: 900px;
}

.tl-event circle {
    transition: r 0.1s ease-out, filter 0.1s ease-out;
}

.tl-event:hover circle:first-child {
    filter: brightness(1.15) drop-shadow(0 0 4px rgba(0,0,0,0.3));
}

.tl-tooltip {
    position: fixed;
    z-index: 1000;
    background: rgba(26, 26, 26, 0.95);
    color: white;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    pointer-events: none;
    display: none;
    max-width: 320px;
}

.tl-tooltip-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.tl-tooltip-meta {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.85);
}

.tl-tooltip-extra {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.75);
    margin-top: 0.25rem;
}

.visual-timeline-legend {
    margin-top: 0.5rem;
}

@media (max-width: 640px) {
    .visual-timeline-wrapper {
        padding: 0;
    }
}



/* Rich-text rendered content */
.rendered-content { }
.rendered-content p { margin: 0 0 0.75rem; }
.rendered-content p:last-child { margin-bottom: 0; }
.rendered-content ul {
    margin: 0.25rem 0 0.75rem 1.5rem;
    padding: 0;
}
.rendered-content ul li { margin-bottom: 0.25rem; }
.rendered-content blockquote {
    margin: 0.75rem 0;
    padding: 0.5rem 1rem;
    border-left: 3px solid var(--border);
    color: var(--text-muted);
    font-style: italic;
}
.rendered-content code {
    background: var(--bg);
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: monospace;
}
.rendered-content strong { font-weight: 700; }
.rendered-content em { font-style: italic; }
.rendered-content a { color: var(--primary); }

.markdown-help {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.markdown-help code {
    background: var(--bg);
    padding: 0.05rem 0.3rem;
    border-radius: 2px;
    font-family: monospace;
    font-size: 0.85em;
}

/* Template management */
.template-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.template-card {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.template-card.template-inactive {
    opacity: 0.6;
}
.template-card h3 {
    margin: 0 0 0.35rem;
    font-size: 1.1rem;
    display: inline;
    margin-right: 0.5rem;
}
.template-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.template-actions {
    display: flex;
    gap: 0.75rem;
    font-size: 0.9rem;
}
.template-preview {
    background: var(--bg);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-top: 0.5rem;
    font-size: 0.9rem;
}
.template-preview pre {
    background: transparent;
    margin: 0.25rem 0;
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.9rem;
}

.add-template-details summary {
    list-style: none;
    display: inline-block;
    cursor: pointer;
}
.add-template-details summary::-webkit-details-marker { display: none; }

/* Entry quick upload */
.entry-quick-upload {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}
.entry-quick-upload summary {
    list-style: none;
    display: inline-block;
    cursor: pointer;
}
.entry-quick-upload summary::-webkit-details-marker { display: none; }
.quick-upload-form {
    margin-top: 1rem;
    background: var(--bg);
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.quick-dropzone {
    padding: 1.5rem;
    margin-bottom: 1rem;
}

/* Changelog */
.entry-changelog-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
}
.entry-changelog-section summary {
    cursor: pointer;
    color: var(--text-muted);
}
.changelog-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0 0;
}
.changelog-list li {
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 0.5rem;
}
.changelog-header {
    display: flex;
    gap: 0.75rem;
    align-items: baseline;
    flex-wrap: wrap;
    font-size: 0.9rem;
}
.changelog-field {
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.changelog-old {
    background: #fce9e9;
    padding: 0.05rem 0.3rem;
    border-radius: 2px;
    text-decoration: line-through;
}
.changelog-new {
    background: #e8f5f0;
    padding: 0.05rem 0.3rem;
    border-radius: 2px;
}

/* Selected export UI on dashboard */
.export-selected-bar {
    position: sticky;
    top: 60px;
    z-index: 10;
    background: var(--primary);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    display: none;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-lg);
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.export-selected-bar.visible { display: flex; }
.export-selected-bar .btn {
    background: white;
    color: var(--primary);
    border-color: white;
}
.export-selected-count {
    font-weight: 600;
}
.entry-select-checkbox {
    display: inline-block;
    margin-right: 0.5rem;
    vertical-align: middle;
}

/* Mobile improvements */
@media (max-width: 640px) {
    /* Bulk upload page - stack controls */
    .staged-file-row {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
    .staged-file-preview img,
    .file-icon-large {
        width: 100% !important;
        max-width: 200px;
        height: auto !important;
        aspect-ratio: 1;
    }
    .staged-file-controls {
        grid-template-columns: 1fr !important;
    }
    .staged-file-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    /* AI batch buttons stack */
    .ai-batch-buttons {
        flex-direction: column;
        align-items: stretch;
    }
    .ai-batch-buttons .btn {
        width: 100%;
    }
    
    /* Header - allow more space */
    .site-header {
        position: sticky;
        top: 0;
        z-index: 20;
    }
    .main-nav {
        gap: 0.35rem;
        font-size: 0.9rem;
    }
    .main-nav a {
        padding: 0.35rem 0.5rem;
    }
    .user-menu {
        font-size: 0.85rem;
    }
    
    /* Filter forms stack */
    .filter-search-row {
        gap: 0.35rem;
    }
    .filter-row {
        grid-template-columns: 1fr !important;
    }
    
    /* Table adjustments */
    .users-table {
        font-size: 0.85rem;
    }
    
    /* Timeline entry - tighter */
    .timeline-entry {
        gap: 0.5rem !important;
        grid-template-columns: 50px 1fr !important;
    }
    .date-day {
        font-size: 1.1rem !important;
    }
    .date-month {
        font-size: 0.7rem;
    }
    
    /* Buttons need to be tappable */
    .btn-small {
        min-height: 40px;
        padding: 0.6rem 1rem;
    }
    
    /* Entry detail page */
    .entry-detail-main {
        padding: 1rem !important;
    }
    .entry-detail-meta-list {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }
    
    /* Add form pages - more compact */
    .form-container {
        padding: 1rem !important;
    }
    
    /* Print view controls */
    .print-controls button, .print-controls a {
        width: 100%;
        margin-bottom: 0.5rem;
        display: block;
        text-align: center;
    }
    
    /* Lightbox - full screen on mobile */
    .lightbox {
        padding: 0 !important;
    }
    .lightbox-content img {
        max-height: calc(100vh - 120px);
    }
    .lightbox-caption {
        font-size: 0.85rem;
    }
}



/* Rich-text rendered content */
.rendered-content { }
.rendered-content p { margin: 0 0 0.75rem; }
.rendered-content p:last-child { margin-bottom: 0; }
.rendered-content ul {
    margin: 0.25rem 0 0.75rem 1.5rem;
    padding: 0;
}
.rendered-content ul li { margin-bottom: 0.25rem; }
.rendered-content blockquote {
    margin: 0.75rem 0;
    padding: 0.5rem 1rem;
    border-left: 3px solid var(--border);
    color: var(--text-muted);
    font-style: italic;
}
.rendered-content code {
    background: var(--bg);
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: monospace;
}
.rendered-content strong { font-weight: 700; }
.rendered-content em { font-style: italic; }
.rendered-content a { color: var(--primary); }

.markdown-help {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.markdown-help code {
    background: var(--bg);
    padding: 0.05rem 0.3rem;
    border-radius: 2px;
    font-family: monospace;
    font-size: 0.85em;
}

/* Template management */
.template-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.template-card {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.template-card.template-inactive {
    opacity: 0.6;
}
.template-card h3 {
    margin: 0 0 0.35rem;
    font-size: 1.1rem;
    display: inline;
    margin-right: 0.5rem;
}
.template-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.template-actions {
    display: flex;
    gap: 0.75rem;
    font-size: 0.9rem;
}
.template-preview {
    background: var(--bg);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-top: 0.5rem;
    font-size: 0.9rem;
}
.template-preview pre {
    background: transparent;
    margin: 0.25rem 0;
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.9rem;
}

.add-template-details summary {
    list-style: none;
    display: inline-block;
    cursor: pointer;
}
.add-template-details summary::-webkit-details-marker { display: none; }

/* Entry quick upload */
.entry-quick-upload {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}
.entry-quick-upload summary {
    list-style: none;
    display: inline-block;
    cursor: pointer;
}
.entry-quick-upload summary::-webkit-details-marker { display: none; }
.quick-upload-form {
    margin-top: 1rem;
    background: var(--bg);
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.quick-dropzone {
    padding: 1.5rem;
    margin-bottom: 1rem;
}

/* Changelog */
.entry-changelog-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
}
.entry-changelog-section summary {
    cursor: pointer;
    color: var(--text-muted);
}
.changelog-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0 0;
}
.changelog-list li {
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 0.5rem;
}
.changelog-header {
    display: flex;
    gap: 0.75rem;
    align-items: baseline;
    flex-wrap: wrap;
    font-size: 0.9rem;
}
.changelog-field {
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.changelog-old {
    background: #fce9e9;
    padding: 0.05rem 0.3rem;
    border-radius: 2px;
    text-decoration: line-through;
}
.changelog-new {
    background: #e8f5f0;
    padding: 0.05rem 0.3rem;
    border-radius: 2px;
}

/* Selected export UI on dashboard */
.export-selected-bar {
    position: sticky;
    top: 60px;
    z-index: 10;
    background: var(--primary);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    display: none;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-lg);
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.export-selected-bar.visible { display: flex; }
.export-selected-bar .btn {
    background: white;
    color: var(--primary);
    border-color: white;
}
.export-selected-count {
    font-weight: 600;
}
.entry-select-checkbox {
    display: inline-block;
    margin-right: 0.5rem;
    vertical-align: middle;
}

/* Mobile improvements */
@media (max-width: 640px) {
    /* Bulk upload page - stack controls */
    .staged-file-row {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
    .staged-file-preview img,
    .file-icon-large {
        width: 100% !important;
        max-width: 200px;
        height: auto !important;
        aspect-ratio: 1;
    }
    .staged-file-controls {
        grid-template-columns: 1fr !important;
    }
    .staged-file-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    /* AI batch buttons stack */
    .ai-batch-buttons {
        flex-direction: column;
        align-items: stretch;
    }
    .ai-batch-buttons .btn {
        width: 100%;
    }
    
    /* Header - allow more space */
    .site-header {
        position: sticky;
        top: 0;
        z-index: 20;
    }
    .main-nav {
        gap: 0.35rem;
        font-size: 0.9rem;
    }
    .main-nav a {
        padding: 0.35rem 0.5rem;
    }
    .user-menu {
        font-size: 0.85rem;
    }
    
    /* Filter forms stack */
    .filter-search-row {
        gap: 0.35rem;
    }
    .filter-row {
        grid-template-columns: 1fr !important;
    }
    
    /* Table adjustments */
    .users-table {
        font-size: 0.85rem;
    }
    
    /* Timeline entry - tighter */
    .timeline-entry {
        gap: 0.5rem !important;
        grid-template-columns: 50px 1fr !important;
    }
    .date-day {
        font-size: 1.1rem !important;
    }
    .date-month {
        font-size: 0.7rem;
    }
    
    /* Buttons need to be tappable */
    .btn-small {
        min-height: 40px;
        padding: 0.6rem 1rem;
    }
    
    /* Entry detail page */
    .entry-detail-main {
        padding: 1rem !important;
    }
    .entry-detail-meta-list {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }
    
    /* Add form pages - more compact */
    .form-container {
        padding: 1rem !important;
    }
    
    /* Print view controls */
    .print-controls button, .print-controls a {
        width: 100%;
        margin-bottom: 0.5rem;
        display: block;
        text-align: center;
    }
    
    /* Lightbox - full screen on mobile */
    .lightbox {
        padding: 0 !important;
    }
    .lightbox-content img {
        max-height: calc(100vh - 120px);
    }
    .lightbox-caption {
        font-size: 0.85rem;
    }
}

/* Template picker on the Add entry form */
.template-picker {
    background: #f0f7ff;
    border: 1px solid #cfe2f3;
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}
.template-picker label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.35rem;
}
.template-picker select {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--surface);
}
.template-picker small {
    display: block;
    margin-top: 0.4rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}


:root {
    --header-h: 54px;
}

html {
    -webkit-text-size-adjust: 100%;
}

/* Nothing should ever cause sideways page scroll */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Long filenames, refs and URLs must not blow out the layout */
.entry-title,
.staged-file-name,
.evidence-caption-name,
.evidence-name,
.nav-card h3,
.template-card h3 {
    overflow-wrap: anywhere;
}

/* ============================================================
   HEADER — collapsible nav
   ============================================================ */

.nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 44px;
    height: 44px;
    padding: 0;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}
.nav-toggle-bar {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform 0.18s ease, opacity 0.18s ease;
}
.nav-toggle.open .nav-toggle-bar:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}
.nav-toggle.open .nav-toggle-bar:nth-child(2) {
    opacity: 0;
}
.nav-toggle.open .nav-toggle-bar:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

/* Desktop: collapse wrapper is just a flex row */
.header-collapse {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex: 1;
}

/* Current page indicator */
.main-nav a.nav-current {
    background: var(--bg);
    font-weight: 600;
    box-shadow: inset 0 -2px 0 var(--primary);
}

@media (max-width: 820px) {
    .site-header {
        position: sticky;
        top: 0;
        z-index: 40;
        padding-top: env(safe-area-inset-top);
    }
    .header-inner {
        flex-wrap: nowrap;
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
        min-height: var(--header-h);
    }
    .logo {
        font-size: 1.1rem;
        flex: 1;
        min-width: 0;
    }
    .nav-toggle {
        display: flex;
        flex: 0 0 auto;
    }

    /* Collapsed panel drops below the bar */
    .header-collapse {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
        padding: 0.5rem;
        max-height: calc(100vh - var(--header-h));
        overflow-y: auto;
    }
    .header-collapse.open {
        display: flex;
    }

    .main-nav {
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
        width: 100%;
    }
    .main-nav a {
        display: block;
        padding: 0.85rem 0.75rem;
        border-radius: var(--radius);
        font-size: 1rem;
        min-height: 44px;
        line-height: 1.5;
    }
    .main-nav a.nav-current {
        box-shadow: inset 3px 0 0 var(--primary);
    }
    .btn-add {
        text-align: center;
        margin: 0.25rem 0;
    }

    .user-menu {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        margin-top: 0.5rem;
        padding: 0.75rem;
        border-top: 1px solid var(--border);
        gap: 0.5rem;
    }
    .user-name {
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .logout-link {
        flex: 0 0 auto;
        padding: 0.5rem 0.75rem;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        min-height: 40px;
        display: inline-flex;
        align-items: center;
    }

    /* Sticky things must sit below the sticky header */
    .timeline-year {
        top: var(--header-h);
    }
    .export-selected-bar {
        top: calc(var(--header-h) + 4px);
        z-index: 30;
    }
}

/* ============================================================
   FORMS — stop iOS zooming in on focus
   Any input under 16px triggers auto-zoom on iPhone.
   ============================================================ */

@media (max-width: 820px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    input[type="url"],
    select,
    textarea,
    .filter-search-input,
    .filter-group input,
    .filter-group select,
    .staged-file-controls select,
    .staged-file-controls input[type="text"],
    .template-picker select {
        font-size: 16px !important;
    }

    /* Date/time inputs render badly at full width on some Androids */
    input[type="date"],
    input[type="time"] {
        min-height: 44px;
        appearance: none;
        -webkit-appearance: none;
    }

    .form-row {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
    }
    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .form-actions .btn {
        width: 100%;
        min-height: 46px;
    }
    .form-container {
        padding: 1rem;
    }
}

/* ============================================================
   TABLES — scroll horizontally rather than hiding data
   The earlier mobile rules hid columns 4 and 5 outright, which
   quietly removed information from users.php and audit-log.php.
   ============================================================ */

@media (max-width: 640px) {
    .users-table th:nth-child(4),
    .users-table td:nth-child(4),
    .users-table th:nth-child(5),
    .users-table td:nth-child(5) {
        display: table-cell;
    }
    .users-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .users-table {
        min-width: 640px;
    }
    .users-table th,
    .users-table td {
        padding: 0.6rem 0.6rem;
        white-space: nowrap;
    }
    .audit-table .log-details {
        max-width: none;
        white-space: normal;
        min-width: 200px;
    }
    /* Hint that the table scrolls */
    .users-table-wrapper::after {
        content: 'Scroll sideways for more →';
        display: block;
        padding: 0.4rem 0.75rem;
        font-size: 0.75rem;
        color: var(--text-muted);
        background: var(--bg);
        border-top: 1px solid var(--border);
        position: sticky;
        left: 0;
    }
}

/* ============================================================
   TIMELINE
   ============================================================ */

@media (max-width: 640px) {
    .timeline-entry {
        grid-template-columns: 48px 1fr;
        gap: 0.5rem;
    }
    .timeline-date {
        padding: 0.5rem 0;
    }
    .date-day { font-size: 1.15rem; }
    .date-month { font-size: 0.65rem; }

    .entry-link { padding: 0.75rem 0.85rem; }
    .entry-title { font-size: 1rem; line-height: 1.35; }
    .entry-excerpt { font-size: 0.9rem; }

    .entry-thumb-strip {
        gap: 0.4rem;
        -webkit-overflow-scrolling: touch;
    }
    .thumb-link { width: 64px; height: 64px; }

    .entry-select-checkbox {
        width: 20px;
        height: 20px;
    }

    .export-selected-bar {
        gap: 0.5rem;
        padding: 0.6rem 0.75rem;
    }
    .export-selected-bar .btn {
        flex: 1 1 auto;
        min-height: 40px;
    }
    .export-selected-count {
        flex: 1 0 100%;
    }
}

/* ============================================================
   FILTER BAR
   ============================================================ */

@media (max-width: 640px) {
    .filter-bar { padding: 0.75rem; }
    .filter-search-row { flex-direction: column; gap: 0.5rem; }
    .filter-search-row .btn,
    .filter-search-input { width: 100%; min-height: 46px; }
    .filter-row { grid-template-columns: 1fr !important; }
    .checkbox-grid { grid-template-columns: 1fr; }
    .checkbox-label { min-height: 44px; padding: 0.5rem; }
    .checkbox-label input[type="checkbox"] { width: 20px; height: 20px; }
    .filter-actions { flex-direction: column; }
    .filter-actions .btn { width: 100%; min-height: 46px; }
}

/* ============================================================
   ENTRY DETAIL
   ============================================================ */

@media (max-width: 640px) {
    .entry-detail-main { padding: 1rem; }
    .entry-detail-title { font-size: 1.35rem; }
    .entry-detail-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    .entry-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }
    .entry-actions .btn { min-height: 44px; }

    .entry-detail-meta-list {
        grid-template-columns: 1fr;
        gap: 0.15rem 0;
        padding: 0.85rem 1rem;
    }
    .entry-detail-meta-list dt { margin-top: 0.5rem; }
    .entry-detail-meta-list dd { margin-bottom: 0.25rem; }

    .evidence-image-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 0.5rem;
    }
    .evidence-list li { flex-wrap: wrap; }
    .evidence-actions { flex-wrap: wrap; gap: 0.75rem; }
    .evidence-link { min-height: 32px; }

    /* Entry links */
    .entry-link-item { flex-direction: row; align-items: flex-start; }
    .entry-link-body { flex-direction: column; align-items: flex-start; gap: 0.35rem; }
    .link-remove-btn { min-width: 32px; min-height: 32px; }
    .add-link-form { padding: 0.85rem; }
}

/* ============================================================
   BULK UPLOAD + AI
   ============================================================ */

@media (max-width: 640px) {
    .dropzone { padding: 1.5rem 0.75rem; }
    .dropzone-icon { font-size: 2rem; margin-bottom: 0.5rem; }

    .staged-file-row {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    .staged-file-preview { display: flex; justify-content: center; }
    .staged-file-preview img,
    .file-icon-large {
        width: 140px;
        height: 140px;
    }
    .staged-file-controls { grid-template-columns: 1fr; }
    .staged-file-actions {
        display: flex;
        gap: 0.75rem;
        align-items: center;
        justify-content: space-between;
        padding-top: 0.5rem;
        border-top: 1px solid var(--border);
    }
    .staged-file-actions .btn { min-height: 44px; }

    .ai-batch-buttons { flex-direction: column; align-items: stretch; }
    .ai-batch-buttons .btn { width: 100%; min-height: 44px; }
    .ai-batch-status { margin-left: 0; text-align: center; }
    .ai-suggestion-panel { font-size: 0.85rem; }
}

/* ============================================================
   SETTINGS / TEMPLATES / STATS
   ============================================================ */

@media (max-width: 640px) {
    .nav-cards { grid-template-columns: 1fr; gap: 0.75rem; }
    .nav-card { padding: 1rem; }

    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
    .stat-card { padding: 1rem 0.5rem; }
    .stat-number { font-size: 1.5rem; }
    .stat-label { font-size: 0.7rem; }

    .detail-list { grid-template-columns: 1fr; gap: 0.15rem 0; }
    .detail-list dt { margin-top: 0.6rem; }

    .template-card { padding: 1rem; }
    .template-card-header { flex-direction: column; gap: 0.5rem; }
    .template-actions { gap: 1rem; }
    .template-preview pre { font-size: 0.8rem; overflow-x: auto; }

    .backup-status-card { padding: 1rem; }
    .settings-card { padding: 1rem; }

    .pagination { flex-wrap: wrap; gap: 0.5rem; }
    .pagination .btn { min-height: 44px; }
}

/* ============================================================
   VISUAL TIMELINE — scrolls sideways, tell the user
   ============================================================ */

@media (max-width: 820px) {
    .visual-timeline-wrapper {
        padding: 0;
        -webkit-overflow-scrolling: touch;
    }
    .visual-timeline-wrapper::before {
        content: 'Scroll sideways to move through time →';
        display: block;
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
        color: var(--text-muted);
        background: var(--bg);
        border-bottom: 1px solid var(--border);
        position: sticky;
        left: 0;
    }
    .tl-tooltip {
        max-width: calc(100vw - 2rem);
        font-size: 0.85rem;
    }
}

/* ============================================================
   LIGHTBOX — full screen on phones
   ============================================================ */

@media (max-width: 640px) {
    .lightbox {
        padding: 0;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .lightbox-content {
        max-width: 100vw;
        max-height: 100vh;
        gap: 0.5rem;
    }
    .lightbox-content img {
        max-height: calc(100vh - 160px);
        border-radius: 0;
    }
    .lightbox-close {
        top: 0.5rem;
        right: 0.5rem;
        width: 44px;
        height: 44px;
        font-size: 1.75rem;
    }
    .lightbox-nav {
        width: 44px;
        height: 44px;
        font-size: 1.75rem;
        background: rgba(255, 255, 255, 0.2);
    }
    .lightbox-prev { left: 0.35rem; }
    .lightbox-next { right: 0.35rem; }
    .lightbox-caption { padding: 0 0.75rem; }
    .lightbox-filename { font-size: 0.85rem; }
    .lightbox-description { font-size: 0.8rem; }
}

/* ============================================================
   MISC
   ============================================================ */

@media (max-width: 640px) {
    .site-main {
        padding: 1rem 0.75rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
    .dashboard-header h1 { font-size: 1.5rem; }

    .flash { font-size: 0.9rem; }
    .flash ul { padding-left: 1.1rem; }

    .btn-small { min-height: 40px; padding: 0.5rem 0.85rem; }

    .info-box { padding: 0.85rem 1rem; }
    .info-box ol { padding-left: 1.1rem; }

    .ai-log-details { grid-template-columns: 1fr; gap: 0.1rem 0; }
    .ai-log-details dt { margin-top: 0.5rem; }
    .ai-log-code { font-size: 0.7rem; }
    .ai-log-header { flex-direction: column; gap: 0.35rem; }

    code, .police-ref { overflow-wrap: anywhere; }
}

/* Login page (no header, so it needs its own spacing) */
@media (max-width: 640px) {
    .login-main {
        padding: 1.5rem 1rem 1rem;
        padding-top: calc(1.5rem + env(safe-area-inset-top));
    }
    .login-container { padding: 1.25rem; }
    .login-container h1 { font-size: 1.4rem; }
    .login-container .btn { min-height: 46px; }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
