/* yaadsay — design system */

:root {
    --brand: #16a34a;
    --brand-hover: #15803d;
    --brand-soft: #dcfce7;
    --brand-fg: #ffffff;

    --bg: #ffffff;
    --bg-alt: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --fg: #0f172a;
    --fg-2: #334155;
    --muted: #64748b;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-soft: #fee2e2;
    --danger-fg: #7f1d1d;

    --warn: #d97706;
    --warn-soft: #fef3c7;

    --info: #2563eb;
    --info-soft: #dbeafe;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-full: 999px;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;

    --fs-xs: 12px;
    --fs-sm: 13px;
    --fs-base: 15px;
    --fs-lg: 17px;
    --fs-xl: 20px;
    --fs-2xl: 24px;
    --fs-3xl: 30px;

    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
    --shadow: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.10), 0 4px 6px -4px rgba(15, 23, 42, 0.05);

    --nav-h: 60px;
    --content-max: 960px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1120;
        --bg-alt: #0f172a;
        --surface: #111827;
        --surface-2: #1e293b;
        --fg: #f1f5f9;
        --fg-2: #cbd5e1;
        --muted: #94a3b8;
        --border: #1e293b;
        --border-strong: #334155;

        --brand: #22c55e;
        --brand-hover: #16a34a;
        --brand-soft: #052e16;
        --brand-fg: #052e16;

        --danger-soft: #450a0a;
        --danger-fg: #fecaca;
        --warn-soft: #451a03;
        --info-soft: #172554;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font);
    font-size: var(--fs-base);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 var(--space-3); line-height: 1.25; font-weight: 600; color: var(--fg); }
h1 { font-size: var(--fs-2xl); letter-spacing: -0.01em; }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-base); }

p { margin: 0 0 var(--space-3); color: var(--fg-2); }

img { max-width: 100%; display: block; }

hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-5) 0; }

/* --- Layout ------------------------------------------------------------ */

.app-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}

.app-header-inner {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 0 var(--space-5);
    height: var(--nav-h);
    display: flex;
    align-items: center;
    gap: var(--space-5);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: var(--fs-lg);
    color: var(--fg);
    letter-spacing: -0.02em;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 26px; height: 26px;
    border-radius: 7px;
    background: var(--brand);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 800;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--fg-2);
    font-size: var(--fs-base);
    font-weight: 500;
}
.nav-link:hover {
    background: var(--surface-2);
    color: var(--fg);
    text-decoration: none;
}
.nav-link.is-active { color: var(--fg); background: var(--surface-2); }

.nav-icon { width: 18px; height: 18px; flex: 0 0 auto; }

.nav-avatar {
    width: 32px; height: 32px;
    border-radius: var(--radius-full);
    background: var(--brand-soft);
    color: var(--brand);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--fs-sm);
    border: 0;
    cursor: pointer;
}

.app-main {
    flex: 1 0 auto;
    width: 100%;
}

.app-main-inner {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--space-6) var(--space-5) var(--space-8);
}

/* --- Footer ------------------------------------------------------------ */

.app-footer {
    border-top: 1px solid var(--border);
    padding: var(--space-5);
    color: var(--muted);
    font-size: var(--fs-sm);
    text-align: center;
}

/* --- Buttons ----------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    font-size: var(--fs-base);
    font-weight: 500;
    font-family: inherit;
    line-height: 1;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--brand);
    color: #fff;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
    text-decoration: none;
    white-space: nowrap;
    min-height: 40px;
}
.btn:hover { background: var(--brand-hover); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-sm { padding: 6px 12px; font-size: var(--fs-sm); min-height: 32px; }
.btn-lg { padding: 12px 20px; font-size: var(--fs-lg); min-height: 46px; }

.btn-secondary {
    background: var(--surface);
    color: var(--fg);
    border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); }

.btn-ghost {
    background: transparent;
    color: var(--fg-2);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--fg); }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-danger-ghost {
    background: transparent;
    color: var(--danger);
    border-color: transparent;
}
.btn-danger-ghost:hover { background: var(--danger-soft); }

.btn-icon {
    padding: 8px;
    min-height: 0;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--fg-2);
}
.btn-icon:hover { background: var(--surface-2); color: var(--fg); }

/* --- Forms ------------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: var(--space-4); }

.field { display: flex; flex-direction: column; gap: 6px; }

.form-tab-panel {
    margin-top: 8px;
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }

label {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--fg);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: var(--fs-base);
    font-family: inherit;
    color: var(--fg);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
    min-height: 40px;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}

textarea { min-height: 96px; resize: vertical; }

.hint { font-size: var(--fs-xs); color: var(--muted); }

.field-error { font-size: var(--fs-xs); color: var(--danger); }

/* --- Cards ------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: var(--fs-base);
}

.card-body { padding: var(--space-5); }
.card-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border);
    background: var(--bg-alt);
}

/* --- Alerts ------------------------------------------------------------ */

.alert {
    padding: 12px 14px;
    border-radius: var(--radius);
    font-size: var(--fs-sm);
    border: 1px solid transparent;
}

.alert-error { background: var(--danger-soft); color: var(--danger-fg); border-color: var(--danger); }
.alert-success { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.alert-info { background: var(--info-soft); color: var(--info); border-color: var(--info); }

/* --- Badges / pills ---------------------------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    font-size: var(--fs-xs);
    font-weight: 500;
    border-radius: var(--radius-full);
    background: var(--surface-2);
    color: var(--fg-2);
}
.badge-brand { background: var(--brand-soft); color: var(--brand); }
.badge-danger { background: var(--danger-soft); color: var(--danger-fg); }

/* --- Page header ------------------------------------------------------- */

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
    flex-wrap: wrap;
}

.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: var(--fs-sm); margin: 4px 0 0; }

.page-head-actions { display: flex; gap: var(--space-2); align-items: center; }

/* --- Empty state ------------------------------------------------------- */

.empty-state {
    text-align: center;
    padding: var(--space-8) var(--space-5);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--bg-alt);
}

.empty-state-icon {
    width: 48px; height: 48px;
    margin: 0 auto var(--space-4);
    color: var(--muted);
}

.empty-state h2 { margin: 0 0 var(--space-2); font-size: var(--fs-lg); }
.empty-state p { margin: 0 0 var(--space-4); color: var(--muted); }

/* --- Auth pages -------------------------------------------------------- */

.auth-wrap {
    min-height: 100dvh;
    display: grid;
    grid-template-columns: 1fr;
    background: var(--bg);
}

@media (min-width: 900px) {
    .auth-wrap { grid-template-columns: 1fr 1fr; }
}

.auth-side {
    display: none;
    background: linear-gradient(160deg, var(--brand) 0%, var(--brand-hover) 100%);
    color: #fff;
    padding: var(--space-8);
    flex-direction: column;
    justify-content: space-between;
}

@media (min-width: 900px) {
    .auth-side { display: flex; }
}

.auth-side h2 { color: #fff; font-size: var(--fs-3xl); margin: 0 0 var(--space-4); letter-spacing: -0.02em; }
.auth-side p { color: rgba(255,255,255,0.92); font-size: var(--fs-lg); }
.auth-side .brand { color: #fff; }
.auth-side .brand-mark { background: rgba(255,255,255,0.2); }
.auth-side-footer { font-size: var(--fs-sm); color: rgba(255,255,255,0.7); }

.auth-main {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6) var(--space-5);
}

.auth-card {
    width: 100%;
    max-width: 400px;
}

.auth-card h1 { font-size: var(--fs-2xl); margin: 0 0 var(--space-2); }
.auth-card .sub { color: var(--muted); margin: 0 0 var(--space-6); }

.auth-alt {
    margin-top: var(--space-5);
    text-align: center;
    font-size: var(--fs-sm);
    color: var(--muted);
}


/* --- List -------------------------------------------------------------- */

.list {
    list-style: none;
    padding: 0;
    margin: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--surface);
}

.list-item {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: var(--space-3);
    align-items: center;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    transition: background 0.1s ease;
}

.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); }

.list-icon {
    width: 40px; height: 40px;
    border-radius: var(--radius);
    background: var(--brand-soft);
    color: var(--brand);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.list-icon svg { width: 20px; height: 20px; }

.list-body { min-width: 0; }

.list-title {
    font-weight: 500;
    color: var(--fg);
    font-size: var(--fs-base);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.list-title a { color: inherit; }
.list-title a:hover { color: var(--brand); text-decoration: none; }

.list-meta {
    font-size: var(--fs-sm);
    color: var(--muted);
    margin-top: 2px;
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
}
.list-meta .dot { opacity: 0.5; }

.list-amount {
    font-family: var(--font-mono);
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--fg);
    text-align: right;
}

/* --- Item detail ------------------------------------------------------- */

.detail-header {
    padding-bottom: var(--space-5);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-5);
}
.detail-header h1 { margin: 0 0 var(--space-3); font-size: var(--fs-3xl); letter-spacing: -0.02em; }
.detail-meta { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; color: var(--muted); font-size: var(--fs-sm); }

.detail-amount {
    font-family: var(--font-mono);
    font-size: var(--fs-2xl);
    font-weight: 700;
    color: var(--fg);
    margin: var(--space-4) 0;
}

.detail-description {
    margin: var(--space-5) 0;
    line-height: 1.7;
    color: var(--fg-2);
    white-space: pre-wrap;
}

.detail-section {
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: 1px solid var(--border);
}
.detail-section h2 {
    font-size: var(--fs-base);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin: 0 0 var(--space-4);
    font-weight: 600;
}

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }

.detail-actions {
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: 1px solid var(--border);
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

/* --- Filters ----------------------------------------------------------- */

.filters {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}
.filters input[type="search"] { flex: 1 1 200px; min-width: 0; }
.filters select { flex: 0 0 auto; }
.filters .btn { min-height: 40px; }

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--space-5);
    font-size: var(--fs-sm);
}

/* --- Files ------------------------------------------------------------- */

.file-list { list-style: none; padding: 0; margin: 0; }
.file-item {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: var(--space-3);
    align-items: center;
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border);
}
.file-item:last-child { border-bottom: 0; }
.file-icon { width: 32px; height: 32px; color: var(--brand); }
.file-name { font-size: var(--fs-base); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: var(--fs-xs); color: var(--muted); }
.file-actions { display: flex; gap: 6px; }

/* --- Uploader ---------------------------------------------------------- */

.uploader { margin: var(--space-4) 0; }

.uploader-dropzone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: var(--space-6) var(--space-4);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    background: var(--bg-alt);
}
.uploader-dropzone:hover, .uploader-dropzone.is-dragover {
    border-color: var(--brand);
    background: var(--brand-soft);
}
.uploader-dropzone-icon {
    font-size: 28px;
    color: var(--muted);
    line-height: 1;
    margin-bottom: 6px;
}
.uploader-dropzone-text { font-size: var(--fs-base); color: var(--fg); }
.uploader-link { color: var(--brand); text-decoration: underline; cursor: pointer; }
.uploader-dropzone-hint { font-size: var(--fs-xs); color: var(--muted); margin-top: var(--space-2); }

.uploader-list { margin-top: var(--space-3); }

.uploader-entry {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: var(--space-3);
    align-items: center;
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border);
}
.uploader-entry:last-child { border-bottom: 0; }
.uploader-entry-icon { font-size: 20px; text-align: center; }
.uploader-entry-body { min-width: 0; }
.uploader-entry-name { font-size: var(--fs-sm); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploader-entry-meta { font-size: var(--fs-xs); color: var(--muted); margin-top: 2px; }
.uploader-entry.is-uploaded .uploader-entry-meta { color: var(--brand); }
.uploader-entry.is-uploaded .uploader-entry-meta::before { content: '✓ '; font-weight: bold; }
.uploader-entry.is-failed .uploader-entry-meta { color: var(--danger); }

.uploader-progress { height: 4px; background: var(--surface-2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.uploader-progress-bar { height: 100%; width: 0; background: var(--brand); transition: width 0.15s; }
.uploader-entry-error { font-size: var(--fs-xs); color: var(--danger); margin-top: 4px; }
.uploader-entry-actions { display: flex; gap: 6px; align-items: center; }
.uploader-action {
    font-size: var(--fs-xs);
    padding: 4px 10px;
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-family: inherit;
    color: var(--fg-2);
}
.uploader-action:hover { background: var(--brand-soft); color: var(--brand); }
.uploader-remove { font-size: 18px; line-height: 1; padding: 2px 8px; background: transparent; color: var(--muted); }
.uploader-remove:hover { background: var(--danger-soft); color: var(--danger); }
.uploader-status { font-size: var(--fs-sm); color: var(--muted); margin-top: var(--space-2); min-height: 18px; }
.uploader-status.is-ok { color: var(--brand); }
.uploader-status.is-error { color: var(--danger); }
.uploader-ready { color: var(--brand); font-weight: 600; }

/* --- Share ------------------------------------------------------------- */

.share-link-box {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    margin-top: var(--space-2);
}
.share-link-box input {
    flex: 1;
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    background: var(--bg-alt);
}

/* --- Reminders --------------------------------------------------------- */

.reminders-list { list-style: none; padding: 0; margin: 0 0 var(--space-4); }
.reminder-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border);
    font-size: var(--fs-sm);
}
.reminder-item:last-child { border-bottom: 0; }

/* --- Settings ---------------------------------------------------------- */

.settings-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-5);
    overflow: hidden;
}
.settings-section-head {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
}
.settings-section-head h2 { margin: 0 0 2px; font-size: var(--fs-lg); }
.settings-section-head p { margin: 0; font-size: var(--fs-sm); color: var(--muted); }
.settings-section-body { padding: var(--space-5); }

/* --- Misc -------------------------------------------------------------- */

.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mb-0 { margin-bottom: 0; }

.update-banner {
    position: fixed;
    bottom: var(--space-4);
    left: 50%;
    transform: translateX(-50%);
    background: var(--brand);
    color: #fff;
    padding: 10px 16px;
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-lg);
    font-size: var(--fs-sm);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: var(--space-3);
}
.update-banner button {
    background: rgba(255,255,255,0.2);
    color: #fff;
    border: 0;
    padding: 6px 12px;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--fs-xs);
    font-weight: 600;
}
.update-banner button:hover { background: rgba(255,255,255,0.3); }

@media (max-width: 480px) {
    .app-header-inner { padding: 0 var(--space-4); gap: var(--space-3); }
    .app-main-inner { padding: var(--space-5) var(--space-4) var(--space-7); }
    .nav-link { padding: 8px 10px; font-size: var(--fs-sm); }
    .nav-link-label { display: none; }
    .page-head h1 { font-size: var(--fs-xl); }
    .detail-header h1 { font-size: var(--fs-2xl); }
    .stat-value { font-size: var(--fs-2xl); }
}

/* --- Bulk bar ---------------------------------------------------------- */

.bulk-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--brand-soft);
    border: 1px solid var(--brand);
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
    position: sticky;
    top: calc(var(--nav-h) + 8px);
    z-index: 20;
}

.bulk-bar select {
    padding: 6px 10px;
    font-size: var(--fs-sm);
    min-height: 32px;
    width: auto;
}

/* --- Thumbnail in list ------------------------------------------------- */

.list-thumb {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    object-fit: cover;
    background-color: var(--surface-2);
    flex: 0 0 auto;
    border: 1px solid var(--border);
}

.list-item .bulk-check { display: flex; align-items: center; }
.list-item:has(.bulk-check) {
    grid-template-columns: 20px 40px 1fr auto;
}

@media (max-width: 640px) {
    .list-item:has(.bulk-check) {
        grid-template-columns: 20px 40px 1fr;
    }
    .list-amount { grid-column: 3 / 4; font-size: var(--fs-sm); }
}


/* --- Toast ------------------------------------------------------------- */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 12px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: var(--fs-sm);
    font-weight: 500;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    max-width: 90vw;
    pointer-events: none;
}

.toast-in {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast-success { background: var(--brand);   color: #fff; }
.toast-error   { background: var(--danger);  color: #fff; }
.toast-info    { background: var(--fg);      color: var(--bg); }

/* --- Quick Add modal --------------------------------------------------- */

.qa-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
}

.qa-modal.is-open { display: block; }

.qa-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
}

.qa-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(640px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}

.qa-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
}

.qa-head h2 { margin: 0; font-size: var(--fs-lg); }

.qa-close {
    font-size: 22px;
    line-height: 1;
    width: 32px;
    height: 32px;
    padding: 0;
}

.qa-body { padding: var(--space-5); }

.qa-sub {
    margin: 0 0 var(--space-4);
    color: var(--muted);
    font-size: var(--fs-sm);
}

.qa-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-3);
}

.qa-tile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: var(--space-4);
    text-align: left;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.12s, background 0.12s;
}

.qa-tile:hover {
    border-color: var(--brand);
    background: var(--brand-soft);
}

.qa-tile-label {
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--fg);
}

.qa-tile-hint {
    font-size: var(--fs-xs);
    color: var(--muted);
    line-height: 1.35;
}

.qa-stage-form { display: none; }
.qa-stage-form.is-active { display: block; }

.qa-back {
    background: none;
    border: 0;
    padding: 0;
    font-family: inherit;
    font-size: var(--fs-sm);
    color: var(--brand);
    cursor: pointer;
    margin-bottom: var(--space-4);
}

.qa-back:hover { text-decoration: underline; }

.qa-form .field { margin-bottom: var(--space-4); }

.qa-error {
    background: var(--danger-soft);
    color: var(--danger-fg);
    border-left: 4px solid var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: var(--fs-sm);
    margin-bottom: var(--space-4);
}

.qa-actions {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    margin-top: var(--space-5);
}

.qa-field-record,
.qa-field-task,
.qa-field-event,
.qa-field-reminder { display: none; }

@media (max-width: 640px) {
    .qa-panel {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        width: 100%;
        max-height: 90vh;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
}

/* --- Type chips -------------------------------------------------------- */

.type-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}

.type-chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    font-size: var(--fs-sm);
    border-radius: var(--radius-full);
    background: var(--surface-2);
    color: var(--fg-2);
    text-decoration: none;
    border: 1px solid transparent;
    transition: background 0.12s, color 0.12s;
}

.type-chip:hover {
    background: var(--brand-soft);
    color: var(--brand);
    text-decoration: none;
}

.type-chip.is-active {
    background: var(--brand);
    color: #fff;
}

.uploader-dropzone.is-disabled {
    border-color: var(--danger);
    background: var(--danger-soft);
    cursor: not-allowed;
}
.uploader-dropzone.is-disabled .uploader-dropzone-icon {
    color: var(--danger);
}

/* --- Rich text Editor --------------------------------------------------------- */

.rich-text p { margin: 0 0 var(--space-3); }
.rich-text p:last-child { margin-bottom: 0; }
.rich-text strong, .rich-text b { font-weight: 600; }
.rich-text em, .rich-text i { font-style: italic; }
.rich-text u { text-decoration: underline; }
.rich-text h2 { font-size: var(--fs-xl); margin: var(--space-4) 0 var(--space-3); }
.rich-text h3 { font-size: var(--fs-lg); margin: var(--space-3) 0 var(--space-2); }
.rich-text ul, .rich-text ol { margin: var(--space-3) 0; padding-left: var(--space-5); }
.rich-text li { margin: 4px 0; }
.rich-text blockquote {
    border-left: 3px solid var(--border-strong);
    padding-left: var(--space-4);
    margin: var(--space-3) 0;
    color: var(--muted);
}
.rich-text code {
    font-family: var(--font-mono);
    font-size: 0.92em;
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: 4px;
}
.rich-text pre {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    background: var(--surface-2);
    padding: var(--space-3);
    border-radius: var(--radius);
    overflow-x: auto;
    margin: var(--space-3) 0;
}
.rich-text a { color: var(--brand); text-decoration: underline; }

/* --- Rich text editor (in the form) ------------------------------------ */

.rte-wrap {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}

.rte-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.rte-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--fs-sm);
    color: var(--fg-2);
}

.rte-btn:hover { background: var(--surface); color: var(--fg); }
.rte-btn.is-active { background: var(--brand-soft); color: var(--brand); }

.rte-btn-sep {
    width: 1px;
    height: 20px;
    background: var(--border-strong);
    margin: 6px 4px;
}

.rte-editor {
    min-height: 120px;
    padding: var(--space-4);
    font-size: var(--fs-base);
    line-height: 1.6;
    outline: none;
    overflow-y: auto;
    max-height: 500px;
}

.rte-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--muted);
    pointer-events: none;
}

.rte-editor p { margin: 0 0 var(--space-3); }

/* --- Toolbar toggle buttons ------------------------------------------- */

.form-toolbar {
    display: flex;
    gap: 6px;
    margin-bottom: var(--space-3);
}

.form-toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: var(--fs-sm);
    background: var(--surface-2);
    color: var(--fg-2);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-family: inherit;
}

.form-toolbar-btn:hover { background: var(--brand-soft); color: var(--brand); }
.form-toolbar-btn.is-active { background: var(--brand); color: #fff; }


/* --- Audio recorder ---------------------------------------------------- */

.recorder {
    margin: 8px 0;
}

.recorder-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.recorder-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: var(--fs-sm);
    background: var(--surface-2);
    color: var(--fg);
    border: 0;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-family: inherit;
}

.recorder-btn:hover { background: var(--brand-soft); color: var(--brand); }

.recorder-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    flex: 0 0 auto;
}

.recorder-active {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    justify-content: space-between;
}

.recorder-time {
    font-family: var(--font-mono);
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--danger);
    min-width: 48px;
}

.recorder-status {
    font-size: var(--fs-sm);
    color: var(--muted);
    flex: 1;
}

.recorder-stop {
    background: var(--danger);
    color: #fff;
}

.recorder-stop:hover { background: var(--danger-hover); color: #fff; }

.recorder-error {
    width: 100%;
    font-size: var(--fs-sm);
    color: var(--danger);
    margin-top: 8px;
}

/* --- Audio in the detail file list ------------------------------------- */

.file-item audio {
    width: 100%;
    max-width: 320px;
    height: 34px;
    margin-top: 4px;
}

/* --- Preview modal ----------------------------------------------------- */

.pm-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 3000;
}

.pm-modal.is-open { display: block; }

.pm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(2px);
}

.pm-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(900px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pm-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}

.pm-title {
    margin: 0;
    font-size: var(--fs-base);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.pm-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

.pm-close { font-size: 22px; }

.pm-body {
    flex: 1 1 auto;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-alt);
    padding: var(--space-4);
    min-height: 200px;
}

/* --- Confirm dialog (compact, centered) -------------------------------- */

.pm-modal.cd-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 4000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.pm-modal.cd-modal.is-open {
    display: flex;
}

.pm-modal.cd-modal .pm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
}

.cd-panel {
    position: relative;
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1;
}

.cd-panel .pm-head {
    padding: 12px 16px;
}

.cd-panel .pm-title {
    font-size: var(--fs-base);
}

.cd-panel .pm-body {
    display: block;
    background: var(--surface);
    padding: 16px;
    min-height: 0;
    overflow: visible;
}

.cd-panel .cd-message {
    margin: 0 0 16px;
    font-size: var(--fs-sm);
    color: var(--muted);
}

.cd-panel .cd-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

@media (max-width: 640px) {
    .pm-panel {
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    .pm-frame { height: calc(100vh - 140px); }
    .pm-image { max-height: calc(100vh - 160px); }
}

/* --- Collection picker ------------------------------------------------- */

.collection-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.collection-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: var(--fs-sm);
    background: var(--surface-2);
    color: var(--fg-2);
    border-radius: var(--radius-full);
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.12s, color 0.12s;
    margin: 0;
    font-weight: 400;
}

.collection-chip:hover { background: var(--brand-soft); color: var(--brand); }
.collection-chip input[type="checkbox"] {
    width: auto;
    min-height: 0;
    margin: 0;
}
.collection-chip:has(input:checked) {
    background: var(--brand);
    color: #fff;
}

.collection-new {
    color: var(--brand);
    border: 1px dashed var(--brand);
    text-decoration: none;
}
.collection-new:hover { text-decoration: none; background: var(--brand-soft); }


/* ==========================================================================
   App shell — sidebar + main column
   ========================================================================== */

body {
    background: var(--bg-alt);
}

.app-shell {
    display: grid;
    grid-template-columns: 248px 1fr;
    min-height: 100dvh;
}

/* --- Sidebar ----------------------------------------------------------- */

.sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100dvh;
    overflow-y: auto;
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding: 20px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 30;
}

.sidebar-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 20px;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--fg);
    text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    font-size: 18px;
}

.sidebar-quick-add {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 14px;
    background: var(--brand);
    color: #fff;
    border: 0;
    border-radius: var(--radius);
    font-size: var(--fs-base);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    margin-bottom: 20px;
}
.sidebar-quick-add:hover { background: var(--brand-hover); }

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--fg-2);
    font-size: var(--fs-base);
    font-weight: 500;
    text-decoration: none;
    transition: background 0.12s, color 0.12s;
}
.sidebar-link:hover {
    background: var(--surface-2);
    color: var(--fg);
    text-decoration: none;
}
.sidebar-link.is-active {
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 600;
}
.sidebar-icon { flex: 0 0 auto; opacity: 0.9; }

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 8px;
}

.sidebar-user {
    position: relative;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.sidebar-user-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px;
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}
.sidebar-user-btn:hover { background: var(--surface-2); }

.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    flex: 0 0 auto;
}

.sidebar-user-meta {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}
.sidebar-user-name {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--fg);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-user-email {
    font-size: var(--fs-xs);
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-user-caret { color: var(--muted); flex: 0 0 auto; }

.sidebar-user-menu {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 4px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: 40;
}

.sidebar-menu-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: var(--fg);
    font-size: var(--fs-sm);
    text-decoration: none;
}
.sidebar-menu-link:hover { background: var(--surface-2); text-decoration: none; }
.sidebar-menu-link-danger { color: var(--danger); }
.sidebar-menu-link-danger:hover { background: var(--danger-soft); }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 25;
}
.sidebar-backdrop.is-open { display: block; }

/* --- Main column ------------------------------------------------------- */

.app-main-col {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 20;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: color-mix(in srgb, var(--bg) 90%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}

.app-topbar-menu {
    background: transparent;
    border: 0;
    padding: 8px;
    border-radius: 8px;
    color: var(--fg);
    cursor: pointer;
}
.app-topbar-menu:hover { background: var(--surface-2); }

.app-topbar-title {
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--fg);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
}

.app-main-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 32px 40px 80px;
    width: 100%;
}

/* --- Responsive -------------------------------------------------------- */

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        max-width: 85vw;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.is-open {
        transform: translateX(0);
    }

    .app-topbar {
        display: flex;
    }

    .app-main-inner {
        padding: 20px 16px 60px;
    }
}

@media (max-width: 480px) {
    .sidebar { width: 82vw; }
    .app-main-inner { padding: 16px 12px 60px; }
}

/* ==========================================================================
   Library
   ========================================================================== */

.library-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
    flex-wrap: wrap;
}
.library-head h1 {
    margin: 0;
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.025em;
}
.library-sub {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: var(--fs-base);
}
.library-head-actions { display: flex; gap: 8px; }

/* Search bar */
.library-searchbar {
    display: flex;
    gap: 8px;
    margin-bottom: var(--space-4);
}
.library-search-input {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    height: 44px;
}
.library-search-input svg { color: var(--muted); flex: 0 0 auto; }
.library-search-input input {
    flex: 1;
    border: 0;
    background: transparent;
    padding: 0;
    height: 100%;
    font-size: var(--fs-base);
    min-height: 0;
}
.library-search-input input:focus { outline: none; }

/* Type chips */
.type-chips-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: var(--space-3);
}
.type-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--surface);
    color: var(--fg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-size: var(--fs-sm);
    font-weight: 500;
    text-decoration: none;
}
.type-chip:hover { background: var(--surface-2); color: var(--fg); text-decoration: none; }
.type-chip.is-active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

/* Filter row */
.library-filter-row {
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
}
.library-filter-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.library-filter-form select,
.library-filter-form input {
    padding: 8px 12px;
    font-size: var(--fs-sm);
    min-height: 36px;
    width: auto;
}
.filter-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--fs-sm);
    font-weight: 400;
    margin: 0;
    cursor: pointer;
}
.filter-check input { width: auto; min-height: 0; }

/* Toolbar (count + view toggle + sort) */
.library-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
}
.library-count { font-size: var(--fs-sm); color: var(--fg-2); }
.library-count strong { color: var(--fg); }
.library-toolbar-right { display: flex; gap: 8px; align-items: center; }

.view-toggle {
    display: inline-flex;
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 2px;
}
.view-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
}
.view-toggle-btn:hover { color: var(--fg); }
.view-toggle-btn.is-active { background: var(--surface); color: var(--fg); box-shadow: var(--shadow-sm); }

.sort-dropdown { position: relative; }
.sort-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    z-index: 40;
    overflow: hidden;
}
.sort-menu-link {
    display: block;
    padding: 10px 14px;
    color: var(--fg);
    font-size: var(--fs-sm);
    text-decoration: none;
}
.sort-menu-link:hover { background: var(--surface-2); text-decoration: none; }
.sort-menu-link.is-active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* Table */
.library-table {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.library-table-head,
.library-row {
    display: grid;
    grid-template-columns: 32px 1fr 130px 200px 130px 80px;
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
}
.library-table-head {
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--muted);
    text-transform: uppercase;
}
.library-row {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}
.library-row:last-child { border-bottom: 0; }
.library-row:hover { background: var(--bg-alt); }

.lt-col { min-width: 0; }
.lt-check { display: flex; align-items: center; }
.lt-check input { width: auto; min-height: 0; margin: 0; }
.lt-date { font-size: var(--fs-sm); color: var(--fg-2); }
.lt-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.lt-amount { font-family: var(--font-mono); font-size: var(--fs-sm); font-weight: 600; text-align: right; }
.lt-actions { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }

.library-row-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.library-row-icon,
.library-row-thumb {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    background-size: cover;
    background-position: center;
    border: 1px solid var(--border);
}
.library-row-body { min-width: 0; flex: 1; }
.library-row-title {
    font-size: var(--fs-base);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.library-row-title a { color: var(--fg); text-decoration: none; }
.library-row-title a:hover { color: var(--brand); }
.library-row-sub {
    font-size: var(--fs-sm);
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
}

.fav-btn.is-active { color: #eab308; }
.fav-btn:hover { background: var(--surface-2); }

.row-menu-wrap { position: relative; }
.row-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    z-index: 40;
    overflow: hidden;
}
.row-menu a,
.row-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    background: transparent;
    border: 0;
    color: var(--fg);
    font-size: var(--fs-sm);
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
}
.row-menu a:hover,
.row-menu button:hover { background: var(--surface-2); text-decoration: none; }
.row-menu-danger { color: var(--danger); }
.row-menu-danger:hover { background: var(--danger-soft); }

/* Grid view */
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}
.library-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--fg);
    transition: border-color 0.12s, box-shadow 0.12s;
}
.library-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
    text-decoration: none;
}
.library-card-top { display: flex; justify-content: space-between; align-items: flex-start; }
.library-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.library-card-fav { color: #eab308; font-size: 18px; line-height: 1; }
.library-card-title {
    font-size: var(--fs-base);
    font-weight: 600;
    line-height: 1.35;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.library-card-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.library-card-amount {
    font-family: var(--font-mono);
    font-size: var(--fs-base);
    font-weight: 700;
    color: var(--fg);
    margin-top: auto;
}

/* Responsive */
@media (max-width: 1100px) {
    .library-table-head,
    .library-row {
        grid-template-columns: 32px 1fr 110px 130px 60px;
    }
    .lt-tags { display: none; }
}
@media (max-width: 780px) {
    .library-table-head,
    .library-row {
        grid-template-columns: 32px 1fr 60px;
        padding: 12px;
    }
    .lt-date, .lt-amount { display: none; }
    .library-head h1 { font-size: 24px; }
    .library-searchbar { flex-direction: column; }
    .library-searchbar .btn { width: 100%; }
    .library-toolbar { flex-wrap: wrap; gap: 8px; }
}

/* --- Topbar ------------------------------------------------------------ */

.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    padding: 8px 20px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    height: 60px;
    position: sticky;
    top: 0;
    z-index: 25;
}
.topbar-left {
    display: flex;
    align-items: center;
    justify-self: start;
}
@media (max-width: 900px) {
    .topbar-left { display: flex; }
}
@media (min-width: 901px) {
    .topbar-left { visibility: hidden; }
}

.topbar-menu {
    background: transparent;
    border: 0;
    padding: 8px;
    border-radius: 8px;
    color: var(--fg);
    cursor: pointer;
}
.topbar-menu:hover { background: var(--surface-2); }

.topbar-search {
    flex: 1;
    max-width: 560px;
    justify-self: center;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    height: 38px;
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    color: var(--muted);
    font-family: inherit;
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.topbar-search:hover { background: var(--surface); border-color: var(--border-strong); }
.topbar-search-label { flex: 1; text-align: left; }
.topbar-search-kbd {
    font-size: 11px;
    padding: 2px 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--muted);
    font-family: var(--font-mono);
}

.topbar-right {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-self: end;
}

.topbar-icon-btn {
    position: relative;
    width: 38px;
    height: 38px;
    background: transparent;
    border: 0;
    border-radius: 50%;
    color: var(--fg-2);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.topbar-icon-btn:hover { background: var(--surface-2); color: var(--fg); }
.topbar-bell-dot {
    position: absolute;
    top: 8px;
    right: 10px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    border: 2px solid var(--bg);
}

.topbar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    border: 0;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
}

.topbar-bell-wrap,
.topbar-avatar-wrap { position: relative; }

.topbar-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    z-index: 50;
    overflow: hidden;
}
.topbar-dropdown-head {
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
}
.topbar-dropdown-item {
    display: block;
    padding: 10px 14px;
    color: var(--fg);
    font-size: var(--fs-sm);
    text-decoration: none;
}
.topbar-dropdown-item:hover { background: var(--surface-2); text-decoration: none; }
.topbar-dropdown-danger { color: var(--danger); }
.topbar-dropdown-empty {
    padding: 14px;
    font-size: var(--fs-sm);
    color: var(--muted);
    margin: 0;
}

/* Search overlay */
.search-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
}
.search-overlay.is-open { display: block; }
.search-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
}
.search-overlay-panel {
    position: relative;
    max-width: 560px;
    margin: 60px auto 0;
    background: var(--bg-alt);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
    overflow: hidden;
    padding: 8px;
}
.search-overlay-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--surface);
    border-radius: 10px;
    border: 1px solid var(--border);
    transition: border-color 0.12s;
}
.search-overlay-input-wrap:focus-within {
    border-color: var(--border-strong);
}
.search-overlay-input-wrap svg { color: var(--muted); flex: 0 0 auto; }
.search-overlay-input-wrap input {
    flex: 1;
    border: 0;
    background: transparent;
    padding: 0;
    font-size: 15px;
    min-height: 0;
    color: var(--fg);
}
.search-overlay-input-wrap input::placeholder { color: var(--muted); }
.search-overlay-input-wrap input:focus { outline: none; box-shadow: none; }
.search-overlay-close {
    background: transparent;
    border: 1px solid var(--border);
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    color: var(--muted);
    font-family: var(--font-mono);
    cursor: pointer;
}
.search-overlay-close:hover { background: var(--surface-2); color: var(--fg); }
.search-overlay-results {
    max-height: 60vh;
    overflow-y: auto;
    padding: 6px;
    margin-top: 6px;
}
.search-overlay-hint {
    padding: 20px 16px;
    color: var(--muted);
    font-size: var(--fs-sm);
    margin: 0;
    text-align: center;
}
.search-result {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--fg);
}
.search-result:hover { background: var(--surface); text-decoration: none; }
.search-result-title { font-size: var(--fs-sm); font-weight: 500; }
.search-result-sub { font-size: var(--fs-xs); color: var(--muted); margin-top: 2px; }

/* Responsive */
@media (max-width: 640px) {
    .topbar-search-kbd { display: none; }
    .topbar-search-label { font-size: 13px; }
}

/* Hide the old mobile-only topbar if still present */
.app-topbar { display: none !important; }


/* ==========================================================================
   Item detail — v2 (unified card + updates + right sidebar)
   ========================================================================== */

.item-page {
    width: 100%;
}

.item-reminder-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.reminder-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.reminder-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.item-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--fs-sm);
    color: var(--muted);
    text-decoration: none;
    margin-bottom: var(--space-4);
}
.item-back:hover { color: var(--fg); text-decoration: none; }

.item-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 28px;
    align-items: start;
}

@media (max-width: 1000px) {
    .item-layout { grid-template-columns: 1fr; gap: 20px; }
}

/* --- Unified original-entry card ---------------------------------------- */

.orig-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px 28px;
}

.orig-head { position: relative; }

.orig-badge-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
}
.orig-fav { color: #eab308; font-size: 16px; }

.orig-menu-wrap {
    position: absolute;
    top: 0;
    right: 0;
}
.orig-menu-btn {
    font-size: 20px;
    line-height: 1;
    width: 34px;
    height: 34px;
}
.orig-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 170px;
    z-index: 40;
    overflow: hidden;
}
.orig-menu a,
.orig-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    background: transparent;
    border: 0;
    color: var(--fg);
    font-size: var(--fs-sm);
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
}
.orig-menu a:hover,
.orig-menu button:hover { background: var(--surface-2); text-decoration: none; }
.orig-menu-danger { color: var(--danger); }
.orig-menu-danger:hover { background: var(--danger-soft); }

.orig-title {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.25;
    margin: 0 0 12px;
    color: var(--fg);
}

.orig-desc {
    font-size: var(--fs-base);
    line-height: 1.65;
    color: var(--fg-2);
    margin-bottom: 16px;
}
.orig-desc-toggle {
    background: none;
    border: 0;
    padding: 0;
    color: var(--brand);
    font-family: inherit;
    font-size: var(--fs-sm);
    cursor: pointer;
    margin-bottom: 16px;
}
.orig-desc-toggle:hover { text-decoration: underline; }

.orig-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    margin-top: 16px;
}
.orig-meta-left {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    font-size: var(--fs-sm);
    color: var(--fg-2);
}
.orig-meta-left span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.orig-meta-left svg { color: var(--muted); }

.orig-edit-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--fs-sm);
    color: var(--brand);
    text-decoration: none;
    flex: 0 0 auto;
}
.orig-edit-btn:hover { text-decoration: underline; }

.orig-task-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 12px;
}

.orig-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

/* Attachments inside the card */
.orig-attach {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.orig-attach-empty {
    text-align: right;
    padding-top: 12px;
}
.orig-attach-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.orig-attach-title {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--fg);
}
.orig-attach-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.orig-attach-item {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
}
.orig-attach-icon {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border-radius: 6px;
    font-size: 18px;
    color: var(--muted);
}
.orig-attach-thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background-size: cover;
    background-position: center;
    background-color: var(--surface-2);
    border: 0;
    cursor: pointer;
    padding: 0;
}
.orig-attach-body { min-width: 0; }
.orig-attach-name {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--fg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.orig-attach-sub {
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-top: 2px;
}
.orig-attach-actions {
    display: flex;
    gap: 2px;
    align-items: center;
}

/* --- Updates card ------------------------------------------------------- */

.updates-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-top: 20px;
    overflow: hidden;
}
.updates-head {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}
.updates-head-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--fg);
}
.updates-head-title svg { color: var(--muted); }

.updates-empty {
    padding: 24px;
    text-align: center;
}

.updates-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.update-item {
    display: grid;
    grid-template-columns: 32px 1fr;
    gap: 12px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}
.update-item:last-child { border-bottom: 0; }

.update-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex: 0 0 auto;
}
.update-body { min-width: 0; }
.update-head {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    font-size: var(--fs-sm);
    margin-bottom: 4px;
    position: relative;
}
.update-name { font-weight: 600; color: var(--fg); }
.update-action { color: var(--muted); }
.update-time { color: var(--muted); margin-left: auto; font-size: var(--fs-xs); }
.update-edited { color: var(--muted); font-style: italic; font-size: var(--fs-xs); }
.update-menu-btn { font-size: 16px; line-height: 1; width: 26px; height: 26px; padding: 0; }
.update-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 140px;
    z-index: 40;
    overflow: hidden;
}
.update-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 14px;
    background: transparent;
    border: 0;
    color: var(--fg);
    font-size: var(--fs-sm);
    font-family: inherit;
    cursor: pointer;
}
.update-menu button:hover { background: var(--surface-2); }
.update-menu-danger { color: var(--danger); }
.update-menu-danger:hover { background: var(--danger-soft); }

.update-content {
    font-size: var(--fs-sm);
    line-height: 1.6;
    color: var(--fg-2);
    margin-top: 4px;
}
.update-content[contenteditable="true"] {
    padding: 8px;
    border: 1px solid var(--brand);
    border-radius: 6px;
    background: var(--bg);
}
.update-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 8px;
}
.update-edit-actions .link-btn { font-size: var(--fs-sm); }

.update-files {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.update-thumb {
    width: 66px;
    height: 66px;
    border-radius: 8px;
    background-size: cover;
    background-position: center;
    background-color: var(--surface-2);
    border: 1px solid var(--border);
    cursor: pointer;
    padding: 0;
}
.update-audio { max-width: 320px; height: 32px; }
.update-file-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--surface-2);
    border-radius: var(--radius-full);
    font-size: var(--fs-sm);
    color: var(--fg);
    text-decoration: none;
}
.update-file-link:hover { background: var(--brand-soft); color: var(--brand); text-decoration: none; }

/* --- Compact composer --------------------------------------------------- */

.composer {
    padding: 14px 20px 18px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}
.composer-error {
    padding: 8px 12px;
    background: var(--danger-soft);
    color: var(--danger-fg);
    border-radius: 6px;
    font-size: var(--fs-sm);
    margin-bottom: 8px;
}
.composer-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.composer-chips:empty { display: none; }
.composer-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--surface-2);
    border-radius: var(--radius-full);
    font-size: var(--fs-xs);
    color: var(--fg-2);
}
.composer-chip-x {
    background: none;
    border: 0;
    cursor: pointer;
    color: var(--muted);
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
}
.composer-chip-x:hover { color: var(--danger); }

.composer-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.composer-row-recording {
    padding: 8px 12px;
    background: var(--danger-soft);
    border-radius: var(--radius-full);
}
.composer-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex: 0 0 auto;
}
.composer-input-wrap {
    flex: 1;
    position: relative;
    min-width: 0;
}
.composer-input {
    min-height: 44px;
    max-height: 140px;
    overflow-y: auto;
    padding: 12px 18px;
    font-size: var(--fs-base);
    line-height: 1.5;
    color: var(--fg);
    background: var(--bg-alt);
    border: 1px solid transparent;
    border-radius: 22px;
    outline: none;
    transition: background 0.12s, border-color 0.12s;
}

.composer-input:focus {
    background: var(--surface);
    border-color: var(--border-strong);
}
.composer-input:empty::before {
    content: attr(data-placeholder);
    color: var(--muted);
    pointer-events: none;
}
.composer-input p { margin: 0; }

.composer-format-popover {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    display: flex;
    gap: 2px;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 30;
}
.composer-format-btn {
    min-width: 32px;
    height: 30px;
    padding: 0 8px;
    background: transparent;
    border: 0;
    border-radius: 6px;
    font-size: var(--fs-sm);
    font-family: inherit;
    cursor: pointer;
    color: var(--fg-2);
}
.composer-format-btn:hover { background: var(--surface-2); color: var(--fg); }

.composer-icon-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 50%;
    color: var(--muted);
    cursor: pointer;
    font-family: inherit;
    font-size: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.composer-icon-btn:hover { background: var(--surface-2); color: var(--fg); }
.composer-post {
    margin-left: 6px;
    padding: 10px 22px;
    min-height: 44px;
    font-size: var(--fs-base);
    border-radius: 22px;
}

.composer-recording-status {
    flex: 1;
    font-size: var(--fs-sm);
    color: var(--danger-fg);
}

/* --- Right sidebar ------------------------------------------------------ */

.item-side { display: flex; flex-direction: column; gap: 16px; }

.side-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.side-card-primary {
    border-color: var(--brand);
    box-shadow: 0 1px 3px rgba(22, 163, 74, 0.08);
}
.side-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.side-card-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.side-card-icon-plain {
    background: var(--surface-2);
    color: var(--fg-2);
}
.side-card-title {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--fg);
    flex: 1;
    min-width: 0;
}
.side-card-sub {
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-top: 2px;
}
.side-card-link { flex: 0 0 auto; }
.side-card-body { padding: 12px 16px 14px; }

.side-action {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 0;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--border);
    color: var(--fg);
    font-family: inherit;
    font-size: var(--fs-sm);
    font-weight: 500;
    text-align: left;
    cursor: pointer;
}
.side-action:last-child { border-bottom: 0; }
.side-action:hover { color: var(--brand); }
.side-action svg { color: var(--muted); flex: 0 0 auto; }

.side-file {
    display: grid;
    grid-template-columns: 32px 1fr;
    gap: 10px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.side-file:last-child { border-bottom: 0; }
.side-file-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background-size: cover;
    background-position: center;
    background-color: var(--surface-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 14px;
}
.side-file-icon-plain { background: var(--surface-2); }
.side-file-body { min-width: 0; }
.side-file-name {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--fg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.side-file-sub {
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-top: 2px;
}

.side-reminders {
    list-style: none;
    padding: 0;
    margin: 0 0 12px;
}
.side-reminder-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: var(--fs-sm);
    border-bottom: 1px solid var(--border);
}
.side-reminder-item:last-child { border-bottom: 0; }

.side-reminder-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.side-reminder-form input,
.side-reminder-form select {
    padding: 7px 10px;
    font-size: var(--fs-sm);
    min-height: 34px;
}

.side-related {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: var(--fs-sm);
}
.side-related-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--brand);
    flex: 0 0 auto;
}
.side-related-link {
    flex: 1;
    color: var(--fg);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.side-related-link:hover { color: var(--brand); text-decoration: none; }

/* --- File Library modal ------------------------------------------------- */

.modal-file-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.modal-file-item {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.modal-file-body { min-width: 0; }
.modal-file-name {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--fg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.modal-file-sub { font-size: var(--fs-xs); color: var(--muted); margin-top: 2px; }

/* --- Responsive --------------------------------------------------------- */

@media (max-width: 640px) {
    .orig-card { padding: 18px 16px; }
    .orig-title { font-size: 20px; }
    .orig-meta { flex-direction: column; align-items: flex-start; }
    .composer { padding: 12px 14px 14px; }
    .composer-input { min-height: 34px; padding: 7px 12px; }
    .update-item { padding: 14px 16px; }
}

/* --- Compact uploader (composer inline) --------------------------------- */

.uploader-entry-compact {
    grid-template-columns: 24px 1fr auto;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface-2);
    margin-top: 6px;
}
.uploader-entry-compact .uploader-entry-icon {
    font-size: 14px;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.uploader-entry-compact .uploader-entry-name {
    font-size: var(--fs-xs);
    font-weight: 500;
}
.uploader-entry-compact .uploader-entry-meta {
    font-size: 10px;
    margin-top: 1px;
}
.uploader-entry-compact .uploader-progress {
    height: 3px;
    margin-top: 4px;
}
.uploader-entry-compact .uploader-entry-actions {
    gap: 2px;
}
.uploader-entry-compact .uploader-action {
    font-size: 10px;
    padding: 2px 8px;
}
.uploader-entry-compact .uploader-remove {
    font-size: 14px;
    padding: 0 6px;
}


/* --- Small text links --------------------------------------------------- */

.link-btn {
    background: none;
    border: 0;
    padding: 0;
    color: var(--brand);
    font-family: inherit;
    font-size: var(--fs-sm);
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
}
.link-btn:hover { text-decoration: underline; }
.link-btn-danger { color: var(--danger); }
.link-btn-danger:hover { color: var(--danger); }

.side-card-link {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--brand);
}
.side-card-link:hover { text-decoration: underline; }

/* "+ Add file" inline link in the attachments head */
.orig-attach-empty .link-btn {
    font-size: var(--fs-sm);
    color: var(--brand);
}

.inline-attach-host {
    margin-top: 12px;
}

/* --- Button spinner ---------------------------------------------------- */

.btn.is-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}
.btn.is-loading::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    top: calc(50% - 7px);
    left: calc(50% - 7px);
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btn-spin 0.7s linear infinite;
}
.btn-secondary.is-loading::after {
    border-color: rgba(15,23,42,0.15);
    border-top-color: var(--fg);
}
@keyframes btn-spin {
    to { transform: rotate(360deg); }
}


/* --- Confirm modal ----------------------------------------------------- */

.confirm-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 4000;
}
.confirm-modal.is-open { display: flex; align-items: center; justify-content: center; }
.confirm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
}
.confirm-panel {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    max-width: 400px;
    width: calc(100vw - 40px);
}
.confirm-panel h3 {
    margin: 0 0 8px;
    font-size: var(--fs-lg);
}
.confirm-panel p {
    margin: 0 0 20px;
    color: var(--fg-2);
    font-size: var(--fs-sm);
}
.confirm-panel-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}


/* --- Focus states ------------------------------------------------------ */

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 4px;
}

button:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* Remove for pointer users (mouse click) */
:focus:not(:focus-visible) {
    outline: none;
}


/* --- Recent searches Topbar js --------------------------------------------------- */

.search-recent {
    padding: 4px;
}
.search-recent-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
}
.search-recent-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: 0;
    border-radius: 8px;
    color: var(--fg);
    font-family: inherit;
    font-size: var(--fs-sm);
    text-align: left;
    cursor: pointer;
}
.search-recent-item:hover { background: var(--surface); }
.search-recent-item svg { color: var(--muted); flex: 0 0 auto; }

/* --- Faster File Preview --------------------------------------------------- */

.pm-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    width: 100%;
    position: relative;
    overflow: hidden;
}

.pm-loading::after {
    content: '';
    display: block;
    width: 36px;
    height: 36px;
    border: 4px solid #cbd5e1;
    border-top-color: #16a34a;
    border-radius: 50%;
    animation: pm-spin 0.9s linear infinite;
    transform-origin: center center;
    will-change: transform;
}

@keyframes pm-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}


/* --- Sidebar install prompt ------------------------------------------- */

.sidebar-install {
    margin: 8px 0 4px;
    padding: 10px;
    background: var(--brand-soft);
    border: 1px solid var(--brand);
    border-radius: 10px;
}
.sidebar-install-row {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    gap: 10px;
    align-items: center;
}
.sidebar-install-row .brand-mark {
    width: 28px;
    height: 28px;
    font-size: 14px;
}
.sidebar-install-body { min-width: 0; }
.sidebar-install-title {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--brand);
    line-height: 1.2;
}
.sidebar-install-sub {
    font-size: 11px;
    color: var(--brand);
    opacity: 0.8;
    margin-top: 1px;
    line-height: 1.2;
}
.sidebar-install-btn {
    padding: 4px 10px;
    font-size: 11px;
    min-height: 28px;
    background: var(--brand);
    color: #fff;
    border-radius: 6px;
}
.sidebar-install-btn:hover { background: var(--brand-hover); }


/* --- Sidebar cards (v2 collapsible) ------------------------------------ */

.side-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    background: transparent;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    width: 100%;
    text-align: left;
    font-family: inherit;
    cursor: default;
}
.side-card-toggle {
    cursor: pointer;
}
.side-card-toggle:hover {
    background: var(--surface-2);
}
.side-card-toggle .side-card-caret {
    color: var(--muted);
    transition: transform 0.15s;
    flex: 0 0 auto;
}
.side-card-collapsible.is-open .side-card-toggle .side-card-caret {
    transform: rotate(90deg);
}

.side-card-body-collapsible {
    display: none;
}
.side-card-collapsible.is-open .side-card-body-collapsible {
    display: block;
}

.side-card-collapsible:not(.is-open) .side-card-head {
    border-bottom: 0;
}

.side-card-title-grow {
    flex: 1;
    min-width: 0;
}
.side-card-summary {
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-top: 2px;
}

/* Space out the sidebar vertically */
.item-side {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* --- Offline status pill ----------------------------------------------- */

.offline-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: var(--radius-full);
    background: var(--surface-2);
    color: var(--fg-2);
    transition: background 0.2s, color 0.2s;
}

.offline-status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
}

.offline-status.is-online {
    background: var(--brand-soft);
    color: var(--brand);
}
.offline-status.is-online::before { background: var(--brand); }

.offline-status.is-offline {
    background: var(--danger-soft);
    color: var(--danger-fg);
}
.offline-status.is-offline::before {
    background: var(--danger);
    animation: offline-pulse 1.6s ease-in-out infinite;
}

.offline-status.is-pending {
    background: var(--warn-soft);
    color: var(--warn);
}
.offline-status.is-pending::before { background: var(--warn); }

.offline-status.is-flushing {
    background: var(--warn-soft);
    color: var(--warn);
}
.offline-status.is-flushing::before {
    background: var(--warn);
    animation: offline-pulse 1s ease-in-out infinite;
}

@keyframes offline-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

@media (max-width: 640px) {
    .offline-status {
        font-size: 11px;
        padding: 3px 8px;
    }
}

@media (min-width: 901px) {
    .sidebar { transform: none !important; }
}

/* ==========================================================================
   Dashboard v2 — compact stats + hero recent items
   ========================================================================== */

.dash-page {
    max-width: 780px;
    margin: 0 auto;
    padding: var(--space-5) 0 var(--space-8);
}

/* --- Compact stats strip --- */

.dash-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: var(--space-6);
}

.dash-stat {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--fg);
    transition: border-color 0.12s, box-shadow 0.12s;
}
.dash-stat:hover {
    border-color: var(--border-strong);
    text-decoration: none;
}

.dash-stat-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.dash-stat-value {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.1;
    color: var(--fg);
}

.dash-stat-label {
    font-size: var(--fs-xs);
    color: var(--muted);
    line-height: 1.2;
}

/* --- Hero header --- */

.dash-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
    flex-wrap: wrap;
}

.dash-head h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.dash-sub {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: var(--fs-sm);
}

/* --- Section heads --- */

.dash-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin: 0 0 var(--space-3);
}

.dash-section-head h2 {
    margin: 0;
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--fg);
}

.dash-see-all {
    font-size: var(--fs-sm);
    color: var(--brand);
    text-decoration: none;
}
.dash-see-all:hover { text-decoration: underline; }

/* --- Item list --- */

.dash-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dash-item {
    list-style: none;
}

.dash-item-link {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    text-decoration: none;
    color: var(--fg);
    transition: border-color 0.12s, background 0.12s;
}

.dash-item-link:hover {
    border-color: var(--border-strong);
    background: var(--bg-alt);
    text-decoration: none;
}

.dash-item-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.dash-item-body {
    min-width: 0;
}

.dash-item-title {
    font-size: var(--fs-base);
    font-weight: 500;
    color: var(--fg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.dash-item-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-top: 4px;
}

.dash-item-type {
    font-weight: 500;
}

.dash-item-files {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: var(--muted);
}

.dash-item-amount {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--fg);
    text-align: right;
    flex: 0 0 auto;
}

/* --- Responsive --- */

@media (max-width: 640px) {
    .dash-head h1 { font-size: 22px; }
    .dash-item-link { padding: 10px 12px; }
    .dash-item-icon { width: 36px; height: 36px; }
    .dash-item-amount { font-size: var(--fs-xs); }
    .dash-stat-value { font-size: 20px; }
    .dash-stat { padding: 12px; }
}

/* --- Notifications bell ----------------------------------------------- */

.topbar-bell-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--danger);
    color: #fff;
    border-radius: 9px;
    font-size: 10px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    border: 2px solid var(--bg);
    box-sizing: content-box;
}

.topbar-dropdown-wide {
    min-width: 320px;
    max-width: 380px;
}

.topbar-dropdown-foot {
    display: block;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    font-size: var(--fs-sm);
    color: var(--brand);
    text-decoration: none;
    text-align: center;
}
.topbar-dropdown-foot:hover { background: var(--surface-2); text-decoration: none; }

/* --- Bell item with actions ------------------------------------------- */

.bell-item {
    display: block;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}
.bell-item:last-child { border-bottom: 0; }

.bell-item-head {
    display: grid;
    grid-template-columns: 32px 1fr;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.bell-item-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.bell-item-body { min-width: 0; }
.bell-item-title {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--fg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bell-item-meta {
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-top: 2px;
}

.bell-item-actions {
    display: flex;
    gap: 6px;
    padding-left: 42px;
}

.bell-action {
    padding: 5px 12px;
    font-size: 12px;
    font-family: inherit;
    font-weight: 500;
    background: var(--surface-2);
    color: var(--fg-2);
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.bell-action:hover { background: var(--brand-soft); color: var(--brand); }
.bell-action-primary {
    background: var(--brand);
    color: #fff;
}
.bell-action-primary:hover { background: var(--brand-hover); color: #fff; }
.bell-action-more {
    padding: 5px 10px;
    font-size: 14px;
    line-height: 1;
}

/* --- Snooze menu -------------------------------------------------------- */

.bell-snooze-menu {
    position: fixed;
    z-index: 200;
    min-width: 180px;
    max-width: 260px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    padding: 4px;
}

.bell-snooze-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 12px;
    background: transparent;
    border: 0;
    border-radius: 6px;
    color: var(--fg);
    font-family: inherit;
    font-size: var(--fs-sm);
    cursor: pointer;
}

.bell-snooze-menu button:hover {
    background: var(--surface-2);
}

.bell-snooze-danger {
    color: var(--danger);
}

.bell-snooze-danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

@media (max-width: 640px) {
    .bell-item-actions { padding-left: 0; }
}

/* --- Full notifications page ------------------------------------------ */

.notif-section-title {
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--fg);
    margin: 0 0 var(--space-3);
}

.notif-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.notif-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    transition: border-color 0.12s;
}
.notif-item:hover { border-color: var(--border-strong); }
.notif-item.is-ack { opacity: 0.7; }

.notif-link {
    display: grid;
    grid-template-columns: 40px 1fr;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    text-decoration: none;
    color: var(--fg);
}
.notif-link:hover { text-decoration: none; }

.notif-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.notif-body { min-width: 0; }
.notif-title {
    font-size: var(--fs-base);
    font-weight: 500;
    color: var(--fg);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.notif-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-top: 4px;
}

.notif-ack {
    margin-right: 14px;
}

/* --- Channel picker ---------------------------------------------------- */

.channel-picker {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.channel-option {
    display: grid;
    grid-template-columns: 20px 40px 1fr;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
    margin: 0;
    font-weight: 400;
}

.channel-option:hover { border-color: var(--border-strong); }

.channel-option.is-active {
    border-color: var(--brand);
    background: var(--brand-soft);
}

.channel-option input[type="radio"] {
    width: auto;
    min-height: 0;
    margin: 0;
    accent-color: var(--brand);
}

.channel-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--fg-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.channel-option.is-active .channel-icon {
    background: var(--brand);
    color: #fff;
}

.channel-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.channel-title {
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--fg);
    line-height: 1.3;
}

.channel-sub {
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-top: 2px;
    line-height: 1.4;
}


/* --- Add menu --------------------------------------------------------- */

.add-menu-wrap { position: relative; }

.add-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 280px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    overflow: hidden;
}

.add-menu-item {
    display: grid;
    grid-template-columns: 32px 1fr;
    gap: 10px;
    align-items: center;
    padding: 12px 14px;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--border);
    width: 100%;
    text-align: left;
    font-family: inherit;
    cursor: pointer;
    color: var(--fg);
    text-decoration: none;
}
.add-menu-item:last-child { border-bottom: 0; }
.add-menu-item:hover { background: var(--surface-2); text-decoration: none; }

.add-menu-title {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--fg);
}
.add-menu-sub {
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-top: 2px;
}

/* --- Share active state ------------------------------------------------ */

#share-active-state .alert { font-size: var(--fs-sm); }

/* --- Shared page ------------------------------------------------------ */

.shared-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.shared-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color 0.12s;
}
.shared-card:hover { border-color: var(--border-strong); }

.shared-card-head {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    gap: 14px;
    align-items: center;
}

.shared-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--fg-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.shared-icon-record   { background: #dcfce7; color: #16a34a; }
.shared-icon-task     { background: #dbeafe; color: #2563eb; }
.shared-icon-event    { background: #fef3c7; color: #d97706; }
.shared-icon-reminder { background: #fee2e2; color: #dc2626; }
.shared-icon-note     { background: #f1f5f9; color: #475569; }

.shared-title-wrap { min-width: 0; }
.shared-title {
    font-size: var(--fs-base);
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.shared-title a { color: var(--fg); text-decoration: none; }
.shared-title a:hover { color: var(--brand); }

.shared-meta {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 4px;
    font-size: var(--fs-xs);
    color: var(--muted);
}

.shared-status { flex: 0 0 auto; }

.shared-card-body {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: var(--fs-xs);
    color: var(--fg-2);
    padding-left: 58px;
}

.shared-flag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.shared-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding-left: 58px;
}

@media (max-width: 640px) {
    .shared-card-head { grid-template-columns: 40px 1fr; }
    .shared-status { grid-column: 1 / -1; margin-top: 4px; }
    .shared-card-body { padding-left: 0; }
    .shared-actions { padding-left: 0; }
}

/* ================================================================
   Mobile item-detail fixes
   ================================================================ */

/* Hide the sidebar stack entirely on phones and narrow tablets. */
@media (max-width: 900px) {
    .item-side { display: none; }
}

/* Composer: give the input room. Let the buttons wrap to a second row. */
@media (max-width: 640px) {
    .composer {
        padding: 14px 16px 18px;
    }

    .composer-row {
        flex-wrap: wrap;
        gap: 8px;
    }

    .composer-avatar { display: none; }
    .composer-input-wrap {
        flex: 1 1 100%;
        order: 1;
    }

    .composer-input {
        min-height: 64px;
        max-height: 240px;
        padding: 12px 16px;
        font-size: 16px;
        line-height: 1.5;
    }

    .composer-icon-btn {
        order: 2;
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .composer-post {
        order: 3;
        margin-left: auto;
        min-height: 36px;
        padding: 8px 18px;
        font-size: var(--fs-sm);
    }

    .updates-list {
        max-height: 420px;
        overflow-y: auto;
    }
}

/* Tighten side cards if any of them do show on mid-size screens. */
@media (max-width: 640px) {
    .side-card-head { padding: 12px 14px; }
    .side-card-body { padding: 10px 14px 12px; }
    .side-card-title { font-size: var(--fs-sm); }
}

/* Bring the composer up on mobile. */
@media (max-width: 640px) {
    .updates-card {
        display: flex;
        flex-direction: column;
    }
    .composer {
        order: -1;
        border-top: 0;
        border-bottom: 1px solid var(--border);
        margin-bottom: 4px;
    }
}

/* ================================================================
   Mobile item-detail — compact action bar + collapsed updates
   ================================================================ */

.mobile-action-bar {
    display: none;
}

@media (max-width: 900px) {
    .item-side {
        display: none;
    }

    .mobile-action-bar {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        padding: 12px 0 16px;
        margin-bottom: 16px;
        border-bottom: 1px solid var(--border);
    }

    .mobile-action-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 12px 8px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        color: var(--fg-2);
        font-family: inherit;
        cursor: pointer;
        transition: background 0.12s, border-color 0.12s, color 0.12s;
        min-height: 64px;
    }

    .mobile-action-btn:active {
        background: var(--brand-soft);
        border-color: var(--brand);
        color: var(--brand);
    }

    .mobile-action-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        color: var(--fg-2);
    }

    .mobile-action-label {
        font-size: 12px;
        font-weight: 500;
        color: var(--fg);
    }

    .updates-list {
        max-height: 320px;
        overflow-y: auto;
    }

    .updates-card {
        display: flex;
        flex-direction: column;
    }
    .composer {
        order: -1;
        border-top: 0;
        border-bottom: 1px solid var(--border);
        margin-bottom: 8px;
        padding: 14px 16px 18px;
    }

    .composer-row {
        flex-wrap: wrap;
        gap: 8px;
    }
    .composer-avatar { display: none; }
    .composer-input-wrap {
        flex: 1 1 100%;
        order: 1;
    }
    .composer-input {
        min-height: 64px;
        max-height: 240px;
        padding: 12px 16px;
        font-size: 16px;
        line-height: 1.5;
    }
    .composer-icon-btn {
        order: 2;
        width: 36px;
        height: 36px;
    }
    .composer-post {
        order: 3;
        margin-left: auto;
        min-height: 36px;
        padding: 8px 18px;
        font-size: var(--fs-sm);
    }
}

/* --- Thumbnail fill fix ------------------------------------------------ */

.orig-attach-thumb,
.update-thumb,
.list-thumb {
    padding: 0;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.orig-attach-thumb img,
.update-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Share modal — recipient rows */
#modal-share #share-recipients-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

#modal-share #share-recipients-list .share-recipient-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

#modal-share #share-recipients-list .share-recipient-row:last-child {
    border-bottom: none;
}

#modal-share #share-recipients-list .share-recipient-email {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 14px;
    word-break: break-all;
    color: var(--text);
}

#modal-share #share-recipients-list .share-recipient-role {
    flex: 0 0 auto;
    width: auto;
    min-width: 140px;
    max-width: 180px;
    font-size: 13px;
}

#modal-share #share-recipients-list .share-recipient-remove {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    cursor: pointer;
}

#modal-share #share-recipients-list .share-recipient-remove:hover {
    background: var(--surface-2);
    color: var(--danger);
}

.toast, .toast-container, #toast, #toast-container {
    z-index: 10000 !important;
}

/* Search overlay — highlight matched words, type badge, file icon */
.search-result-title mark,
.search-result-sub mark {
    background: #fef3c7;
    color: inherit;
    padding: 0 2px;
    border-radius: 3px;
}

.search-type-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--surface-2, #e2e8f0);
    color: var(--muted, #64748b);
    padding: 1px 6px;
    border-radius: 4px;
    margin-right: 4px;
    vertical-align: middle;
}

.search-sub-icon {
    font-size: 11px;
    margin-right: 2px;
}

/* Attachment highlight when scrolled to via #file-{id} */
.orig-attach-item.is-highlighted,
.side-file.is-highlighted {
    animation: file-pulse 2.2s ease-out;
}

@keyframes file-pulse {
    0%   { background: #fef3c7; box-shadow: 0 0 0 2px #fbbf24; }
    80%  { background: #fef3c7; box-shadow: 0 0 0 2px #fbbf24; }
    100% { background: transparent; box-shadow: none; }
}

/* Library list — shared indicator */
.shared-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--info-soft, #eff6ff);
    color: var(--info, #1e40af);
    vertical-align: middle;
    flex: 0 0 18px;
}
.shared-indicator svg {
    width: 11px;
    height: 11px;
}

.uploader-entry.is-pending-upload {
    background: #fef3c7;
    border-color: #fde68a;
}
.uploader-pending {
    color: #92400e;
    font-weight: 500;
}
.uploader-status.is-pending {
    color: #92400e;
}

/* Vault Uploader */

.vault-uploader-entry .vault-stage-label { transition: color 0.2s; }
.vault-uploader-entry.is-uploaded { background: #f0fdf4; border-color: #86efac; }
.vault-uploader-entry.is-failed { background: #fef2f2; border-color: #fecaca; }


/* Thumbnail with share-badge overlay */
.library-row-thumb {
    position: relative;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
}

.thumb-share-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--info);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 2px var(--surface);
    pointer-events: none;
    z-index: 2;
}

.thumb-share-badge svg {
    width: 10px;
    height: 10px;
    stroke: currentColor;
    display: block;
}


/* --- Improvement 1: reserve space for the bulk bar --- */
body.has-bulk-bar {
    padding-bottom: 96px; /* height of the bulk bar + safe area */
}

/* --- Improvement 3: horizontal-scrolling type chips on mobile --- */
@media (max-width: 640px) {
    .type-chips-row {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;      /* Firefox */
        padding-bottom: 4px;        /* small buffer so chips don't clip on focus ring */
        margin-left: -20px;
        margin-right: -20px;
        padding-left: 20px;
        padding-right: 20px;
    }
    .type-chips-row::-webkit-scrollbar {
        display: none;              /* Chrome / Safari */
    }
    .type-chips-row .type-chip {
        flex-shrink: 0;
    }
}

/* --- Improvement 5: filter button active state --- */
#more-filters-btn.is-active {
    background: var(--info-soft);
    color: var(--info);
    border-color: var(--info);
}
.filter-active-dot {
    display: inline-block;
    margin-left: 4px;
    font-size: 16px;
    line-height: 1;
    vertical-align: middle;
    color: currentColor;
}

/* --- Improvement 7: disabled pagination placeholders --- */
.pagination .btn.is-disabled {
    opacity: 0.45;
    pointer-events: none;
    cursor: default;
}

/* --- Improvement 8: empty-state query emphasis --- */
.empty-state-query {
    color: var(--fg);
    font-weight: 600;
    word-break: break-word;
}


/* --- Recurring new feature css --- */

.recurring-card {
    margin: 24px 0;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.recurring-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.recurring-title {
    margin: 0;
    font-size: var(--fs-lg);
    font-weight: 600;
}
.recurring-summary {
    margin-bottom: 20px;
}
.recurring-total {
    font-size: var(--fs-base);
    margin-bottom: 6px;
}
.recurring-total.muted {
    color: var(--muted);
    font-size: var(--fs-sm);
}
.recurring-next-due {
    font-size: var(--fs-sm);
    color: var(--muted);
    margin-top: 4px;
}
.recurring-next-due.is-overdue {
    color: var(--danger);
    font-weight: 500;
}
.recurring-calendar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}
@media (max-width: 640px) {
    .recurring-calendar { grid-template-columns: repeat(3, 1fr); }
}
.recurring-month {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: inherit;
}
.recurring-month:hover { border-color: var(--brand); }
.recurring-month.is-active {
    border-color: var(--brand);
    background: var(--brand-soft);
}
.recurring-month.is-empty { opacity: 0.65; cursor: default; }
.recurring-month-label {
    display: block;
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 4px;
}
.recurring-month-total {
    display: block;
    font-weight: 600;
    font-size: var(--fs-sm);
}
.recurring-month-count {
    font-size: var(--fs-xs);
    color: var(--muted);
}
.recurring-month-detail {
    grid-column: 1 / -1;
    padding: 12px 14px;
    background: var(--surface-2);
    border-radius: var(--radius);
    margin-top: 4px;
}
.recurring-month-detail h4 {
    margin: 0 0 8px;
    font-size: var(--fs-sm);
    font-weight: 600;
}
.recurring-month-detail ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
.recurring-month-detail li {
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: var(--fs-sm);
    display: flex;
    gap: 10px;
    align-items: center;
}
.recurring-month-detail li:last-child { border-bottom: none; }
.recurring-payment-rows {
    list-style: none;
    margin: 0;
    padding: 0;
}
.recurring-payment-row {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.recurring-payment-row:last-child { border-bottom: none; }
.recurring-row-main {
    display: flex;
    gap: 10px;
    align-items: baseline;
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
}
.recurring-row-date { font-weight: 500; font-size: var(--fs-sm); }
.recurring-row-amount {
    font-weight: 600;
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
}
.recurring-row-method {
    font-size: var(--fs-xs);
    color: var(--muted);
    padding: 1px 6px;
    background: var(--surface-2);
    border-radius: 4px;
}
.recurring-row-note {
    width: 100%;
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-top: 2px;
}
.recurring-row-actions { display: flex; gap: 4px; }