/* Finance module styles only. Page chrome (topbar, sidebar, footer, cookiebox,
   theme variables, base reset) comes from the shared shell stylesheet served by
   account (/api/shell/css/style.css), which is loaded before this file. */

.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); }

/* ---------------------------------------------------------------------- */
/* 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 panels — one per sidebar item; the shell's sidebar picks the active one. */
.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-paused { opacity: 0.45; }
.data-row-paused .data-row-title { font-style: italic; }

.expense-group-header {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 1rem 0 0.35rem 0;
}
.expense-group-header:first-child { padding-top: 0; }
.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); }

.month-status-card { text-align: center; }
.month-status-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 0.6rem;
}
.month-status-badge-not_tracked { background: var(--text-muted); }
.month-status-badge-open { background: var(--accent-blue); }
.month-status-badge-ongoing { background: #f59e0b; }
.month-status-badge-completed { background: #22c55e; }
.month-status-select { width: 100%; }
.month-status-total { font-size: 1.2rem; font-weight: 600; margin-bottom: 0.6rem; }
.month-status-total.negative { color: var(--error); }

/* ---------------------------------------------------------------------- */
/* Confirm modal + toast — in-app replacements for window.confirm/alert   */
/* ---------------------------------------------------------------------- */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.confirm-modal {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    padding: 1.5rem;
    max-width: 380px;
    width: 90%;
}
.confirm-modal p {
    margin: 0 0 1.25rem 0;
    font-size: 0.95rem;
    line-height: 1.4;
}
.confirm-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.finance-toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(1rem);
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--error);
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    max-width: 90vw;
    opacity: 0;
    transition:
        opacity 0.25s ease,
        transform 0.25s ease;
    z-index: 1100;
}
.finance-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.finance-toast-success {
    border-left-color: #22c55e;
}

.locked-row-badge {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--error);
}

.locked-notice {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid var(--error);
    color: var(--error);
    padding: 0.6rem 0.9rem;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

/* ---------------------------------------------------------------------- */
/* Period picker — finance-only element in the shared header's              */
/* #topbar-extra slot (moved there by js/shell-init.js).                    */
/* ---------------------------------------------------------------------- */
.period-control { position: relative; display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.period-control[hidden] { display: none; }
.period-select {
    height: 34px;
    padding: 0 0.6rem;
    background: var(--bg-input);
    color: var(--text-main);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}
.period-nav {
    display: flex;
    align-items: center;
    height: 34px;
    background: var(--bg-input);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    overflow: hidden;
}
.period-step, .period-label {
    height: 100%;
    background: none;
    border: none;
    color: var(--text-main);
    font: inherit;
    cursor: pointer;
}
.period-step { width: 30px; font-size: 1.1rem; color: var(--text-muted); }
.period-label { padding: 0 0.75rem; font-size: 0.85rem; font-weight: 600; white-space: nowrap; min-width: 7.5rem; }
.period-step:hover, .period-label:hover { background: var(--bg-panel-hover); color: var(--text-main); }
.period-select:focus-visible, .period-step:focus-visible, .period-label:focus-visible { outline: 2px solid var(--accent-purple); outline-offset: -2px; }
.period-control.is-custom .period-step { display: none; }
.period-popover {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 120;
    display: flex;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(8, 5, 16, 0.5);
}
.period-popover[hidden], .period-popover .field[hidden] { display: none; }
.period-popover .field { margin: 0; }

/* ---------------------------------------------------------------------- */
/* Overview                                                                */
/* ---------------------------------------------------------------------- */
.ov-hero { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.ov-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin-bottom: 1rem; }
.ov-tile {
    padding: 1.1rem 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    min-width: 0;
}
.ov-hero .ov-tile { border-top: 3px solid var(--border-strong); }
.ov-tile--income { border-top-color: var(--success) !important; }
.ov-tile--expenses { border-top-color: var(--accent-purple) !important; }
.ov-tile--balance { border-top-color: var(--accent-blue) !important; }
.ov-eyebrow { color: var(--text-muted); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; margin: 0 0 0.45rem; }
.ov-value { font-size: 1.9rem; font-weight: 700; line-height: 1.15; margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ov-grid .ov-value { font-size: 1.6rem; }
.ov-value--md { font-size: 1.3rem !important; }
.ov-value.is-positive { color: var(--success); }
.ov-value.is-negative { color: var(--error); }
.ov-sub { color: var(--text-muted); font-size: 0.8rem; margin: 0.35rem 0 0; }
.ov-split { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.ov-split-label { display: flex; align-items: center; gap: 0.4rem; color: var(--text-muted); font-size: 0.8rem; margin: 0 0 0.2rem; }
.ov-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.ov-dot--fixed { background: var(--accent-purple); }
.ov-dot--flexible { background: var(--accent-magenta); }
.ov-bar { height: 8px; border-radius: 4px; background: var(--accent-magenta); overflow: hidden; margin-top: 0.9rem; }
.ov-bar-fixed { height: 100%; background: var(--accent-purple); transition: width 0.3s ease; }
.ov-excluded { padding: 0.9rem 1.25rem; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); }
.ov-excluded .ov-eyebrow { margin-bottom: 0.6rem; }
.ov-excluded-items { display: flex; gap: 2rem; flex-wrap: wrap; }
.ov-excluded-items > div { display: flex; flex-direction: column; gap: 0.1rem; }
.ov-excluded-label { color: var(--text-muted); font-size: 0.8rem; }
.ov-excluded-value { color: var(--text-muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.is-loading .ov-value, .is-loading .ov-excluded-value { opacity: 0.45; }

@media (max-width: 900px) {
    .ov-hero { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .ov-grid { grid-template-columns: 1fr; }
    .ov-value { font-size: 1.6rem; }
    .period-control { flex: 1; }
    .period-nav { flex: 1; }
    .period-label { flex: 1; min-width: 0; }
    .period-popover { flex-direction: column; left: 0; right: 0; }
}

/* Hidden until the shell moves it into its main area (see js/shell-init.js). */
#amea-shell-content { display: none; }
