/* ============ THEME TOKENS ============ */
:root {
    /* base */
    --bg: #f6f7fb;
    --card: #ffffff;
    --text: #101315;
    --muted: #6b7280;
    --border: #e7e9ee;

    /* brand accents */
    --primary: #5561f6;
    /* refined indigo */
    --primary-weak: color-mix(in oklab, var(--primary) 16%, white);
    --danger: #ef4444;

    /* depth & effects */
    --shadow-1: 0 1px 2px rgba(16, 19, 21, .06), 0 6px 16px rgba(16, 19, 21, .06);
    --shadow-2: 0 10px 30px rgba(16, 19, 21, .12), 0 2px 6px rgba(16, 19, 21, .08);
    --radius: 14px;

    /* focus */
    --ring: 0 0 0 3px color-mix(in oklab, var(--primary) 24%, transparent);

    /*topbar*/
    --topbar-h: 58px;

    /* typography */
    --font-head: "Cormorant Garamond", serif;
    --font-sans: "Work Sans", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:root.dark {
    --bg: #0b0c0f;
    --card: #121419;
    --text: #e7eaf0;
    --muted: #9aa3b2;
    --border: #222630;
    --primary: #7b87ff;
    --primary-weak: color-mix(in oklab, var(--primary) 18%, #0b0c0f);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .25), 0 6px 16px rgba(0, 0, 0, .25);
    --shadow-2: 0 10px 30px rgba(0, 0, 0, .35), 0 2px 6px rgba(0, 0, 0, .25);
    --ring: 0 0 0 3px color-mix(in oklab, var(--primary) 34%, transparent);
}

/* ============ RESET / BASE ============ */
* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font: 15px/1.6 var(--font-sans);
    color: var(--text);
    background:
        radial-gradient(1200px 800px at 120% -10%, #e8ebff 0%, transparent 50%),
        radial-gradient(1000px 700px at -20% -20%, #ffe9f0 0%, transparent 48%),
        var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* background blobs */
.bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.blob {
    position: absolute;
    width: 42vmax;
    height: 42vmax;
    filter: blur(40px);
    opacity: .28;
    border-radius: 50%;
    animation: float 28s ease-in-out infinite;
    will-change: transform;
}

.blob-a {
    left: -10vmax;
    top: -6vmax;
    background: radial-gradient(circle at 30% 30%, #c9d0ff, #8ea2ff);
}

.blob-b {
    right: -8vmax;
    bottom: -10vmax;
    background: radial-gradient(circle at 60% 40%, #ffd1df, #ff9fb8);
    animation-duration: 34s;
}

@keyframes float {
    0% {
        transform: translate3d(0, 0, 0) scale(1);
    }

    50% {
        transform: translate3d(2vmax, -1vmax, 0) scale(1.06);
    }

    100% {
        transform: translate3d(0, 0, 0) scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .blob {
        animation: none;
    }
}

/* ============ TYPOGRAPHY ============ */
h1,
h2 {
    font-family: var(--font-head);
}

h1 {
    font-weight: 700;
    font-size: clamp(1.75rem, 2vw + 1rem, 2.25rem);
    line-height: 1.2;
}

h2 {
    font-weight: 700;
    font-size: 1.5rem;
    line-height: 1.3;
    margin: 0 0 12px;
}

.group-title {
    font-family: var(--font-head);
    font-weight: 800;
    font-size: 12px;
    line-height: 1;
    letter-spacing: .22em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0 6px;
}

legend {
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 13px;
    line-height: 1;
    letter-spacing: .3px;
    color: var(--muted);
    padding: 0 6px;
}

.meta,
code,
.mono,
.kv .k,
.kv .v {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.4;
    color: var(--muted);
}

/* ============ APP CHROME ============ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 18px;
    background: color-mix(in oklab, var(--bg) 72%, #ffffff 28%);
    backdrop-filter: saturate(1.2) blur(6px);
    border-bottom: 1px solid var(--border);
    flex-wrap: nowrap;
    /* keeps all items on the same row */
}

.topbar h1 {
    flex: 0 0 auto;
    margin: 0;
    font: 700 18px/1 var(--font-head);
    letter-spacing: .2px;
    white-space: nowrap;
}

.topbar-search {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    max-width: 600px;
}

.topbar-actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* smaller screens: let the search shrink gracefully but stay inline */
@media (max-width: 600px) {
    .topbar {
        gap: 8px;
        padding: 12px;
    }

    .topbar-search input {
        min-width: 120px;
    }
}

.topbar h1 {
    margin: 0;
    font: 700 18px/1 var(--font-head);
    letter-spacing: .2px;
}

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

.topbar-search {
    display: flex;
    align-items: center;
    max-width: 520px;
    width: 100%;
}

.topbar-search input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: color-mix(in oklab, var(--card) 92%, transparent);
    color: var(--text);
}

.topbar-search input:focus {
    border-color: color-mix(in oklab, var(--primary)60%, var(--border));
    box-shadow: var(--ring);
}

.menu {
    display: none !important;
}

/* Tabs with badges */
.tabs {
    position: sticky;
    top: var(--topbar-h);
    z-index: 2;
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(0deg, color-mix(in oklab, var(--bg) 85%, #fff 15%), var(--bg));
}

.tab {
    position: relative;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: color-mix(in oklab, var(--card) 86%, var(--primary-weak) 14%);
    cursor: pointer;
    color: var(--text);
    transition: transform .12s ease, box-shadow .2s ease;
}

.tab:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-1);
}

.tab.active {
    border-color: color-mix(in oklab, var(--primary) 60%, var(--border));
    background: color-mix(in oklab, var(--card) 70%, var(--primary-weak) 30%);
    box-shadow: var(--shadow-1);
}

.badge {
    display: inline-block;
    margin-left: 8px;
    padding: 0 8px;
    border-radius: 999px;
    font: 600 12px/20px var(--font-head);
    background: color-mix(in oklab, var(--primary) 16%, var(--card));
    border: 1px solid var(--border);
    color: var(--text);
}

.tabpanel {
    display: none;
    padding: 20px;
    max-width: 1100px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.tabpanel.active {
    display: block;
}

/* ============ CARDS & LAYOUT ============ */
.card {
    background: color-mix(in oklab, var(--card) 92%, var(--primary-weak) 8%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-1);
}

.grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(280px, 1fr));
    gap: 16px 20px;
}

.grid .full {
    grid-column: 1 / -1;
}

.grid .grow {
    flex: 1;
    min-width: 160px;
}

/* Grouped sections */
.group {
    border: 1px solid color-mix(in oklab, var(--border) 80%, var(--primary-weak) 20%);
    border-radius: 14px;
    padding: 14px;
    background: color-mix(in oklab, var(--card) 96%, transparent);
}

.group-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(280px, 1fr));
    gap: 14px 16px;
}

.group fieldset {
    border: 1px dashed color-mix(in oklab, var(--border) 70%, var(--primary-weak) 30%);
    padding: 12px;
    border-radius: 12px;
    transition: border-color .2s, background .2s, box-shadow .2s;
}

.group fieldset:hover {
    border-color: color-mix(in oklab, var(--border) 40%, var(--primary) 60%);
    box-shadow: var(--shadow-1);
}

/* labels & controls */
label {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    margin: 6px 12px 0 0;
}

/* inputs */
input[type="text"],
input[type="search"],
textarea,
select {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: color-mix(in oklab, var(--card) 92%, transparent);
    color: var(--text);
    transition: border-color .2s, box-shadow .2s, background .2s;
    outline: none;
}

input[type="text"]:focus,
input[type="search"]:focus,
textarea:focus,
select:focus {
    border-color: color-mix(in oklab, var(--primary) 60%, var(--border));
    box-shadow: var(--ring);
    background: color-mix(in oklab, var(--card) 88%, var(--primary-weak) 12%);
}

textarea {
    resize: vertical;
}

/* custom radios/checkboxes */
input[type="radio"],
input[type="checkbox"] {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 6px;
    border: 1.5px solid var(--border);
    display: inline-block;
    position: relative;
    transition: border-color .2s, background .2s, transform .12s;
    background: color-mix(in oklab, var(--card) 92%, transparent);
}

input[type="radio"] {
    border-radius: 999px;
}

input[type="radio"]:checked,
input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 25%, transparent);
}

input[type="radio"]:active,
input[type="checkbox"]:active {
    transform: scale(.96);
}

/* buttons */
button,
.file-btn {
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    transition: transform .12s, box-shadow .2s, background .2s, border-color .2s;
    font: inherit;
}

button:hover,
.file-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-1);
}

button:focus-visible,
.file-btn:focus-within {
    box-shadow: var(--ring);
}

button.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

button.primary:hover {
    box-shadow: var(--shadow-2);
}

button.ghost {
    background: color-mix(in oklab, var(--card) 70%, transparent);
}

button.danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

/* groups */
.actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

/* toolbar + list */
.toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.spacer {
    flex: 1;
}

/* chips */
.chips {
    display: inline-flex;
    gap: 8px;
}

.chip {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: color-mix(in oklab, var(--card) 86%, var(--primary-weak) 14%);
}

.chip.selected {
    border-color: color-mix(in oklab, var(--primary) 60%, var(--border));
    background: color-mix(in oklab, var(--card) 70%, var(--primary-weak) 30%);
    box-shadow: var(--shadow-1);
}

/* list with inline expand */
.list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.list li {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0;
    background: var(--card);
    margin-bottom: 10px;
    box-shadow: var(--shadow-1);
    transition: transform .12s, box-shadow .2s, border-color .2s, background .2s;
}

.list li:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-2);
    border-color: color-mix(in oklab, var(--primary) 55%, var(--border));
}

.row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 12px 14px;
    cursor: pointer;
}

.row .title {
    font-weight: 600;
}

.row .meta {
    color: var(--muted);
    font: 13px/1.4 var(--font-sans);
}

.row .chev {
    padding-left: 12px;
    color: var(--muted);
    font: 600 18px/1 var(--font-head);
}

.row-actions {
    display: flex;
    gap: 8px;
}

.row-actions .iconbtn {
    border-radius: 10px;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.row-expand {
    display: none;
    padding: 0 14px 12px;
}

.list li.expanded .row-expand {
    display: block;
}

.preview {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 8px 16px;
    align-items: start;
    padding-top: 8px;
}

.preview .kv {
    display: contents;
}

.k {
    color: var(--muted);
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 13px;
    letter-spacing: .2px;
}

.v {
    white-space: pre-wrap;
}

.thumb {
    max-width: 180px;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-top: 6px;
}

/* dialog (detail view) */
dialog {
    border: none;
    padding: 0;
    border-radius: 16px;
    width: min(760px, 92vw);
    background: color-mix(in oklab, var(--card) 90%, var(--primary-weak) 10%);
    color: var(--text);
    box-shadow: var(--shadow-2);
}

dialog::backdrop {
    background: rgba(0, 0, 0, .45);
    backdrop-filter: blur(2px);
}

#detailContent {
    padding: 18px;
    max-height: 72vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.dialog-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px;
    border-top: 1px solid var(--border);
}

.kv {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 8px 16px;
}

/* fixed selector (typo) */
.img-preview {
    display: block;
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-top: 10px;
}

/* Quick Add dialog */
.quickadd h3 {
    margin: 0 0 8px;
}

.quickadd .row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.selectlike select {
    width: 100%;
}

/* FAB */
.fab {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 5;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--primary);
    color: #fff;
    font-size: 24px;
    line-height: 0;
    box-shadow: var(--shadow-2);
}

.fab:hover {
    transform: translateY(-1px);
}

/* Make "other:" inputs span full width and stack vertically */
label.other-input {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    margin-top: 12px;
    align-items: center;
    margin: 0 10rem 0 10rem;
}

/* responsive */
@media (max-width: 900px) {
    .topbar {
        grid-template-columns: 1fr auto;
        grid-auto-rows: auto;
    }

    .topbar-search {
        grid-column: 1 / -1;
    }
}

@media (max-width: 760px) {

    .grid,
    .group-grid,
    .kv,
    .preview {
        grid-template-columns: 1fr;
    }

    .quickadd .row {
        grid-template-columns: 1fr;
    }
}

/* ===== Likes (heart) ===== */
.iconbtn.like {
    position: relative;
    font-size: 16px;
    line-height: 1;
}

.iconbtn.like[aria-pressed="true"] {
    background: color-mix(in oklab, var(--primary) 20%, var(--card));
    border-color: color-mix(in oklab, var(--primary) 55%, var(--border));
    box-shadow: var(--shadow-1);
}

.iconbtn.like .like-count {
    font: 600 11px/1 var(--font-sans);
    color: var(--muted);
    margin-left: 6px;
}

/* fit 4th icon nicely */
.row-actions .iconbtn {
    width: 34px;
    height: 34px;
}

.row-actions {
    gap: 6px;
}

/* ---------- Public page thumbnail sizing (scoped) ---------- */
#publicLogList .preview {
    grid-template-columns: 140px 1fr;
    /* narrower, consistent left column */
    align-items: center;
    /* centers image nicely */
}

#publicLogList .thumb {
    display: block;
    width: 120px;
    /* fixed width so all cards align */
    height: 160px;
    /* fixed height for uniform rows */
    object-fit: contain;
    /* keep bottle proportions */
    background: var(--card);
    /* optional: neutral backdrop */
    border-radius: 12px;
    border: 1px solid var(--border);
}

/* Tweak for small screens */
@media (max-width: 760px) {
    #publicLogList .preview {
        grid-template-columns: 100px 1fr;
    }

    #publicLogList .thumb {
        width: 90px;
        height: 120px;
    }
}

/* ===== AI Chat UI ===== */
.chat {
    padding: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in oklab, var(--card) 92%, var(--primary-weak) 8%);
    border-radius: 16px 16px 0 0;
}

.chat-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

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

#geminiKey {
    width: 280px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: color-mix(in oklab, var(--card) 92%, transparent);
    font: 13px/1.4 var(--font-mono);
}

.chat-messages {
    max-height: min(60vh, 540px);
    overflow: auto;
    padding: 14px 16px;
    background: color-mix(in oklab, var(--card) 90%, var(--primary-weak) 10%);
}

.msg {
    display: inline-block;
    max-width: 80%;
    padding: 10px 12px;
    margin: 6px 0;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--card);
    white-space: pre-wrap;
}

.msg.user {
    background: color-mix(in oklab, var(--primary) 10%, var(--card));
    border-color: color-mix(in oklab, var(--primary) 40%, var(--border));
}

.msg.bot {
    background: color-mix(in oklab, var(--card) 92%, var(--primary-weak) 8%);
}

.bubble {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.bubble .who {
    font: 600 11px/1 var(--font-sans);
    color: var(--muted);
    width: 56px;
    flex: 0 0 56px;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.bubble .msg {
    flex: 1;
}

.chat-input {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 12px 16px 16px;
    border-top: 1px solid var(--border);
    border-radius: 0 0 16px 16px;
    background: color-mix(in oklab, var(--card) 94%, transparent);
}

#chatInput {
    resize: vertical;
}

/* Make the FAB a chat trigger visually */
.fab {
    font-size: 22px;
}