.brand{display:flex; align-items:center; gap:10px;}
.brand .logo{width:22px; height:22px; display:inline-block; color: var(--acc);}
.brand .logo svg{width:100%; height:100%;}
:root {
    /* LIGHT theme (default) */
    --bg: #f7f8fb;
    --fg: #111827;
    --muted: #6b7280;
    --card: #ffffff;
    --acc: #2563eb;
    --border: #e5e7eb;
    --input: #ffffff;
    --input-border: #d1d5db;
    --btn: #f3f4f6;
    --btn-hover: #e5e7eb;
    --pill-text: #1f2937;
    --pill-bg: #eef2ff;
    --pill-hover-bg: #e0e7ff;
    --tt-bg: #111827;   /* tooltip background */
    --tt-fg: #f9fafb;   /* tooltip text */
    /* New item flash (light) */
    --new-bg-start: #dbeafe;     /* bg at 0% */
    --new-bg-mid:   #eff6ff;     /* bg at 60% */
    --new-bg-end:   transparent; /* bg at 100% */
    --new-br-start: #93c5fd;     /* border at 0% */
    --new-br-mid:   #bfdbfe;     /* border at 60% */
    --new-br-end:   var(--border); /* border at 100% */
    --pre-bg: #f9fafb;       /* subtle light background for code/view box */
    --pre-border: var(--border);
    --pre-fg: var(--fg);
    --page-bg: linear-gradient(180deg, #ffffff 0%, #f5f7ff 40%, #f7f8fb 100%);
}

:root[data-theme="dark"] {
    /* DARK theme */
    --bg: #0b0e14;
    --fg: #e6e6e6;
    --muted: #a0a0a0;
    --card: #151a23;
    --acc: #4da3ff;
    --border: #1f2531;
    --input: #0e1320;
    --input-border: #333333;
    --btn: #1f2937;        /* lighter than before for contrast */
    --btn-hover: #374151;  /* clearer hover */
    --pill-text: #e6e6e6;  /* use main fg for legibility */
    --pill-bg: #1f2937;        /* slate-800 */
    --pill-hover-bg: #334155;  /* slate-700 */
    --tt-bg: #111827;   /* tooltip background (dark) */
    --tt-fg: #e5e7eb;   /* tooltip text (dark) */
    /* New item flash (dark) */
    --new-bg-start: #0b2239;     /* deeper navy */
    --new-bg-mid:   #0f2a4a;     /* subtle mid */
    --new-bg-end:   transparent; /* fade to transparent */
    --new-br-start: #1e3a8a;     /* blue-800 */
    --new-br-mid:   #1d4ed8;     /* blue-700 */
    --new-br-end:   var(--border);
    --pre-bg: #0f172a;       /* dark slate */
    --pre-border: #334155;   /* slate-700 */
    --pre-fg: #e6e6e6;
    --page-bg: linear-gradient(180deg, #0c111a 0%, #0b0e14 100%);
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, sans-serif;
    background: var(--page-bg);
    background-attachment: fixed;
    color: var(--fg);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 12px;
    align-items: center;
    flex: 0 0 auto;
    background: var(--card);
}

h1 {
    font-size: 16px;
    margin: 0;
}

.wrap {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 18px;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    align-items: center;
}

input[type="text"] {
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    background: var(--input);
    color: var(--fg);
    border-radius: 10px;
    width: 260px;
}

button {
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    background: var(--btn);
    color: var(--fg);
    border-radius: 10px;
    cursor: pointer;
}

button:hover {
    background: var(--btn-hover);
    border-color: var(--input-border);
}

.grid {
    display: grid;
    grid-template-columns: 220px 1fr 1fr;
    gap: 12px;
    flex: 1 1 auto;
    min-height: 0;
}
.cats {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 8px;
    overflow: auto;
    min-height: 0;
}
.cat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    border: 1px solid transparent;
}
.cat-item:hover {
    background: var(--btn-hover);
    border-color: var(--input-border);
}
.cat-item.active {
    background: var(--pill-bg);
    border-color: var(--input-border);
}
.cat-name {
    font-weight: 600;
}
.cat-count {
    padding: 2px 6px;
    border-radius: 999px;
    background: var(--btn);
    border: 1px solid var(--input-border);
    font-size: 12px;
    color: var(--fg);
}

.list {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0;
    overflow: auto;
    min-height: 0;
}

.viewer {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    min-height: 0;
    overflow: auto;
}

pre {
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    color: var(--pre-fg);
    background: var(--pre-bg);
    border: 1px solid var(--pre-border);
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    padding: 12px;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.grow {
    flex: 1;
}

.pill {
    padding: 3px 8px;
    border: 1px solid var(--input-border);
    border-radius: 999px;
    color: var(--fg);
    background: var(--pill-bg);
    font-size: 12px;
    text-decoration: none;
}

a {
    color: var(--acc);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

@media (max-width: 900px) {
    .grid { grid-template-columns: 1fr; }
}

.toolbar .spacer {
    flex: 1 1 auto;
}

label.inline {
    display: flex;
    align-items: center;
    gap: 6px;
}

select, input[type="checkbox"] {
    accent-color: var(--acc);
}

.meta {
    color: var(--muted);
    font-size: 12px;
}

.item {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.metaRow {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: space-between; /* meta left, actions right */
    width: 100%;
}

.actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Small action buttons with icons */
.actions .btn,
.actions .pill {
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--fg);            /* ensure high-contrast text/icon */
    border: 1px solid var(--input-border);
    background: var(--btn);
}

.actions .btn,
.actions .pill {
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

/* Generic hover for all action buttons */
.actions .btn:hover,
.actions .pill:hover {
    background: var(--btn-hover);
    border-color: var(--input-border);
    color: var(--fg);
    text-decoration: none;
}

/* Download pill — slightly deeper hover */
.actions .pill:hover {
    background: var(--pill-hover-bg);
}

/* Delete hover — red (override) */
.actions .danger:hover {
    background: #fee2e2;
    border-color: #ef4444;
    color: #b91c1c;
}

.actions .btn svg,
.actions .pill svg {
    width: 14px;
    height: 14px;
    display: inline-block;
}

/* ===== Tooltips ===== */
[data-tip]{
    position: relative;
}
[data-tip]::after{
    content: attr(data-tip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translateX(-50%) translateY(4px);
    background: var(--tt-bg);
    color: var(--tt-fg);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,0.22);
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease, transform 120ms ease;
    z-index: 20;
}
[data-tip]::before{
    content: "";
    position: absolute;
    left: 50%;
    bottom: calc(100% + 4px);
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--tt-bg);
    opacity: 0;
    transition: opacity 120ms ease, transform 120ms ease;
    z-index: 20;
}
[data-tip]:hover::after,
[data-tip]:hover::before{
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Delete hover — red */
.actions .danger:hover {
    background: #fee2e2;
    border-color: #ef4444;
    color: #b91c1c;
}

/* Make item action buttons/links compact while inheriting theme vars */
.item button,
.item .pill {
    padding: 3px 8px;
    font-size: 12px;
    border-radius: 999px;
}

/* New item highlight */
.item.new {
    background: var(--new-bg-mid);
    border-color: var(--new-br-mid);
    animation: newFlash 1.6s ease-out;
}

:root[data-theme="dark"] .item.new {
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15) inset;
}

@keyframes newFlash {
    0% {
        background: var(--new-bg-start);
        border-color: var(--new-br-start);
    }
    60% {
        background: var(--new-bg-mid);
        border-color: var(--new-br-mid);
    }
    100% {
        background: var(--new-bg-end);
        border-color: var(--new-br-end);
    }
}

/* --- Forward modal --- */
.promptRow{ display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.promptRow input[type="text"]{ width:380px; }
.modal{
    position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.3); z-index: 50;
}
.modal.show{ display:flex; }
.modal .card{
    background: var(--card); color: var(--fg); border:1px solid var(--border); border-radius:12px; padding:16px; width: min(560px, 92vw);
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.modal .actions{ display:flex; gap:8px; justify-content:flex-end; }