/* ═══════════════════════════════════════════════════════════════════════════
   Bookmark Manager — style.css
   Dark-first design with CSS custom properties for theming.
   ═══════════════════════════════════════════════════════════════════════════ */

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

:root {
    /* Palette */
    --bg:           #0d1117;
    --bg-surface:   #161b22;
    --bg-elevated:  #1c2333;
    --border:       #30363d;
    --border-focus: #58a6ff;

    --text-primary:   #e6edf3;
    --text-secondary: #8b949e;
    --text-muted:     #6e7681;

    --accent:       #58a6ff;
    --accent-hover: #79b8ff;
    --accent-dim:   rgba(88,166,255,.12);

    --green:   #3fb950;
    --red:     #f85149;
    --yellow:  #d29922;
    --orange:  #f0883e;

    --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
    --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

    --radius-sm: 4px;
    --radius:    6px;
    --radius-lg: 10px;

    --shadow: 0 4px 12px rgba(0,0,0,.35);
    --shadow-sm: 0 1px 4px rgba(0,0,0,.25);

    --sidebar-w: 220px;
    --header-h: 52px;
}

html { font-size: 15px; }

body {
    background: var(--bg);
    color: var(--text-primary);
    font-family: var(--sans);
    line-height: 1.6;
    min-height: 100vh;
}

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

code, kbd, .mono {
    font-family: var(--mono);
    font-size: .875em;
    background: var(--bg-elevated);
    padding: .1em .35em;
    border-radius: var(--radius-sm);
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Header ───────────────────────────────────────────────────────────────── */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    height: 100%;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.site-logo {
    font-family: var(--mono);
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
    white-space: nowrap;
}

.header-nav { display: flex; gap: .25rem; }

.nav-link {
    padding: .3rem .75rem;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: .875rem;
    text-decoration: none;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--bg-elevated); color: var(--text-primary); text-decoration: none; }
.nav-link.active { background: var(--accent-dim); color: var(--accent); }

.header-actions { margin-left: auto; display: flex; align-items: center; gap: .75rem; }

.username-badge {
    font-family: var(--mono);
    font-size: .8rem;
    color: var(--text-muted);
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app-layout {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.25rem;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    gap: 1.25rem;
    align-items: start;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
    position: sticky;
    top: calc(var(--header-h) + 1.25rem);
    max-height: calc(100vh - var(--header-h) - 2.5rem);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sidebar-section {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: .875rem;
}

.sidebar-heading {
    font-size: .7rem;
    font-family: var(--mono);
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: .625rem;
    display: flex;
    align-items: center;
    gap: .4rem;
}

.sidebar-empty { font-size: .8rem; color: var(--text-muted); }

/* Tag cloud */
.tag-cloud { display: flex; flex-wrap: wrap; gap: .3rem; }

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .2rem .55rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: .75rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background .15s, border-color .15s, color .15s;
    line-height: 1.4;
}
.tag-pill:hover { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); text-decoration: none; }
.tag-pill.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.tag-count { font-size: .7rem; color: var(--text-muted); }

/* Feed list */
.feed-list { list-style: none; display: flex; flex-direction: column; gap: .15rem; }

.feed-item { display: flex; align-items: center; gap: .25rem; }

.feed-link {
    flex: 1;
    min-width: 0;
    font-size: .8rem;
    color: var(--text-secondary);
    text-decoration: none;
    padding: .3rem .4rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: .4rem;
    transition: background .15s, color .15s;
}
.feed-link:hover { background: var(--bg-elevated); color: var(--text-primary); text-decoration: none; }
.feed-link.active { background: var(--accent-dim); color: var(--accent); }

.unread-badge {
    flex-shrink: 0;
    background: var(--accent);
    color: var(--bg);
    font-size: .65rem;
    font-weight: 700;
    padding: .05rem .35rem;
    border-radius: 999px;
    line-height: 1.6;
}

/* ── Main content ─────────────────────────────────────────────────────────── */
.main-content { min-width: 0; }

.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 1rem;
}

.content-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.highlight {
    font-family: var(--mono);
    color: var(--accent);
    font-size: .95em;
}

/* Search + filter row */
.search-row {
    display: flex;
    gap: .5rem;
    align-items: center;
    margin-bottom: 1rem;
}
.search-row .search-bar {
    flex: 1;
    margin-bottom: 0;
}

.filter-btn { white-space: nowrap; }
.filter-btn.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* Search bar */
.search-bar {
    position: relative;
    margin-bottom: 1rem;
}
.search-bar input {
    width: 100%;
    padding: .6rem 2.5rem .6rem .875rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: .9rem;
    transition: border-color .15s;
}
.search-bar input:focus { outline: none; border-color: var(--border-focus); }
.spinner {
    position: absolute;
    right: .75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px; height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

/* ── Bookmark cards ───────────────────────────────────────────────────────── */
#bookmark-list { display: flex; flex-direction: column; gap: .625rem; }

.bookmark-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: .875rem 1rem;
    transition: border-color .15s, opacity .2s;
}
.bookmark-card:hover { border-color: var(--text-muted); }
.bookmark-card.is-read { opacity: .45; }
.bookmark-card.is-read:hover { opacity: 1; }

.bookmark-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: .25rem;
}

/* Action buttons row */
.bookmark-actions {
    display: flex;
    align-items: center;
    gap: .15rem;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity .15s;
}
.bookmark-card:hover .bookmark-actions,
.bookmark-card:focus-within .bookmark-actions { opacity: 1; }

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px; height: 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: .85rem;
    transition: background .12s, color .12s;
    padding: 0;
    line-height: 1;
}
.btn-icon:hover { background: var(--bg-elevated); color: var(--text-primary); }

.btn-read-toggle { font-size: .9rem; }
.btn-read-toggle.is-read { color: var(--green); }
.btn-read-toggle.is-read:hover { color: var(--text-muted); }

/* Edit form inside card */
.bookmark-edit {
    padding-top: .5rem;
    border-top: 1px solid var(--border);
    margin-top: .25rem;
}
.edit-grid { display: flex; flex-direction: column; gap: 0; }
.edit-grid .field { margin-bottom: .6rem; }
.edit-grid .field:last-of-type { margin-bottom: 0; }

.favicon {
    width: 16px; height: 16px;
    border-radius: 2px;
    flex-shrink: 0;
    object-fit: contain;
}
.favicon-placeholder {
    width: 16px; height: 16px;
    background: var(--bg-elevated);
    border-radius: 2px;
    flex-shrink: 0;
}

.bookmark-title {
    flex: 1;
    min-width: 0;
    font-size: .95rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
}
.bookmark-title:hover { color: var(--accent); text-decoration: underline; }

.bookmark-desc {
    font-size: .825rem;
    color: var(--text-secondary);
    margin-bottom: .4rem;
    line-height: 1.5;
}

.bookmark-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem .75rem;
    font-size: .75rem;
}

.bookmark-url { color: var(--text-muted); font-family: var(--mono); font-size: .72rem; }
.bookmark-date { color: var(--text-muted); }

.bookmark-tags { display: flex; flex-wrap: wrap; gap: .25rem; }

.tag-chip {
    display: inline-block;
    padding: .1rem .45rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: .7rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background .15s, color .15s;
}
.tag-chip:hover { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); text-decoration: none; }

/* ── Feed cards ───────────────────────────────────────────────────────────── */
#feed-items { display: flex; flex-direction: column; gap: .5rem; }

.feed-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: .75rem 1rem;
    transition: border-color .15s, opacity .15s;
}
.feed-card.is-read { opacity: .55; }
.feed-card:hover { border-color: var(--text-muted); opacity: 1; }

.feed-card-header {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    margin-bottom: .2rem;
}

.feed-item-title {
    flex: 1;
    font-size: .9rem;
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
    line-height: 1.4;
}
.feed-item-title:hover { color: var(--accent); text-decoration: underline; }

.feed-item-summary {
    font-size: .8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: .35rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.feed-item-meta {
    display: flex;
    gap: .75rem;
    font-size: .72rem;
    color: var(--text-muted);
}
.feed-name { font-family: var(--mono); }
.feed-date { }

/* ── Forms & cards ────────────────────────────────────────────────────────── */
.form-card, .card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.form-title { font-size: .95rem; font-weight: 600; margin-bottom: 1rem; color: var(--text-primary); }

.field { margin-bottom: .875rem; }

.field label {
    display: block;
    font-size: .8rem;
    color: var(--text-secondary);
    margin-bottom: .3rem;
}

.field-hint { color: var(--text-muted); font-size: .75em; }

.field input,
.field textarea,
.field select {
    width: 100%;
    padding: .55rem .75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: .875rem;
    font-family: inherit;
    transition: border-color .15s;
    resize: vertical;
}
.field input:focus,
.field textarea:focus,
.field select:focus { outline: none; border-color: var(--border-focus); }
.field input::placeholder,
.field textarea::placeholder { color: var(--text-muted); }

.url-row { display: flex; gap: .5rem; }
.url-row input { flex: 1; min-width: 0; }

.form-actions, .modal-actions {
    display: flex;
    gap: .5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: background .15s, border-color .15s, color .15s, opacity .15s;
    white-space: nowrap;
    line-height: 1.4;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; color: var(--bg); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text-primary); text-decoration: none; }

.btn-danger {
    background: transparent;
    color: var(--red);
    border-color: var(--red);
}
.btn-danger:hover:not(:disabled) { background: rgba(248,81,73,.12); text-decoration: none; color: var(--red); }

.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-xs { padding: .15rem .4rem; font-size: .72rem; line-height: 1.5; }
.btn-full { width: 100%; justify-content: center; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal[hidden] { display: none; }

.modal-box {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow);
}

.modal-title { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
    padding: .7rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    margin-bottom: 1rem;
}
.alert-error   { background: rgba(248,81,73,.12); border: 1px solid var(--red);    color: #ff7b72; }
.alert-success { background: rgba(63,185,80,.1);  border: 1px solid var(--green);  color: var(--green); }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: .9rem;
}
.empty-hint { margin-top: .5rem; font-size: .8rem; }

/* ── Toast notifications ──────────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    pointer-events: none;
}

.toast {
    padding: .7rem 1.1rem;
    border-radius: var(--radius);
    font-size: .85rem;
    box-shadow: var(--shadow);
    animation: toast-in .2s ease;
    pointer-events: auto;
    max-width: 320px;
}
.toast-success { background: #1a2d1a; border: 1px solid var(--green); color: var(--green); }
.toast-error   { background: #2d1a1a; border: 1px solid var(--red);   color: #ff7b72; }
@keyframes toast-in { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }

/* ── Login page ───────────────────────────────────────────────────────────── */
body.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
}

.login-title {
    font-family: var(--mono);
    font-size: 1.3rem;
    color: var(--accent);
    margin-bottom: 1.5rem;
    text-align: center;
}

.login-form .field { margin-bottom: .875rem; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
        padding: .75rem;
    }

    .sidebar {
        position: static;
        max-height: none;
    }

    /* Collapse tag cloud on mobile */
    .tag-cloud {
        max-height: 120px;
        overflow-y: auto;
    }

    .content-header { flex-wrap: wrap; }
    .header-inner { gap: .75rem; }
    .username-badge { display: none; }
    .url-row { flex-wrap: wrap; }
}

@media (max-width: 480px) {
    .bookmark-header { flex-wrap: wrap; }
    .header-nav .nav-link span { display: none; }
}
