:root {
    /* Without this, native popups (select option lists) default to the OS
       light theme regardless of our dark page styling — that's the low
       contrast bug: dark theme text on a system-light dropdown background. */
    color-scheme: dark;

    --bg-dark: #0a0a0f;
    --bg-panel: rgba(20, 20, 30, 0.6);
    --bg-panel-hover: rgba(30, 30, 45, 0.8);
    --border-color: rgba(255, 255, 255, 0.1);

    --accent-purple: #8b5cf6;
    --accent-blue: #3b82f6;
    --accent-magenta: #d946ef;

    --text-main: #f8fafc;
    --text-muted: #94a3b8;

    --error: #ef4444;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    background-image:
        radial-gradient(circle at 15% 50%, rgba(139, 92, 246, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(217, 70, 239, 0.15), transparent 25%);
    background-attachment: fixed;
    display: flex;
    flex-direction: column;
}

a { color: inherit; text-decoration: none; }

.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

.logo { font-size: 1.1rem; font-weight: 700; }
.logo span { color: var(--accent-magenta); }

.text-muted { color: var(--text-muted); }

/* ---------------------------------------------------------------------- */
/* Buttons                                                                 */
/* ---------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-main);
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
}
.btn:hover { filter: brightness(1.1); }
.btn-block { display: flex; width: 100%; }
.btn.secondary, .btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}
.btn.danger, .btn-danger { background: var(--error); }

/* ---------------------------------------------------------------------- */
/* Topbar                                                                  */
/* ---------------------------------------------------------------------- */
.topbar {
    position: relative;
    z-index: 100;
    margin: 1rem 1.5rem 0;
    padding: 0.85rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }
.topbar-left { display: flex; align-items: center; gap: 1.25rem; }
.topbar-back-link {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-decoration: none;
    transition: color 0.15s;
}
.topbar-back-link:hover { color: var(--text-main); }

.avatar-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-magenta), var(--accent-purple));
    color: white;
    font-weight: 600;
    overflow: hidden;
}
.avatar-circle img { width: 100%; height: 100%; object-fit: cover; }
.avatar-circle-sm { width: 32px; height: 32px; font-size: 0.85rem; }
.avatar-circle-md { width: 48px; height: 48px; font-size: 1.1rem; }

.notif-bell { position: relative; }
.notif-bell-trigger {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.notif-bell-trigger:hover { background: var(--bg-panel-hover); }
.notif-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    border-radius: 999px;
    background: var(--error);
    color: white;
    font-size: 0.65rem;
    line-height: 16px;
    text-align: center;
}
.notif-dropdown {
    position: absolute;
    top: calc(100% + 0.6rem);
    right: 0;
    width: 340px;
    max-height: 420px;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 4px 30px rgba(0,0,0,0.3);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 50;
}
.notif-bell.open .notif-dropdown { opacity: 1; visibility: visible; transform: translateY(0); }
.notif-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}
.btn-icon { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.9rem; }
.notif-list { overflow-y: auto; max-height: 340px; }
.notif-item { display: flex; gap: 0.5rem; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-color); font-size: 0.85rem; }
.notif-item.unread { background: rgba(139, 92, 246, 0.06); }
.notif-item-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-purple); margin-top: 0.4rem; flex-shrink: 0; }
.notif-item-time { color: var(--text-muted); font-size: 0.75rem; margin-top: 0.2rem; }
.notif-load-more { width: 100%; padding: 0.6rem; background: none; border: none; border-top: 1px solid var(--border-color); color: var(--accent-purple); cursor: pointer; }

.profile-menu { position: relative; }
.profile-menu-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.6rem 0.3rem 0.3rem;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
}
.profile-menu-trigger:hover { background: var(--bg-panel-hover); }
.profile-menu-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; }
.profile-menu-chevron { transition: transform 0.15s ease; }
.profile-menu.open .profile-menu-chevron { transform: rotate(180deg); }
.profile-menu-dropdown {
    position: absolute;
    top: calc(100% + 0.6rem);
    right: 0;
    width: 280px;
    padding: 0.5rem;
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 4px 30px rgba(0,0,0,0.3);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 50;
}
.profile-menu.open .profile-menu-dropdown { opacity: 1; visibility: visible; transform: translateY(0); }
.profile-menu-current { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem; }
.profile-menu-current-name { font-weight: 600; font-size: 0.9rem; }
.profile-menu-current-email { color: var(--text-muted); font-size: 0.78rem; }
.profile-menu-divider { height: 1px; background: var(--border-color); margin: 0.4rem 0; }
.profile-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.55rem 0.6rem;
    border: none;
    background: none;
    color: var(--text-main);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    text-align: left;
    text-decoration: none;
    box-sizing: border-box;
}
.profile-menu-item:hover { background: var(--bg-panel-hover); }
.profile-menu-item-danger { color: var(--error); }

/* ---------------------------------------------------------------------- */
/* Dashboard layout (sidebar + content)                                    */
/* ---------------------------------------------------------------------- */
.dashboard-layout { display: flex; flex: 1; overflow: hidden; }
.dashboard-sidebar { width: 220px; margin: 1.5rem; padding: 1.25rem 0; height: fit-content; }
.nav-links { list-style: none; padding: 0 1rem; }
.nav-links a {
    display: block;
    padding: 0.7rem 1rem;
    color: var(--text-muted);
    border-radius: 8px;
    font-size: 0.9rem;
}
.nav-links a:hover, .nav-links a.active { background: var(--bg-panel-hover); color: var(--text-main); }
.dashboard-content { flex: 1; overflow-y: auto; padding: 1.5rem 1.5rem 3rem; }

/* ---------------------------------------------------------------------- */
/* Cards, forms, chips (booky-specific content)                            */
/* ---------------------------------------------------------------------- */
.card {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1.1rem 1.3rem;
    margin-bottom: 1.25rem;
}
/* backdrop-filter gives every .card its own stacking context, so a dropdown
   opened near the bottom of one card (e.g. Condition/Acquired from) would
   otherwise render behind the next card's background rather than on top of
   it, no matter how high the dropdown's own z-index is set. Bumping the
   whole card above its siblings while a lookup dropdown inside it is open
   fixes that without touching the widget's own stacking. */
.card:focus-within { position: relative; z-index: 30; }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.book-card { cursor: pointer; }
.book-card h3 { margin: 0 0 0.25rem; font-size: 1rem; }
.book-card p { margin: 0.15rem 0; color: var(--text-muted); font-size: 0.85rem; }
.badge {
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    background: var(--bg-panel-hover);
    color: var(--text-main);
    margin-right: 0.25rem;
}
.badge-magenta { background: var(--accent-magenta); }

.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: 0.3rem; font-size: 0.85rem; color: var(--text-muted); }
.field input[type=text], .field input[type=number], .field input[type=date],
.field select, .field textarea,
.input {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(0,0,0,0.25);
    color: var(--text-main);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.field textarea { min-height: 5rem; resize: vertical; }
.input:hover:not(:disabled) { border-color: rgba(255,255,255,0.2); }
.input:focus {
    outline: none;
    border-color: var(--accent-purple);
    background: rgba(0,0,0,0.35);
}
.input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background: rgba(255,255,255,0.03);
}
.field select option {
    background: #14141c;
    color: var(--text-main);
}
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.required::after { content: " *"; color: var(--error); }
.help { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.25rem; }

/* Live field validation (same green-valid language as account's login/register forms) */
.field input.field-valid, .field select.field-valid, .field textarea.field-valid,
.lookup-select-wrap input.field-valid {
    border-color: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.15);
}
.field input.field-invalid, .field select.field-invalid, .field textarea.field-invalid,
.lookup-select-wrap input.field-invalid {
    border-color: var(--error);
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15);
}
.field-feedback {
    font-size: 0.78rem;
    margin-top: 0.3rem;
    min-height: 0;
}
.field-feedback-error { color: var(--error); }
.field-feedback-success { color: #22c55e; }

/* Full rules checklist (account's login/register pattern) — one line per
   rule with its own live checkmark/x, used where a single blended message
   isn't enough to show which specific condition still needs meeting. */
.pw-rules {
    margin-top: 0.5rem;
    display: none;
    flex-direction: column;
    gap: 0.3rem;
}
.pw-rules.visible { display: flex; }
.pw-rule {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    transition: color 0.2s;
}
.pw-rule .pw-rule-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    font-size: 0.65rem;
    font-weight: 800;
    flex-shrink: 0;
    background: rgba(255,255,255,0.08);
    color: var(--text-muted);
    transition: background 0.25s, color 0.25s;
}
.pw-rule.valid { color: #22c55e; }
.pw-rule.valid .pw-rule-icon { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.pw-rule.invalid { color: var(--error); }
.pw-rule.invalid .pw-rule-icon { background: rgba(239, 68, 68, 0.15); color: var(--error); }
.form-error {
    color: var(--error);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    padding: 0.7rem 0.9rem;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    display: none;
}
.form-error.visible { display: block; }

.chip-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.chip { background: var(--bg-panel-hover); border-radius: 999px; padding: 0.3rem 0.7rem; font-size: 0.8rem; display: flex; align-items: center; gap: 0.4rem; border: 1px solid var(--border-color); }
.chip button { background: none; border: none; color: var(--text-main); cursor: pointer; font-size: 0.9rem; padding: 0; }

.image-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.image-slot h4 { margin: 0 0 0.4rem; font-size: 0.85rem; color: var(--text-muted); }

/* Searchable single/multi select widgets (lookup-select.js) */
.lookup-select-wrap { position: relative; }
.lookup-search-input { width: 100%; }
.lookup-results {
    display: none;
    position: absolute;
    z-index: 20;
    left: 0;
    right: 0;
    margin-top: 0.25rem;
    max-height: 220px;
    overflow-y: auto;
    background: #14141c;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.lookup-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.7rem;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 0.85rem;
    cursor: pointer;
}
.lookup-option:hover { background: var(--bg-panel-hover); }
.lookup-option-add { color: var(--accent-purple); border-top: 1px solid var(--border-color); width: 100%; text-align: left; }
.lookup-add-row { display: flex; flex-direction: column; }
.lookup-make-default {
    padding: 0.4rem 0.7rem 0.6rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Toggle switch (Settings: "make default", etc.) */
.switch-row { display: flex; align-items: center; gap: 0.6rem; cursor: pointer; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .switch-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-panel-hover);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    transition: background 0.15s ease;
}
.switch .switch-slider::before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 2px;
    top: 2px;
    background: var(--text-main);
    border-radius: 50%;
    transition: transform 0.15s ease;
}
.switch input:checked + .switch-slider { background: var(--accent-purple); border-color: var(--accent-purple); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch input:disabled + .switch-slider { opacity: 0.4; cursor: not-allowed; }

/* Toast notifications — same visual language and behavior as account's
   showToast (see amea-space-account/public/js/app.js), reimplemented here
   rather than shared since the two apps don't share a JS bundle. */
#toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    width: 100%;
    max-width: 400px;
    padding: 0 20px;
}
.toast {
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    pointer-events: auto;
    cursor: pointer;
    animation: toast-slide-down 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast.hiding { opacity: 0; transform: translateY(-20px) scale(0.95); }
.toast.error { border-left: 4px solid var(--error); }
.toast.success { border-left: 4px solid #22c55e; }
.toast.info { border-left: 4px solid var(--accent-purple); }
.toast-message { flex: 1; font-size: 0.95rem; line-height: 1.4; }
.toast-close { opacity: 0.6; transition: opacity 0.2s; font-size: 1.5rem; line-height: 1; display: flex; align-items: center; }
.toast:hover .toast-close { opacity: 1; }

@keyframes toast-slide-down {
    from { opacity: 0; transform: translateY(-40px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Pretty confirm dialog — account doesn't have a generic replacement for
   window.confirm() (it hand-builds a purpose-specific modal per case), but
   plain confirm() next to styled toasts would look inconsistent here, so
   this is a small reusable one instead. */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: confirm-fade-in 0.15s ease forwards;
}
.confirm-box {
    background: var(--bg-panel-hover);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 380px;
    width: calc(100% - 2rem);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
.confirm-message { color: var(--text-main); font-size: 0.95rem; line-height: 1.5; margin: 0 0 1.25rem; }
.confirm-actions { display: flex; gap: 0.6rem; justify-content: flex-end; }

@keyframes confirm-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Finance sub-tabs — the "Finance" sidebar entry stays a single link; these
   are an in-page tab strip so other tools can sit alongside it later without
   the sidebar growing a tree per tool. */
.finance-tabs { display: flex; gap: 0.25rem; margin-bottom: 1.25rem; flex-wrap: wrap; border-bottom: 1px solid var(--border-color); }
.finance-tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.finance-tab-btn:hover { color: var(--text-main); }
.finance-tab-btn.active { color: var(--text-main); border-bottom-color: var(--accent-purple); }
.finance-tab-panel { display: none; }
.finance-tab-panel.active { display: block; }

.data-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}
.data-row:last-child { border-bottom: none; }
.data-row-main { flex: 1; min-width: 160px; }
.data-row-title { font-weight: 500; }
.data-row-sub { color: var(--text-muted); font-size: 0.8rem; }
.data-row-amount { font-weight: 600; min-width: 90px; text-align: right; }
.data-row-amount.negative { color: var(--error); }

.necessity-notwendig { background: var(--accent-blue); }
.necessity-optional { background: var(--accent-purple); }
.necessity-luxus { background: var(--accent-magenta); }

.stat-bar-track { background: rgba(255,255,255,0.06); border-radius: 4px; height: 8px; overflow: hidden; margin-top: 0.35rem; }
.stat-bar-fill { height: 100%; background: var(--accent-purple); }
