/* Butter — Mobile-first news reader */

/*
 * Theme tokens. Default = light. Dark applies when:
 *   <html data-theme="dark">                                   (explicit user pick)
 *   <html data-theme="auto"> AND OS prefers-color-scheme: dark (follow system)
 *
 * Tokens live in one place so refactors don't need to track scattered media queries.
 */

:root {
    --bg: #fafafa;
    --text: #222;
    --card-bg: #fff;
    --card-border: #e8e8e8;
    --header-bg: #fff;
    --header-border: #e0e0e0;
    --muted: #888;
    --tab-bg: #f0f0f0;
    --tab-active: #222;
    --tab-active-text: #fff;
    --card-active: #eef4ff;
    --text-muted-2: #aaa;
    --debug-bg: #fef9c3;
    --debug-border: #eab308;
    --debug-text: #713f12;
    --debug-tag-bg: rgba(0,0,0,0.08);
}

:root[data-theme="dark"] {
    --bg: #111;
    --text: #ddd;
    --card-bg: #1a1a1a;
    --card-border: #333;
    --header-bg: #1a1a1a;
    --header-border: #333;
    --muted: #777;
    --tab-bg: #222;
    --tab-active: #ddd;
    --tab-active-text: #111;
    --card-active: #1f2a44;
    --text-muted-2: #555;
    --debug-bg: #422006;
    --debug-border: #a16207;
    --debug-text: #fef08a;
    --debug-tag-bg: rgba(255,255,255,0.1);
}

@media (prefers-color-scheme: dark) {
    :root[data-theme="auto"] {
        --bg: #111;
        --text: #ddd;
        --card-bg: #1a1a1a;
        --card-border: #333;
        --header-bg: #1a1a1a;
        --header-border: #333;
        --muted: #777;
        --tab-bg: #222;
        --tab-active: #ddd;
        --tab-active-text: #111;
        --card-active: #1f2a44;
        --text-muted-2: #555;
        --debug-bg: #422006;
        --debug-border: #a16207;
        --debug-text: #fef08a;
        --debug-tag-bg: rgba(255,255,255,0.1);
    }
}

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

body {
    font-family: 'Noto Sans Tamil', 'Noto Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.65;
    max-width: 700px;
    margin: 0 auto;
    transition: background 0.3s, color 0.3s;
}

/* Header */
header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
}

.top-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
}

.top-bar-side {
    /* empty spacer column so .brand centers under the layout's true middle
     * even with controls on the right */
    min-width: 0;
}

.brand {
    text-align: center;
    min-width: 0;
}

.brand h1 {
    font-size: 1.25em;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
    letter-spacing: 0.01em;
}

.brand-tagline {
    margin-top: 2px;
    font-size: 0.65em;
    font-weight: 400;
    color: var(--muted);
    line-height: 1.4;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.controls {
    justify-self: end;
}

@media (max-width: 480px) {
    .brand h1 { font-size: 1.1em; }
    .brand-tagline { display: none; }
}

.controls {
    display: flex;
    gap: 6px;
}

.ctrl-btn {
    background: none;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.8em;
    cursor: pointer;
    color: var(--text);
}

.ctrl-btn:hover { background: var(--card-border); }

/* Category tabs */
.tabs {
    display: flex;
    overflow-x: auto;
    gap: 6px;
    padding: 6px 16px 10px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
    background: var(--tab-bg);
    border: none;
    border-radius: 16px;
    padding: 4px 14px;
    font-size: 0.78em;
    font-family: inherit;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-block;
}

.tab.active {
    background: var(--tab-active);
    color: var(--tab-active-text);
}

.tab-count {
    font-size: 0.85em;
    opacity: 0.6;
}

/* Feed */
main {
    padding: 8px 12px;
}

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 10px;
}

.card.read {
    opacity: 0.7;
}

.read-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 0.7em;
    color: var(--muted);
}

.read-label::before,
.read-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--card-border);
}

.read-label span {
    white-space: nowrap;
}

.card h2 {
    font-size: 1.05em;
    font-weight: 700;
    line-height: 1.5;
    color: var(--text);
    margin-bottom: 8px;
}

.card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    margin-bottom: 10px;
}

.pill {
    color: #fff;
    padding: 2px 10px;
    border-radius: 8px;
    font-size: 0.68em;
    font-weight: 600;
    display: inline-block;
}

.card-time {
    color: var(--muted);
    font-size: 0.72em;
}

.card-category {
    color: var(--muted);
    font-size: 0.68em;
    background: var(--tab-bg);
    padding: 2px 8px;
    border-radius: 8px;
}

.card-fetched {
    color: var(--muted);
    font-size: 0.65em;
    font-style: italic;
    margin-left: 4px;
}

.card-summary {
    color: var(--text);
    font-size: 0.9em;
    line-height: 1.7;
    margin: 10px 0;
    flex: 1;
}

.card-summary p {
    margin-bottom: 8px;
}

/* Debug band */
.debug-band {
    background: var(--debug-bg);
    border: 1px solid var(--debug-border);
    border-radius: 6px;
    padding: 6px 10px;
    margin: 8px 0;
    font-size: 0.65em;
    line-height: 1.6;
    color: var(--debug-text);
}

.debug-band .debug-label {
    font-weight: 700;
    margin-right: 4px;
}

.debug-band .debug-tag {
    display: inline-block;
    background: var(--debug-tag-bg);
    padding: 0 5px;
    border-radius: 3px;
    margin: 1px 2px;
}

.debug-band .debug-tag.debug-id {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    user-select: all;
    cursor: text;
}

/* Source links in card */
.card-sources {
    border-top: 1px solid var(--card-border);
    padding-top: 10px;
    margin-top: 8px;
}

.source-link {
    padding: 2px 0;
    display: flex;
    align-items: baseline;
    min-width: 0;
}

.source-link-name {
    font-size: 0.6em;
    font-weight: 600;
    margin-right: 4px;
    flex-shrink: 0;
}

.source-link a {
    color: var(--text);
    text-decoration: none;
    font-size: 0.65em;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.source-link a:hover { text-decoration: underline; }

/* Feedback */
.card-feedback {
    border-top: 1px solid var(--card-border);
    padding-top: 10px;
    margin-top: 8px;
    text-align: center;
}

.feedback-trigger {
    color: var(--muted);
    font-size: 0.72em;
    text-decoration: none;
    cursor: pointer;
}

.feedback-trigger:hover { text-decoration: underline; }

.feedback-options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}

.feedback-pill {
    background: var(--tab-bg);
    border: none;
    border-radius: 16px;
    padding: 6px 14px;
    font-size: 0.72em;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
    min-height: 36px;
    transition: background 0.15s;
}

.feedback-pill:hover { background: var(--card-border); }

.feedback-thanks {
    color: var(--muted);
    font-size: 0.72em;
}

.feedback-error {
    color: #c0392b;
    font-size: 0.72em;
}

/* மேலும் button */
.card-more {
    text-align: center;
    padding-top: 10px;
    border-top: 1px solid var(--card-border);
}

.more-btn {
    background: none;
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 6px 20px;
    font-size: 0.8em;
    font-family: inherit;
    color: var(--muted);
    cursor: pointer;
}

.more-btn:hover { background: var(--card-border); }

/* மேலும் overlay (bottom sheet) */
.more-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.more-sheet {
    background: var(--card-bg);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 700px;
    max-height: 70vh;
    overflow-y: auto;
    padding-bottom: 20px;
}

.more-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--card-border);
    position: sticky;
    top: 0;
    background: var(--card-bg);
}

.more-header span {
    font-weight: 700;
    font-size: 0.95em;
}

.more-close {
    background: none;
    border: none;
    font-size: 1.8em;
    color: var(--muted);
    cursor: pointer;
    padding: 0 8px;
}

.more-content {
    padding: 8px 16px;
}

.more-source {
    padding: 10px 0;
    border-bottom: 1px solid var(--card-border);
}

.more-source:last-child { border-bottom: none; }

.more-source-name {
    font-size: 0.75em;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 4px;
}

.more-source a {
    color: var(--text);
    text-decoration: none;
    font-size: 0.88em;
    line-height: 1.5;
    display: block;
}

.more-source a:hover { text-decoration: underline; }

/* Read divider */
.read-divider {
    text-align: center;
    color: var(--muted);
    font-size: 0.75em;
    padding: 12px 0;
    letter-spacing: 0.05em;
    border-top: 1px solid var(--card-border);
    margin-top: 8px;
}

/* Sentinel sits at the top of the recent-read band; an IntersectionObserver
 * watches it to load older reads when the user scrolls up to it. */
.load-more-sentinel {
    height: 1px;
    margin: 0;
    pointer-events: none;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--muted);
}

/* Empty state */
.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
}

/* Desktop two-pane (Google Reader style). Mobile/tablet keep single column. */

#feed-list, #splitter, #feed-detail { display: none; }

@media (min-width: 1024px) {
    body {
        max-width: 100%;
    }

    #app {
        display: grid;
        grid-template-columns: var(--list-width, 380px) 4px 1fr;
        height: calc(100vh - var(--header-h, 96px));
    }

    /* Hide mobile single-column feed */
    #feed { display: none; }

    #feed-list {
        display: block;
        overflow-y: auto;
        border-right: 1px solid var(--card-border);
        background: var(--bg);
    }

    #splitter {
        display: block;
        background: var(--card-border);
        cursor: col-resize;
        user-select: none;
        touch-action: none;
        transition: background 0.15s;
    }
    #splitter:hover, #splitter.dragging { background: var(--tab-active); }

    #feed-detail {
        display: block;
        overflow-y: auto;
        padding: 16px 24px;
        background: var(--bg);
    }

    /* Inside the detail pane the existing card chrome is overkill; flatten */
    #feed-detail .card {
        max-width: 800px;
        margin: 0 auto;
        border: none;
        background: transparent;
        padding: 8px 0;
    }
    #feed-detail .card.read { opacity: 1; }
    #feed-detail .card .read-label { display: none; }

    /* Empty state for the right pane */
    #feed-detail .detail-empty {
        text-align: center;
        padding: 80px 20px;
        color: var(--muted);
        font-size: 0.95em;
    }

    /* List rows in left pane */
    .list-item {
        padding: 10px 14px 11px;
        border-bottom: 1px solid var(--card-border);
        cursor: pointer;
        transition: background 0.1s;
    }
    .list-item:hover { background: var(--tab-bg); }
    .list-item.active {
        background: var(--card-active);
        border-left: 3px solid var(--tab-active);
        padding-left: 11px;
    }
    .list-item .list-headline {
        font-size: 0.95em;
        font-weight: 700;
        line-height: 1.45;
        color: var(--text);
        margin-bottom: 5px;
    }
    .list-item.read .list-headline {
        font-weight: 400;
        color: var(--text-muted-2);
    }
    .list-item.read.active .list-headline { color: var(--text); }
    .list-item .list-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
        align-items: center;
        font-size: 0.7em;
        color: var(--muted);
    }
    .list-item .list-meta .cat {
        background: var(--tab-bg);
        padding: 1px 7px;
        border-radius: 8px;
    }

    .list-item .read-divider { padding: 8px 0; }
}

/* Gear icon button (sits inside .controls) */
.ctrl-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    color: var(--muted);
}
.ctrl-icon:hover { color: var(--text); }

/* Settings overlay (centered modal) */
.settings-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.settings-sheet {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    width: 100%;
    max-width: 460px;
    max-height: 80vh;
    overflow-y: auto;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px 12px;
    border-bottom: 1px solid var(--card-border);
}

.settings-header span {
    font-weight: 700;
    font-size: 0.95em;
}

.settings-content {
    padding: 14px 18px 20px;
}

.settings-section {
    margin-bottom: 18px;
}
.settings-section:last-child { margin-bottom: 0; }

.settings-label {
    font-size: 0.75em;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.theme-picker {
    display: flex;
    gap: 6px;
}

.theme-opt {
    flex: 1;
    background: var(--tab-bg);
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.85em;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s;
}
.theme-opt:hover { background: var(--card-border); }
.theme-opt.active {
    background: var(--tab-active);
    color: var(--tab-active-text);
    border-color: var(--tab-active);
}

.settings-about p {
    font-size: 0.85em;
    line-height: 1.55;
    color: var(--text);
    margin-bottom: 6px;
}

.settings-version {
    color: var(--muted);
    font-size: 0.75em !important;
    margin-top: 8px !important;
}
