/* ============================================================
   histoir.es — Styles
   ============================================================ */

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

:root {
    --bg: #faf9f6;
    --surface: #fff;
    --text: #2c2c2c;
    --muted: #6c757d;
    --border: #e8e5e0;
    --accent: #8b4513;
    --accent-light: #f5ebe0;
    --header-h: 48px;
    --sidebar-w: 200px;

    --cat-politics: #1a5276;
    --cat-geopolitics: #c0392b;
    --cat-territory: #6c3483;
    --cat-colonisation: #8b4513;
    --cat-science: #2980b9;
    --cat-culture: #8e44ad;
    --cat-economy: #27ae60;
    --cat-health: #e67e22;
    --cat-society: #16a085;
    --cat-technology: #2dd4bf;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* --- Header --- */
.site-header {
    position: sticky; top: 0; z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: var(--header-h);
}
.header-inner {
    max-width: 1600px; margin: 0 auto;
    padding: 0 1rem; height: 100%;
    display: flex; align-items: center; gap: 1rem;
}
.logo {
    font-family: 'Playfair Display', serif;
    font-size: 1.3rem; font-weight: 700;
    color: var(--text); text-decoration: none;
}
.logo-dot { color: var(--accent); }
.header-search {
    margin-left: auto;
    display: flex; align-items: center; gap: 0.3rem;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 16px; padding: 0.2rem 0.6rem;
}
.header-search i { color: var(--muted); font-size: 0.8rem; }
.header-search input {
    border: none; background: transparent; outline: none;
    font-size: 0.78rem; width: 160px; color: var(--text);
}
.filter-toggle {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    border: 1px solid var(--border); border-radius: 6px;
    background: transparent; color: var(--muted);
    cursor: pointer; font-size: 0.9rem;
    transition: all 0.15s;
}
.filter-toggle:hover { background: var(--accent-light); color: var(--text); }
.filter-toggle.has-filter { color: var(--accent); border-color: var(--accent); }
.header-count {
    font-size: 0.75rem; color: var(--muted);
    white-space: nowrap;
}

/* --- Timeline section --- */
.timeline-section {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

/* Century bar */
.century-bar {
    display: flex; gap: 2px;
    padding: 0.4rem 1rem;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
}
.century-bar::-webkit-scrollbar { height: 0; }
.c-btn {
    padding: 0.2rem 0.55rem;
    border: 1px solid var(--border); border-radius: 12px;
    background: transparent; font-size: 0.68rem; font-weight: 500;
    color: var(--muted); cursor: pointer;
    white-space: nowrap; transition: all 0.15s;
}
.c-btn:hover { background: var(--accent-light); color: var(--text); }
.c-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.c-btn .cnt { font-size: 0.6rem; opacity: 0.65; margin-left: 2px; }

/* Timeline wrapper with nav arrows */
.timeline-wrapper {
    position: relative;
    display: flex;
    align-items: stretch;
}
.tl-nav {
    flex-shrink: 0;
    width: 32px;
    border: none;
    background: var(--surface);
    color: var(--muted);
    font-size: 1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
    border-right: 1px solid var(--border);
}
.tl-nav:last-child { border-right: none; border-left: 1px solid var(--border); }
.tl-nav:hover { background: var(--accent-light); color: var(--text); }

/* Timeline viewport */
.timeline-viewport {
    flex: 1;
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    cursor: grab;
    scroll-behavior: smooth;
}
.timeline-viewport:active { cursor: grabbing; }
.timeline-viewport::-webkit-scrollbar { height: 5px; }
.timeline-viewport::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

.timeline-scroll {
    position: relative;
    min-width: 100%;
    /* width set by JS based on period count */
}

/* Timeline bands */
.tl-band {
    position: relative;
    height: 22px;
    width: 100%;
}
.tl-leaders { background: #f8f6f3; }
.tl-wars { background: #fdf5f5; }

.tl-segment {
    position: absolute; top: 1px;
    height: calc(100% - 2px);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    font-size: 0.6rem; font-weight: 500;
    color: #fff; white-space: nowrap;
    border-radius: 2px; opacity: 0.9;
    border-right: 1px solid rgba(255,255,255,0.3);
}
.tl-segment span {
    overflow: hidden; text-overflow: ellipsis;
    padding: 0 3px;
}

/* Leader dynasty colors */
.dy-merovingiens { background: #5b7553; }
.dy-carolingiens { background: #8b6914; }
.dy-robertiens   { background: #6b8e6b; }
.dy-capetiens    { background: #1a5276; }
.dy-valois       { background: #6c3483; }
.dy-bourbons     { background: #b8860b; }
.dy-orleans      { background: #d4a017; }
.rg-republic     { background: #2c5f8a; }
.rg-empire       { background: #6b3a6b; }
.rg-revolution   { background: #c0392b; }
.rg-transitional { background: #7f8c8d; }

/* War color */
.tl-war { background: #c0392b; }

/* Period markers — horizontal bar with 5-year links */
.tl-periods {
    position: relative;
    height: 36px;
    display: flex;
    border-top: 1px solid var(--border);
}
.tl-period {
    flex-shrink: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 2px;
    font-size: 0.7rem; font-weight: 600;
    color: var(--muted);
    border-right: 1px solid var(--border);
    cursor: pointer; transition: all 0.15s;
    position: relative;
}
.tl-period:hover { background: var(--accent-light); }
.tl-period.active { background: var(--accent); color: #fff; }
.tl-period.active .tl-dot { background: #fff; }
.tl-period-year { font-size: 0.68rem; }
.tl-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--accent); flex-shrink: 0;
}
.tl-count {
    font-size: 0.55rem; font-weight: 400; opacity: 0.6;
}

/* Year pills — sub-navigation within selected 5-year period */
.year-pills-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.4rem 1rem;
    display: flex; justify-content: center;
}
.year-pills {
    display: flex; gap: 0.35rem; align-items: center;
}
.yr-pill {
    padding: 0.25rem 0.65rem;
    border: 1px solid var(--border); border-radius: 14px;
    background: transparent; font-size: 0.78rem; font-weight: 500;
    color: var(--text); cursor: pointer;
    transition: all 0.15s;
}
.yr-pill:hover:not(:disabled) { background: var(--accent-light); }
.yr-pill.active {
    background: var(--accent); color: #fff; border-color: var(--accent);
}
.yr-pill.empty {
    opacity: 0.35; cursor: default;
}
.yr-pill:disabled { cursor: default; }
.yr-cnt {
    font-size: 0.6rem; background: rgba(0,0,0,0.12);
    padding: 0.05rem 0.3rem; border-radius: 8px; margin-left: 0.2rem;
}
.yr-pill.active .yr-cnt { background: rgba(255,255,255,0.3); }

/* --- Main content --- */
.main-content {
    max-width: 1600px; margin: 0 auto;
    padding: 1rem;
    min-height: 50vh;
}

/* Offcanvas filters */
.offcanvas-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,0.3);
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s;
}
.offcanvas-overlay.open { opacity: 1; pointer-events: auto; }

.offcanvas-panel {
    position: fixed; top: 0; right: -280px; z-index: 210;
    width: 260px; height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 20px rgba(0,0,0,0.1);
    transition: right 0.3s ease;
    display: flex; flex-direction: column;
}
.offcanvas-panel.open { right: 0; }

.offcanvas-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.offcanvas-header h3 {
    font-size: 1rem; font-weight: 700; margin: 0;
}
.offcanvas-close {
    border: none; background: none;
    font-size: 1.1rem; color: var(--muted);
    cursor: pointer;
}
.offcanvas-close:hover { color: var(--text); }

.offcanvas-body {
    flex: 1; overflow-y: auto;
    padding: 0.75rem 1rem;
}
.offcanvas-body h4 {
    font-size: 0.72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--muted); margin: 0.8rem 0 0.3rem;
}
.offcanvas-body h4:first-child { margin-top: 0; }

.f-btn {
    display: flex; align-items: center; gap: 0.35rem;
    padding: 0.25rem 0.4rem; width: 100%;
    border: none; border-radius: 3px;
    background: transparent; font-size: 0.73rem;
    color: var(--text); cursor: pointer; text-align: left;
    transition: background 0.1s;
}
.f-btn:hover { background: var(--accent-light); }
.f-btn.active { background: var(--accent-light); font-weight: 600; }
.f-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.f-cnt { margin-left: auto; font-size: 0.6rem; color: var(--muted); }

/* Events panel */
.events-panel { flex: 1; min-width: 0; }
.events-header {
    display: flex; align-items: baseline; gap: 0.6rem;
    margin-bottom: 0.75rem;
}
.events-header h2 {
    font-family: 'Playfair Display', serif;
    font-size: 1.3rem;
}
.events-count { font-size: 0.78rem; color: var(--muted); }

/* Events grid — category rows with horizontal cards */
.events-grid {
    display: flex; flex-direction: column; gap: 0.6rem;
}
.cat-row {
    display: flex; align-items: stretch; gap: 0.5rem;
}
.cat-label {
    flex-shrink: 0; width: 110px;
    display: flex; align-items: center; gap: 0.3rem;
    padding: 0.25rem 0.4rem; border-radius: 4px;
    color: #fff; font-size: 0.68rem; font-weight: 600;
    white-space: normal; line-height: 1.15;
    align-self: flex-start;
}
.cat-label i { font-size: 0.75rem; flex-shrink: 0; }

/* Parent bar */
.parent-bar-container { display: flex; gap: 0.3rem; margin-bottom: 0.2rem; }
.parent-bar {
    flex: 1; min-width: 0;
    display: flex; align-items: center;
    padding: 0.15rem 0.4rem; border-radius: 3px;
    color: #fff; font-size: 0.65rem; font-weight: 600;
    text-decoration: none; opacity: 0.9;
    overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.parent-bar:hover { opacity: 1; text-decoration: none; color: #fff; }
.parent-bar-dates {
    margin-left: auto; font-weight: 400; opacity: 0.75;
    padding-left: 0.4rem; flex-shrink: 0;
}

.cat-content { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; }

.cards-scroll {
    display: flex; gap: 0.4rem;
    overflow-x: auto; padding-bottom: 2px;
}
.cards-scroll::-webkit-scrollbar { height: 3px; }
.cards-scroll::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 2px; }

/* Event card */
.ev-card {
    flex-shrink: 0; width: 190px;
    display: flex; gap: 0.35rem;
    padding: 0.3rem; border-radius: 5px;
    background: var(--surface);
    border: 1px solid rgba(0,0,0,0.07);
    text-decoration: none; color: inherit;
    position: relative; z-index: 1;
    transition: width 0.25s ease, box-shadow 0.2s;
}
.ev-card:hover {
    width: 340px; z-index: 10;
    border-color: rgba(0,0,0,0.2);
    box-shadow: 0 3px 10px rgba(0,0,0,0.12);
    text-decoration: none; color: inherit;
}
.ev-card:hover .ev-title { -webkit-line-clamp: unset; }
.ev-card:hover .ev-summary { display: block; }

.ev-img {
    width: 44px; height: 44px;
    object-fit: cover; border-radius: 3px;
    flex-shrink: 0; background: #f0f0f0;
}
.ev-img-ph {
    width: 44px; height: 44px; border-radius: 3px;
    background: #f0f0f0;
    display: flex; align-items: center; justify-content: center;
    color: #bbb; font-size: 0.9rem; flex-shrink: 0;
}

.ev-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.ev-date { font-size: 0.58rem; color: var(--muted); }
.ev-title {
    font-size: 0.72rem; font-weight: 600; line-height: 1.2;
    display: -webkit-box; -webkit-line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden;
}
.ev-scope { font-size: 0.55rem; color: var(--muted); }
.ev-summary {
    display: none; font-size: 0.65rem; color: #555;
    line-height: 1.3; margin-top: 2px;
    max-height: 80px; overflow-y: auto;
}

/* Loading / empty */
.loading { text-align: center; padding: 2rem; color: var(--muted); font-size: 0.85rem; }

/* Footer */
.site-footer {
    text-align: center; padding: 1.5rem;
    color: var(--muted); font-size: 0.75rem;
    border-top: 1px solid var(--border); margin-top: 2rem;
}

/* Responsive */
@media (max-width: 768px) {
    .header-search input { width: 100px; }
    .cat-label { width: 80px; font-size: 0.6rem; }
    .ev-card { width: 160px; }
}
