@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@500&display=swap');

:root {
    --ink-950: #10181C;
    --ink-900: #16222A;
    --ink-800: #1E2E38;
    --ink-700: #2B4150;
    --ink-line: #3A5262;
    --paper: #EEF1EC;
    --paper-dim: #C8D0CB;
    --amber: #E3A23C;
    --amber-dim: #B98230;
    --teal: #5FB8A8;
    --rose: #D97878;
    --radius: 3px;

    --font-display: 'Fraunces', Georgia, serif;
    --font-body: 'IBM Plex Sans', -apple-system, sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--ink-950);
    color: var(--paper);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.5;
}

body {
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        linear-gradient(var(--ink-900) 1px, transparent 1px),
        linear-gradient(90deg, var(--ink-900) 1px, transparent 1px);
    background-size: 48px 48px;
    background-position: -1px -1px;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 500; margin: 0 0 0.4em; letter-spacing: -0.01em; }
p { margin: 0 0 1em; color: var(--paper-dim); }
a { color: var(--amber); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select { font-family: var(--font-body); font-size: 15px; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap;
}

/* ---------------------------------------------------------------- */
/* Buttons                                                            */
/* ---------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    padding: 0.7em 1.3em;
    border-radius: var(--radius);
    border: 1px solid var(--ink-line);
    background: var(--ink-800);
    color: var(--paper);
    cursor: pointer;
    font-weight: 500;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.btn:hover { border-color: var(--paper-dim); }
.btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.btn-primary {
    background: var(--amber);
    border-color: var(--amber);
    color: var(--ink-950);
    font-weight: 600;
}
.btn-primary:hover { background: var(--amber-dim); border-color: var(--amber-dim); }

.btn-danger { color: var(--rose); }
.btn-danger:hover { border-color: var(--rose); }

.btn-small { padding: 0.4em 0.8em; font-size: 13px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: default; }

/* ---------------------------------------------------------------- */
/* Form elements                                                      */
/* ---------------------------------------------------------------- */

.field { margin-bottom: 1.1em; }
.field label {
    display: block;
    margin-bottom: 0.4em;
    font-size: 13px;
    color: var(--paper-dim);
}
.field input, .field select {
    width: 100%;
    padding: 0.7em 0.8em;
    background: var(--ink-950);
    border: 1px solid var(--ink-line);
    border-radius: var(--radius);
    color: var(--paper);
}
.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--amber);
}
.field input::placeholder { color: var(--ink-line); }

/* ---------------------------------------------------------------- */
/* Auth screen                                                        */
/* ---------------------------------------------------------------- */

.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    opacity: 1;
    transition: opacity 0.15s ease;
}
/* Hidden until js/auth.js confirms there's no existing session, so an
   already-logged-in visitor never sees a flash of the login form before
   being redirected to the dashboard. */
body.auth-pending .auth-shell { opacity: 0; }
@media (max-width: 860px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-hero { display: none; }
}

.auth-hero {
    position: relative;
    padding: 3.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-right: 1px solid var(--ink-800);
    overflow: hidden;
}

.week-grid {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}
.week-grid > div { border-right: 1px solid var(--ink-800); }
.week-grid > div:last-child { border-right: none; }

.hero-content { position: relative; z-index: 1; }
.hero-mark { font-family: var(--font-mono); font-size: 13px; letter-spacing: 0.06em; color: var(--teal); margin-bottom: 2rem; }
.hero-title { font-size: clamp(2.2rem, 4vw, 3.2rem); max-width: 11ch; line-height: 1.05; color: var(--paper); }
.hero-sub { max-width: 34ch; }

.event-chip {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    background: var(--ink-800);
    border: 1px solid var(--ink-line);
    border-radius: var(--radius);
    padding: 0.5em 0.8em;
    font-size: 13px;
    margin: 0.25em 0.4em 0.25em 0;
}
.event-chip .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2.5rem;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-card .eyebrow { font-family: var(--font-mono); font-size: 12px; color: var(--teal); margin-bottom: 0.6em; }
.auth-card h1 { font-size: 1.8rem; }
.auth-switch { margin-top: 1.5em; font-size: 14px; color: var(--paper-dim); }

.form-panel { display: none; }
.form-panel.active { display: block; }

.alert {
    padding: 0.8em 1em;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 1.2em;
    border: 1px solid transparent;
}
.alert-error { background: rgba(217, 120, 120, 0.12); border-color: var(--rose); color: #F0B4B4; }
.alert-success { background: rgba(95, 184, 168, 0.12); border-color: var(--teal); color: #B7E5DC; }
.alert:empty { display: none; }

/* ---------------------------------------------------------------- */
/* Dashboard shell                                                    */
/* ---------------------------------------------------------------- */

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75em;
    padding: 1rem clamp(1.25rem, 4vw, 4rem);
    border-bottom: 1px solid var(--ink-800);
    background: rgba(16, 24, 28, 0.85);
    backdrop-filter: blur(6px);
    position: sticky;
    top: 0;
    z-index: 10;
}
.app-brand { display: flex; align-items: center; gap: 0.8em; min-width: 0; }
.brand-icon { flex-shrink: 0; border-radius: 7px; width: clamp(36px, 8vw, 46px); height: auto; }
.brand-text { display: flex; flex-direction: column; gap: 0.15em; line-height: 1.1; min-width: 0; }
.app-brand .mark { font-family: var(--font-display); font-size: clamp(1.4rem, 4.5vw, 1.9rem); color: var(--paper); }
.app-brand .tag { font-family: var(--font-mono); font-size: clamp(10.5px, 1.6vw, 12.5px); color: var(--teal); letter-spacing: 0.06em; }

/* User menu (dropdown) */
.app-user { position: relative; flex-shrink: 0; }
.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: 0.6em;
    background: transparent;
    border: 1px solid var(--ink-line);
    border-radius: var(--radius);
    padding: 0.5em 0.7em;
    color: var(--paper);
    font-size: 14px;
    cursor: pointer;
    max-width: 100%;
}
.user-menu-trigger:hover { border-color: var(--paper-dim); }
.user-menu-trigger:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.user-menu-trigger #user-email {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 42vw;
}
.user-menu-trigger .chevron { flex-shrink: 0; color: var(--paper-dim); transition: transform 0.15s ease; }
.user-menu-trigger[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.user-menu {
    display: none;
    position: absolute;
    top: calc(100% + 0.5em);
    right: 0;
    min-width: 150px;
    background: var(--ink-900);
    border: 1px solid var(--ink-800);
    border-radius: var(--radius);
    padding: 0.35em;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    z-index: 20;
}
.user-menu.open { display: block; }
.user-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--paper);
    font-size: 14px;
    padding: 0.6em 0.7em;
    border-radius: var(--radius);
    cursor: pointer;
}
.user-menu button:hover { background: var(--ink-800); color: var(--rose); }

.app-main {
    flex: 1;
    width: 100%;
    padding: 2.5rem clamp(1.25rem, 4vw, 4rem) 5rem;
}

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75em;
    margin-bottom: 1.2rem;
}
.section-head h2 { font-size: 1.4rem; }
.section-head .count { font-family: var(--font-mono); font-size: 12px; color: var(--paper-dim); }

section.block { margin-bottom: 3.5rem; }

.card-list { display: flex; flex-direction: column; gap: 0.4rem; }

.card {
    background: var(--ink-900);
    border: 1px solid var(--ink-800);
    border-radius: var(--radius);
    padding: 0.7rem 1.1rem;
}

.feed-card { display: flex; flex-direction: column; gap: 0.35em; }
.feed-card-top { display: flex; align-items: flex-start; gap: 0.9em; }
.feed-info { flex: 1; min-width: 0; }
.feed-info .name { font-weight: 500; }
.feed-info .url {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--paper-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.feed-actions { display: flex; gap: 0.4em; flex-shrink: 0; }

.sync-line {
    display: flex;
    align-items: baseline;
    gap: 1.75em;
    font-size: 11.5px;
    color: var(--paper-dim);
}
.sync-line .sync-time { flex-shrink: 0; white-space: nowrap; }
.sync-line .sync-status {
    flex: 1;
    min-width: 0;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sync-line .sync-status.sync-ok { color: var(--teal); }
.sync-line .sync-status.sync-error { color: var(--rose); }

.meta {
    font-size: 11.5px;
    color: var(--paper-dim);
    margin-top: 0.25em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.consolidated-card { display: flex; flex-direction: column; gap: 0.5em; }
.consolidated-top { display: flex; align-items: center; justify-content: space-between; gap: 1em; }
.consolidated-top .consolidated-title { min-width: 0; }
.consolidated-top .name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.consolidated-members { display: flex; flex-wrap: wrap; gap: 0.4em; font-size: 12px; color: var(--paper-dim); }
.consolidated-members .member {
    border: 1px solid var(--ink-line);
    border-radius: var(--radius);
    padding: 0.2em 0.55em;
}

.link-row {
    display: flex;
    align-items: center;
    gap: 0.5em;
    background: var(--ink-950);
    border: 1px solid var(--ink-line);
    border-radius: var(--radius);
    padding: 0.6em 0.7em;
}
.link-row input {
    flex: 1;
    min-width: 0;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--teal);
    font-family: var(--font-mono);
    font-size: 12.5px;
}
.link-row input:focus { outline: none; }

.empty-state {
    border: 1px dashed var(--ink-line);
    border-radius: var(--radius);
    padding: 2rem 1.5rem;
    text-align: center;
    color: var(--paper-dim);
}
.empty-state p { margin-bottom: 1em; }

/* ---------------------------------------------------------------- */
/* Checkbox feed picker (used when building a consolidated feed)      */
/* ---------------------------------------------------------------- */

.feed-picker { display: flex; flex-direction: column; gap: 0.5em; margin-bottom: 1.1em; }
.feed-picker-item {
    display: flex;
    align-items: center;
    gap: 0.7em;
    padding: 0.6em 0.8em;
    border: 1px solid var(--ink-line);
    border-radius: var(--radius);
    cursor: pointer;
}
.feed-picker-item input { width: auto; flex-shrink: 0; }
.feed-picker-item .label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------------------------------------------------------------- */
/* Icon buttons (edit / delete)                                       */
/* ---------------------------------------------------------------- */

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    padding: 0;
    border-radius: var(--radius);
    border: 1px solid var(--ink-line);
    background: var(--ink-800);
    color: var(--paper-dim);
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { border-color: var(--paper-dim); color: var(--paper); }
.icon-btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.icon-btn.icon-btn-danger:hover { border-color: var(--rose); color: var(--rose); }

/* ---------------------------------------------------------------- */
/* Modal                                                              */
/* ---------------------------------------------------------------- */

.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 28, 0.7);
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    z-index: 100;
}
.modal-backdrop.active { display: flex; }
.modal {
    background: var(--ink-900);
    border: 1px solid var(--ink-800);
    border-radius: var(--radius);
    padding: 1.8rem;
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
}
.modal h3 { margin-bottom: 1.2em; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.6em; margin-top: 1.4em; }

@media (max-width: 480px) {
    .modal-backdrop { padding: 0.75rem; }
    .modal { padding: 1.25rem; }
}

/* ---------------------------------------------------------------- */
/* Manage-events screen                                               */
/* ---------------------------------------------------------------- */

.back-link {
    display: inline-block;
    margin-bottom: 1.5rem;
    font-size: 13px;
    color: var(--paper-dim);
}
.back-link:hover { color: var(--amber); }

.filter-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.7em;
    margin-bottom: 1.5rem;
}
.filter-bar label { font-size: 13px; color: var(--paper-dim); }
.filter-bar select {
    padding: 0.55em 0.7em;
    background: var(--ink-950);
    border: 1px solid var(--ink-line);
    border-radius: var(--radius);
    color: var(--paper);
    max-width: 100%;
}

.pattern-section { margin-bottom: 2.2rem; }
.pattern-section h3 { font-size: 1.1rem; margin-bottom: 0.3em; }
.section-note { font-size: 13px; margin-bottom: 1em; }

.pattern-list { display: flex; flex-direction: column; gap: 0.35rem; }
.pattern-row {
    display: flex;
    align-items: flex-start;
    gap: 0.8em;
    background: var(--ink-900);
    border: 1px solid var(--ink-800);
    border-radius: var(--radius);
    padding: 0.6em 0.9em;
    cursor: pointer;
}
.pattern-row:hover { border-color: var(--ink-line); }
.pattern-row input[type="checkbox"] { width: auto; flex-shrink: 0; margin-top: 0.3em; }

/* Two lines: the source feed (+ count, for repeated-title groups) on top,
   the actual event title below it -- on a narrow phone screen there isn't
   room for both on one line without squeezing the title down to nothing. */
.pattern-row .pattern-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25em;
}
.pattern-row .pattern-line1 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8em;
}
.pattern-row .feed-tag {
    flex-shrink: 0;
    font-size: 11.5px;
    font-family: var(--font-mono);
    color: var(--teal);
    border: 1px solid var(--ink-line);
    border-radius: var(--radius);
    padding: 0.15em 0.5em;
}
.pattern-row .pattern-summary {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pattern-row .count-badge {
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--paper-dim);
}

.save-bar { margin-top: 1.5rem; display: flex; justify-content: flex-end; }

.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    max-width: calc(100vw - 2rem);
    transform: translateX(-50%) translateY(120%);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    background: var(--ink-800);
    border: 1px solid var(--ink-line);
    color: var(--paper);
    padding: 0.8em 1.3em;
    border-radius: var(--radius);
    font-size: 14px;
    transition: transform 0.25s ease, opacity 0.25s ease, visibility 0s linear 0.25s;
    z-index: 200;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: transform 0.25s ease, opacity 0.25s ease, visibility 0s linear 0s;
}

/* Keyword rules (manage events) */
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 4px 6px 4px 10px; border: 1px solid var(--border, #ccc); border-radius: 999px; font-size: 0.9rem; background: rgba(127,127,127,0.1); }
.chip .chip-feed { opacity: 0.7; font-size: 0.8rem; }
.chip .chip-count { opacity: 0.7; font-size: 0.8rem; }
.chip button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0 4px; }
.keyword-add { display: flex; gap: 8px; margin-bottom: 6px; max-width: 420px; }
.keyword-add input { flex: 1; min-width: 0; }
.keyword-preview-row { padding: 6px 10px; font-size: 0.9rem; border-bottom: 1px solid rgba(127,127,127,0.2); }
