:root {
    --ink: #1a1a1a;
    --paper: #faf8f3;
    --accent: #a3232f;
    --muted: #6b6b6b;
    --border: #ddd8cc;
    --radius-sm: 4px;
    --radius-md: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,.12);
}

* { box-sizing: border-box; }

html, body {
    /* Safety net: nothing on the page (cards, controls, images) should
       ever be able to force horizontal scrolling on mobile. */
    overflow-x: hidden;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    color: var(--ink);
    background: var(--paper);
    line-height: 1.5;
}

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

/* ---------------------------------------------------------------
   Header / nav — sticky on every viewport; hamburger + left drawer
   take over on mobile/touch widths.
   --------------------------------------------------------------- */
.site-header {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 10px 24px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 100;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.25rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-logo { display: block; height: 40px; width: auto; max-width: 200px; object-fit: contain; }
.brand-text { white-space: nowrap; }
.main-nav, .user-nav { display: flex; gap: 16px; align-items: center; }
.user-nav { margin-left: auto; }

.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    padding: 6px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.nav-toggle:hover { background: var(--paper); }
.nav-toggle span { display: block; height: 2px; width: 100%; background: var(--ink); border-radius: 2px; }

.nav-drawer-overlay { display: none; }
.nav-drawer { display: none; }

.site-main { max-width: 1100px; margin: 0 auto; padding: 24px; }
.site-main--wide { max-width: 1600px; }
.site-footer { text-align: center; padding: 24px; color: var(--muted); font-size: .875rem; }

.btn {
    display: inline-block;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 1rem;
}
.btn:hover { opacity: .9; text-decoration: none; }
.btn-primary { background: var(--accent); }
.btn-small { padding: 4px 10px; font-size: .8rem; }

.link-button { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; }
.alert-error { background: #fdeaea; color: #a3232f; border: 1px solid #f2c0c0; }
.alert-success { background: #e9f7ef; color: #1e7e42; border: 1px solid #bfe6cd; }

.auth-page { display: flex; justify-content: center; padding: 40px 0; }
.auth-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-sm);
}
.auth-card label { display: block; margin-top: 14px; margin-bottom: 4px; font-weight: 600; font-size: .9rem; }
.auth-card input, .auth-card textarea, .auth-card select {
    width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 1rem;
}
.auth-card button { margin-top: 20px; width: 100%; }
.auth-links { margin-top: 16px; text-align: center; font-size: .9rem; }
.field-error { color: var(--accent); font-size: .8rem; margin: 4px 0 0; }

form label { display: block; margin-top: 14px; margin-bottom: 4px; font-weight: 600; font-size: .9rem; }
form input, form textarea, form select {
    width: 100%; max-width: 480px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 1rem;
}

.hero-epaper { display: flex; gap: 24px; align-items: center; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 20px; box-shadow: var(--shadow-sm); }
.hero-epaper img { border-radius: var(--radius-sm); box-shadow: var(--shadow-sm); }

.article-list { display: grid; gap: 20px; margin-top: 20px; }
.article-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 18px; }
.article-meta { color: var(--muted); font-size: .85rem; }

.archive-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-top: 20px; }
.archive-card { display: flex; gap: 12px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; align-items: center; color: var(--ink); }

/* ---------------------------------------------------------------
   Hotspots — deliberately invisible on the page itself (no tint,
   no dashed outline) so the reader just sees a normal newspaper
   page; still a real, clickable/keyboard-focusable button.
   --------------------------------------------------------------- */
.hotspot {
    position: absolute;
    display: block;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.hotspot:hover,
.hotspot:active { background: transparent; }
.hotspot:focus-visible {
    outline: 2px solid rgba(163,35,47,.55);
    outline-offset: 1px;
    background: transparent;
}

.hero-empty, .reader-empty { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 32px; text-align: center; }

/* ---------------------------------------------------------------
   ePaper reader — single real page at a time, page sidebar, calendar
   --------------------------------------------------------------- */
.epaper-reader { display: flex; flex-direction: column; gap: 12px; }

.reader-topbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px 16px; }
.reader-title { display: flex; flex-direction: column; }
.reader-title span { color: var(--muted); font-size: .85rem; }
.reader-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.reader-controls button.active { background: var(--accent); color: #fff; }
.control-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.page-indicator { font-variant-numeric: tabular-nums; min-width: 60px; text-align: center; }
.zoom-level { min-width: 46px; text-align: center; color: var(--muted); font-size: .85rem; }

.reader-body { display: grid; grid-template-columns: 200px 1fr 240px; gap: 16px; align-items: start; }

.reader-sidebar { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; }
.sidebar-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sidebar-heading h3 { margin: 0; font-size: .95rem; }
.sidebar-close { display: none; background: none; border: none; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--muted); }

.reader-sidebar--pages { max-height: 82vh; overflow-y: auto; position: sticky; top: 68px; }
.page-list { display: flex; flex-direction: column; gap: 8px; }
.page-list-item { display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 2px solid transparent; border-radius: var(--radius-sm); padding: 6px; cursor: pointer; text-align: center; }
.page-list-item img { width: 100%; border-radius: 2px; box-shadow: var(--shadow-sm); display: block; }
.page-list-item span { font-size: .75rem; color: var(--muted); }
.page-list-item:hover { background: var(--paper); }
.page-list-item.active { border-color: var(--accent); background: var(--paper); }
.page-list-item.active span { color: var(--accent); font-weight: 600; }

/* Widened reading stage: bigger page image, more breathing room —
   easier on the eyes than the previous cramped 900px cap. */
.reader-stage { position: relative; display: flex; align-items: flex-start; justify-content: center; min-height: 420px; }
.reader-page-scroller { width: 100%; overflow: auto; display: flex; justify-content: center; background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 20px; }
.reader-page-wrap { position: relative; width: 100%; max-width: 1100px; flex: 0 0 auto; }
.reader-page-wrap img#pageImage { width: 100%; height: auto; display: block; box-shadow: var(--shadow-md); background: #fff; }
.hotspot-layer { position: absolute; inset: 0; pointer-events: none; }
.hotspot-layer .hotspot { pointer-events: auto; }

.stage-nav { position: sticky; top: 40vh; flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: #fff; box-shadow: var(--shadow-sm); font-size: 1.4rem; cursor: pointer; z-index: 2; }
.stage-nav--prev { margin-right: -20px; }
.stage-nav--next { margin-left: -20px; }

.mobile-sidebar-toggle { display: none; }

.reader-sidebar--calendar { position: sticky; top: 68px; }
.calendar-archive-link { margin-top: 10px; font-size: .85rem; text-align: center; }

.mini-calendar { width: 100%; }
.calendar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 600; }
.calendar-header button { background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); width: 26px; height: 26px; cursor: pointer; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar-dow { text-align: center; font-size: .7rem; color: var(--muted); font-weight: 600; }
.calendar-day { aspect-ratio: 1 / 1; border: none; border-radius: var(--radius-sm); background: var(--paper); color: var(--muted); font-size: .8rem; cursor: not-allowed; }
.calendar-day--blank { background: transparent; }
.calendar-day--available { background: #fff; color: var(--ink); border: 1px solid var(--border); cursor: pointer; }
.calendar-day--available:hover { background: var(--accent); color: #fff; }
.calendar-day--current { background: var(--accent); color: #fff; font-weight: 700; }
.calendar-day--today:not(.calendar-day--current) { box-shadow: inset 0 0 0 2px var(--accent); }

.btn-danger { background: #a3232f; }
.btn-danger:hover { opacity: .85; }

.manage-meta-edit { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px; margin-top: 16px; max-width: 480px; }
.manage-meta-edit h2 { margin-top: 0; font-size: 1.05rem; }

/* ---------------------------------------------------------------
   Homepage — "Previous Editions": a compact row of small thumbnail
   cards, side by side. Desktop: wraps into a row (no big card
   padding, no wasted white space). Mobile: a single-line, touch
   swipeable strip (see the 780px query below) instead of a tall
   vertical stack.
   --------------------------------------------------------------- */
.latest-editions { margin-top: 32px; }
.latest-editions h2 { margin-bottom: 4px; }
.edition-preview-list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 16px;
}
.edition-preview-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 108px;
    flex: 0 0 auto;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px;
    color: var(--ink);
    box-shadow: var(--shadow-sm);
    transition: box-shadow .15s ease, transform .15s ease;
}
.edition-preview-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); text-decoration: none; }
.edition-preview-card img {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border-radius: 2px;
    display: block;
    background: var(--paper);
}
.edition-preview-date { font-weight: 600; font-size: .75rem; color: var(--ink); text-align: center; line-height: 1.2; }

/* ---------------------------------------------------------------
   Hotspot "clipping" popup — crop preview + download. Paper-white
   body (not a dark backdrop) so text in the crop is always
   legible, and wide enough on desktop to actually read comfortably.
   --------------------------------------------------------------- */
.hotspot-modal-overlay { position: fixed; inset: 0; background: rgba(20,18,15,0.75); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 200; }
.hotspot-modal-overlay.hidden { display: none; }
.hotspot-modal { background: #fff; border-radius: var(--radius-md); box-shadow: var(--shadow-md); width: min(96vw, 1200px); max-width: 96vw; max-height: 94vh; display: flex; flex-direction: column; overflow: hidden; }
.hotspot-modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); gap: 12px; }
.hotspot-modal-header h3 { margin: 0; font-size: 1rem; }
.hotspot-modal-close { background: none; border: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.hotspot-modal-close:hover { color: var(--ink); }
.hotspot-modal-body { padding: 20px; overflow: auto; background: var(--paper); display: flex; align-items: flex-start; justify-content: center; }
.hotspot-modal-body img { display: block; max-width: 100%; height: auto; border-radius: var(--radius-sm); box-shadow: var(--shadow-sm); background: #fff; }
.hotspot-modal-footer { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--border); }

.page-manager { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.page-thumb { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px; width: 140px; text-align: center; cursor: grab; }
.page-thumb img { width: 100%; border-radius: var(--radius-sm); }

.hotspot-editor { margin-top: 20px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px; }
.hotspot-editor img { max-width: 100%; }

.admin-table, table.admin-table { width: 100%; border-collapse: collapse; margin-top: 16px; background: #fff; }
.admin-table th, .admin-table td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; font-size: .9rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 16px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px; text-align: center; }
.stat-card strong { display: block; font-size: 1.8rem; }
.stat-alert strong { color: var(--accent); }

.admin-nav { display: flex; gap: 16px; margin-top: 20px; }

/* ---------------------------------------------------------------
   Admin > Site Settings — logo/favicon upload fields
   --------------------------------------------------------------- */
.brand-asset-field { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.brand-asset-preview { display: flex; align-items: center; gap: 12px; margin: 8px 0; flex-wrap: wrap; }
.brand-asset-preview img { display: block; max-height: 48px; max-width: 180px; object-fit: contain; background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; }
.brand-asset-preview--favicon img { max-height: 32px; max-width: 32px; }
.brand-asset-remove { font-size: .85rem; color: var(--muted); font-weight: 400; display: flex; align-items: center; gap: 4px; }
.field-hint { font-size: .8rem; color: var(--muted); margin: 4px 0 0; }

.status-badge { padding: 2px 8px; border-radius: 10px; font-size: .75rem; text-transform: capitalize; }
.status-published, .status-done { background: #e9f7ef; color: #1e7e42; }
.status-draft, .status-pending { background: #fff6e0; color: #9a6b00; }
.status-failed { background: #fdeaea; color: #a3232f; }

.simple-list { list-style: none; padding: 0; }
.simple-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }

.error-page { text-align: center; padding: 60px 0; }
.error-page h1 { font-size: 3rem; margin-bottom: 8px; }

/* ---------------------------------------------------------------
   Mobile / touch: hamburger + left drawer takes over the navbar;
   larger tap targets throughout.
   --------------------------------------------------------------- */
@media (max-width: 780px) {
    .site-header { justify-content: space-between; gap: 12px; }
    .nav-toggle { display: inline-flex; order: 1; }
    .brand { order: 2; margin-left: auto; }
    .main-nav, .user-nav { display: none; }

    .nav-drawer-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(20,18,15,.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
        z-index: 150;
    }
    .nav-drawer-overlay.open { opacity: 1; pointer-events: auto; }

    .nav-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 80vw;
        max-width: 300px;
        background: #fff;
        box-shadow: var(--shadow-md);
        z-index: 160;
        transform: translateX(-100%);
        transition: transform .25s ease-out;
    }
    .nav-drawer.open { transform: translateX(0); }
    .nav-drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border); }
    .nav-drawer-brand { font-weight: 700; display: flex; align-items: center; }
    .nav-drawer-brand img { height: 32px; width: auto; max-width: 160px; object-fit: contain; }
    .nav-drawer-close { background: none; border: none; font-size: 1.7rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
    .nav-drawer-links { display: flex; flex-direction: column; padding: 8px 0; overflow-y: auto; }
    .nav-drawer-links a, .nav-drawer-links button {
        display: block; width: 100%; text-align: left; padding: 14px 20px;
        color: var(--ink); border: none; background: none; font-size: 1rem; font-family: inherit;
        min-height: 44px;
    }
    .nav-drawer-links a:hover, .nav-drawer-links button:hover { background: var(--paper); text-decoration: none; }
    .nav-drawer-links hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
    .nav-drawer-links form { margin: 0; }

    body.drawer-open { overflow: hidden; }

    .reader-body { grid-template-columns: 1fr; }
    .stage-nav { position: absolute; top: 50%; transform: translateY(-50%); margin: 0; }
    .stage-nav--prev { left: 4px; }
    .stage-nav--next { right: 4px; }

    .mobile-sidebar-toggle { display: inline-flex; align-items: center; gap: 4px; position: absolute; top: 4px; z-index: 3; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; font-size: .8rem; cursor: pointer; min-height: 40px; }
    .mobile-sidebar-toggle--pages { left: 4px; }
    .mobile-sidebar-toggle--calendar { right: 4px; }

    .reader-sidebar--pages, .reader-sidebar--calendar {
        position: fixed; top: 0; bottom: 0; width: 82vw; max-width: 320px; z-index: 120;
        max-height: none; overflow-y: auto; box-shadow: var(--shadow-md);
        transform: translateX(-110%); transition: transform .2s ease-out;
    }
    .reader-sidebar--pages { left: 0; }
    .reader-sidebar--calendar { right: 0; transform: translateX(110%); }
    .reader-sidebar--pages.open, .reader-sidebar--calendar.open { transform: translateX(0); }
    .sidebar-close { display: block; }

    /* Bigger, easier-to-tap controls on touch screens. */
    .btn, .reader-controls button, .stage-nav, .page-list-item { min-height: 40px; }
    .reader-controls { gap: 8px; }
    /* Prev/Next/Zoom/Download: keep them on one row and let that row
       scroll horizontally instead of wrapping into a cramped stack,
       so nothing overflows the screen edge. */
    .reader-controls {
        flex-wrap: nowrap;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 2px;
    }
    .reader-controls button,
    .reader-controls .btn { flex: 0 0 auto; padding: 8px 12px; font-size: .85rem; white-space: nowrap; }
    .control-sep { display: none; }

    /* Previous editions: single-line, swipeable (touch) strip. */
    .edition-preview-list {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        gap: 10px;
        margin-left: -4px;
        margin-right: -4px;
        padding: 4px 4px 6px;
    }
    .edition-preview-card {
        width: 88px;
        scroll-snap-align: start;
    }
}

@media (max-width: 640px) {
    .hero-epaper { flex-direction: column; }
    .reader-controls { justify-content: flex-start; }
}
