:root {
    --bg: #0d0d0d;
    --bg-card: #151518;
    --bg-hover: #1c1c22;
    --border: #2a2a32;
    --text: #e8e8ec;
    --text-dim: #8888a0;
    --accent-usos: #4a9eff;
    --accent-manual: #3ddc84;
    --accent-ai: #a78bfa;
    --accent-now: #ff4d6a;
    --font-mono: 'JetBrains Mono', monospace;
    --font-heading: 'Space Grotesk', sans-serif;
    --radius: 8px;
    --hour-height: 56px;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

/* ===== HEADER ===== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 100;
}

header h1 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 20px;
    letter-spacing: -0.5px;
}

.header-meta {
    display: flex;
    gap: 12px;
    color: var(--text-dim);
    font-size: 12px;
}

#current-time { color: var(--accent-now); font-weight: 500; }

/* ===== MAIN ===== */
main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

h2 {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 12px;
}

/* Tabs removed in v1.6 — all sections visible, scrollable */
.tabs { display: none; }

/* ===== TIMELINE ===== */
#timeline-container { width: 100%; overflow-x: auto; }

#timeline {
    position: relative;
    height: 90px;
    min-width: 100%;
}

#timeline-hours {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 100%;
    display: flex;
}

.timeline-hour {
    flex: 1;
    border-left: 1px solid var(--border);
    font-size: 10px;
    color: var(--text-dim);
    padding: 2px 0 0 3px;
}

.timeline-hour:first-child { border-left: none; }

#timeline-events {
    position: absolute;
    top: 22px; left: 0; right: 0; bottom: 0;
}

.timeline-event {
    position: absolute;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 500;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: filter 0.15s;
    border: 1px solid transparent;
    /* top, height set by JS for overlap rows */
}

.timeline-event:hover { filter: brightness(1.2); border-color: rgba(255,255,255,0.2); }

.timeline-event.source-usos { background: rgba(74,158,255,0.25); color: var(--accent-usos); }
.timeline-event.source-manual { background: rgba(61,220,132,0.25); color: var(--accent-manual); }
.timeline-event.source-ai { background: rgba(167,139,250,0.25); color: var(--accent-ai); }
.timeline-event.done { opacity: 0.35; }

#timeline-now-line {
    position: absolute;
    top: 0; bottom: 0;
    width: 2px;
    background: var(--accent-now);
    z-index: 10;
    pointer-events: none;
}

#timeline-now-line::after {
    content: '';
    position: absolute;
    top: -2px; left: -3px;
    width: 8px; height: 8px;
    background: var(--accent-now);
    border-radius: 50%;
}

/* ===== WEEK GRID ===== */
.week-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.week-nav button {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font-mono);
    padding: 6px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
}

.week-nav button:hover { background: var(--bg-hover); }
.view-btn { margin-left: auto; font-size: 12px !important; padding: 4px 10px !important; }

#week-grid {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.week-headers { display: flex; }
.week-headers .week-header { flex: 1; }
.week-headers .week-header:first-child { flex: 0 0 40px; }

.week-header {
    background: var(--bg);
    padding: 6px 4px;
    text-align: center;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.week-header.today { color: var(--accent-now); }
.week-body { display: flex; }

.week-time-column {
    flex: 0 0 40px;
    border-right: 1px solid var(--border);
}

.week-time-label {
    background: var(--bg);
    padding: 2px 4px 0 0;
    font-size: 9px;
    color: var(--text-dim);
    text-align: right;
    height: var(--hour-height);
    border-bottom: 1px solid var(--border);
}

.week-day-column {
    flex: 1;
    position: relative;
    border-right: 1px solid var(--border);
}

.week-day-column:last-child { border-right: none; }

.week-hour-slot {
    height: var(--hour-height);
    border-bottom: 1px solid var(--border);
}

.week-hour-slot:hover { background: var(--bg-hover); }

.week-event-block {
    position: absolute;
    border-radius: 4px;
    padding: 2px 4px;
    font-size: 9px;
    font-weight: 500;
    overflow: hidden;
    cursor: pointer;
    z-index: 5;
    transition: filter 0.15s;
    line-height: 1.3;
}

.week-event-block:hover { filter: brightness(1.2); z-index: 10; }
.week-event-block .ev-title { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.week-event-block .ev-time { font-size: 8px; opacity: 0.7; }

.week-event-block.source-usos { background: rgba(74,158,255,0.25); color: var(--accent-usos); border-left: 2px solid var(--accent-usos); }
.week-event-block.source-manual { background: rgba(61,220,132,0.25); color: var(--accent-manual); border-left: 2px solid var(--accent-manual); }
.week-event-block.source-ai { background: rgba(167,139,250,0.25); color: var(--accent-ai); border-left: 2px solid var(--accent-ai); }
.week-event-block.done { opacity: 0.35; }

/* Month grid */
#month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.month-header {
    background: var(--bg);
    padding: 6px;
    text-align: center;
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 600;
}

.month-cell {
    background: var(--bg-card);
    min-height: 60px;
    padding: 4px;
}

.month-cell.other-month { opacity: 0.3; }
.month-cell.today { border: 1px solid var(--accent-now); }
.month-date { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }

.month-event {
    font-size: 9px;
    padding: 1px 3px;
    border-radius: 2px;
    margin-bottom: 1px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    cursor: pointer;
}

.month-event.source-usos { background: rgba(74,158,255,0.2); color: var(--accent-usos); }
.month-event.source-manual { background: rgba(61,220,132,0.2); color: var(--accent-manual); }
.month-event.source-ai { background: rgba(167,139,250,0.2); color: var(--accent-ai); }

/* ===== CHAPEL / MAP ===== */
#chapel-auth {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px 16px;
}

.chapel-hint {
    color: var(--text-dim);
    font-size: 13px;
}

.chapel-form {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 300px;
}

.chapel-form input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 14px;
    outline: none;
}

.chapel-form input:focus { border-color: var(--accent-usos); }

.chapel-form button {
    background: var(--accent-usos);
    border: none;
    color: #fff;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 13px;
    cursor: pointer;
}

.chapel-form button:hover { filter: brightness(1.1); }
.chapel-error { color: var(--accent-now); font-size: 12px; }

#map {
    height: 350px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    z-index: 1;
}

#location-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-dim);
    flex-wrap: wrap;
    gap: 8px;
}

/* Leaflet dark */
.leaflet-container { background: #1a1a20; }
.leaflet-tile { filter: brightness(0.7) contrast(1.1) saturate(0.8); }
.leaflet-control-attribution { background: var(--bg-card) !important; color: var(--text-dim) !important; font-size: 10px !important; }
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-control-zoom a { background: var(--bg-card) !important; color: var(--text) !important; border-color: var(--border) !important; }

/* ===== POPUP ===== */
#event-popup {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.popup-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    max-width: 480px;
    width: 100%;
    position: relative;
    max-height: 80vh;
    overflow-y: auto;
}

.popup-close {
    position: absolute;
    top: 8px; right: 12px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 24px;
    cursor: pointer;
}

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

#popup-title {
    font-family: var(--font-heading);
    font-size: 16px;
    margin-bottom: 12px;
    padding-right: 30px;
}

#popup-body { font-size: 13px; color: var(--text-dim); line-height: 1.7; }
#popup-body .label { color: var(--text); font-weight: 500; }

.hidden { display: none !important; }

/* ===== MOBILE ===== */
@media (max-width: 768px) {
    :root { --hour-height: 44px; }

    header h1 { font-size: 16px; }
    .header-meta { gap: 8px; font-size: 11px; }
    #current-date { display: none; }

    main { padding: 8px; gap: 8px; }
    section { padding: 12px; overflow: hidden; }
    h2 { font-size: 14px; margin-bottom: 8px; }

    /* Timeline scroll na mobile */
    #timeline-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    #timeline { min-width: 600px; }

    /* Week/Month — horizontal scroll */
    #week-grid, #month-grid { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    #week-grid .week-headers, #week-grid .week-body { min-width: 500px; }
    #month-grid { min-width: 450px; }

    .week-headers .week-header:first-child { flex: 0 0 30px; }
    .week-time-column { flex: 0 0 30px; }
    .week-time-label { font-size: 8px; padding: 2px 2px 0 0; }
    .week-header { font-size: 9px; padding: 4px 2px; }
    .week-event-block { font-size: 8px; padding: 1px 2px; }
    .week-event-block .ev-time { display: none; }
    .week-nav h2 { font-size: 12px; }

    .month-cell { min-height: 50px; }
    .month-event { font-size: 8px; }

    #map { height: 250px; }
    #location-meta { font-size: 11px; }
}
