/* ===========================================================================
   LedgerLite — component layer (dark, Tailus-style)
   Deep zinc surfaces, soft 1px borders, indigo primary, generous radius and
   subtle shadows. Shared component classes so every page reads as one system.
   =========================================================================== */

:root {
    --background: #09090b;
    --foreground: #f4f4f5;
    --muted-foreground: #a1a1aa;
    --muted-foreground-1: #71717a;
    --line: #26262b;
    --line-strong: #3f3f46;
    --card: #121215;
    --surface: #18181b;
    --surface-2: #1c1c20;
    --muted: #18181b;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-soft: rgba(99, 102, 241, 0.14);
    --income: #22c55e;
    --income-soft: rgba(34, 197, 94, 0.14);
    --expense: #f43f5e;
    --expense-soft: rgba(244, 63, 94, 0.14);
    --radius: 0.625rem;
    --radius-lg: 0.875rem;
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.4);
    --shadow: 0 4px 14px -4px rgba(0,0,0,0.5);
}

html { color-scheme: dark; }
html, body {
    background: var(--background);
    color: var(--foreground);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    font-size: 16px;
    line-height: 1.5;
}
a { color: inherit; }
::selection { background: var(--primary-soft); }

.amount, td.amount, .tabular { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* Scrollbars ----------------------------------------------------------- */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 9999px; border: 3px solid var(--background); }

/* Form controls -------------------------------------------------------- */
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], input[type="url"], select, textarea {
    box-sizing: border-box;
    width: 100%;
    height: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    line-height: 1.375rem;
    color: var(--foreground);
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color .12s, box-shadow .12s, background .12s;
}
/* A single-row select must never render as a multi-row list box. */
select:not([multiple]):not([size]) { min-height: 2.625rem; padding-left: 0.875rem; }

/* -------------------------------------------------------------------------
   Custom select (JS-enhanced) — replaces native <select> so the open menu
   matches the theme exactly. The native select is hidden but kept in the DOM.
   ------------------------------------------------------------------------- */
.cs-wrap { position: relative; width: 100%; }
.cs-native { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.cs-toggle {
    box-sizing: border-box;
    width: 100%; min-height: 2.625rem;
    display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 0.5rem 0.875rem; font-size: 0.875rem; line-height: 1.375rem; color: var(--foreground);
    text-align: left; cursor: pointer; transition: border-color .12s, box-shadow .12s, background .12s;
}
.cs-toggle:hover { border-color: var(--line-strong); }
.cs-toggle.is-open, .cs-toggle:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: var(--surface-2); }
.cs-toggle .cs-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-toggle .cs-value.is-placeholder { color: #52525b; }
.cs-toggle .cs-chevron { flex: 0 0 auto; color: var(--muted-foreground); transition: transform .15s ease; }
.cs-toggle.is-open .cs-chevron { transform: rotate(180deg); }

.cs-menu {
    position: fixed; z-index: 60; box-sizing: border-box;
    padding: 0.3125rem; background: #151518;
    border: 1px solid var(--line-strong); border-radius: 0.625rem;
    box-shadow: 0 12px 32px -8px rgba(0,0,0,0.7); overflow-y: auto; max-height: 18rem;
}
.cs-group { padding: 0.5rem 0.625rem 0.25rem; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted-foreground-1); }
.cs-option {
    box-sizing: border-box; width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
    text-align: left; padding: 0.5rem 0.625rem; font-size: 0.875rem; color: #d4d4d8;
    background: transparent; border: 0; border-radius: 0.375rem; cursor: pointer;
}
.cs-option:hover, .cs-option.is-active { background: #1f1f23; color: #f4f4f5; }
.cs-option.is-selected { color: #a5b4fc; }
.cs-option .cs-check { flex: 0 0 auto; opacity: 0; }
.cs-option.is-selected .cs-check { opacity: 1; }
input::placeholder, textarea::placeholder { color: #52525b; }
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
    background: var(--surface-2);
}
input[type="date"] { color-scheme: dark; }
/* Native selects: custom chevron */
select {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    padding-right: 2.5rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 0.75rem center; background-size: 1rem 1rem;
}
select::-ms-expand { display: none; }
input[type="color"] {
    padding: 0.25rem; height: 2.75rem; width: 4rem; cursor: pointer;
    border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
input[type="file"] { padding: 0; font-size: 0.875rem; color: var(--muted-foreground); }
input[type="file"]::file-selector-button {
    background: var(--surface-2); border: 0; border-right: 1px solid var(--line);
    margin-right: 0.875rem; padding: 0.625rem 0.875rem; font-weight: 500; color: var(--foreground); cursor: pointer;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }
label { font-size: 0.875rem; font-weight: 500; color: #d4d4d8; display: inline-block; margin-bottom: 0.5rem; }
textarea {
    padding: 0.625rem 0.875rem;
    line-height: 1.55;
    min-height: 5.5rem;
    resize: vertical;
}

/* Buttons -------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--surface); color: #e4e4e7;
    padding: 0.625rem 1rem; font-size: 0.875rem; font-weight: 500;
    cursor: pointer; text-decoration: none; line-height: 1.25;
    transition: background .12s, border-color .12s, box-shadow .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn:focus { outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
.btn-primary {
    background: var(--primary); border-color: transparent; color: #fff;
    box-shadow: inset 0 1px 0 0 rgba(255,255,255,0.18), 0 1px 2px 0 rgba(0,0,0,0.4);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { border-color: rgba(244,63,94,0.4); color: #fb7185; background: transparent; }
.btn-danger:hover { background: var(--expense); border-color: var(--expense); color: #fff; }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.8125rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* Cards / panels ------------------------------------------------------- */
.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.panel-head {
    border-bottom: 1px solid var(--line);
    padding: 1rem 1.25rem;
    font-weight: 600; font-size: 1rem; color: var(--foreground);
}

/* Tables --------------------------------------------------------------- */
table.data { width: 100%; border-collapse: collapse; }
:where(table.data) thead th {
    background: var(--muted);
    color: var(--muted-foreground-1);
    font-weight: 500; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em;
    text-align: left; white-space: nowrap;
    padding: 0.75rem 1.5rem; border-bottom: 1px solid var(--line);
}
:where(table.data) tbody td {
    padding: 0.875rem 1.5rem; font-size: 0.875rem; color: var(--foreground);
    border-bottom: 1px solid var(--line); vertical-align: middle;
}
table.data tbody tr { transition: background .1s; }
table.data tbody tr:hover { background: rgba(255,255,255,0.02); }
table.data tbody tr:last-child td { border-bottom: none; }

/* Icon swatch ---------------------------------------------------------- */
.swatch {
    display: inline-flex; align-items: center; justify-content: center;
    width: 2rem; height: 2rem; border: 1px solid var(--line); border-radius: var(--radius);
    overflow: hidden; flex: 0 0 auto;
}
.swatch img { width: 100%; height: 100%; object-fit: cover; display: block; }
.swatch .initial { font-size: 0.8rem; font-weight: 700; color: #fff; }

/* Badges --------------------------------------------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: 0.25rem;
    border-radius: 9999px; padding: 0.1875rem 0.625rem;
    font-size: 0.75rem; font-weight: 500; color: #d4d4d8; background: var(--surface);
    border: 1px solid var(--line);
}
.badge-income  { color: #4ade80; background: var(--income-soft); border-color: rgba(34,197,94,0.3); }
.badge-expense { color: #fb7185; background: var(--expense-soft); border-color: rgba(244,63,94,0.3); }
.text-income  { color: var(--income); }
.text-expense { color: var(--expense); }

/* Misc ----------------------------------------------------------------- */
.field-error { color: #fb7185; font-size: 0.8rem; margin-top: 0.375rem; }
.page-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; color: var(--foreground); }
.text-muted { color: var(--muted-foreground); }
.divider { height: 1px; background: var(--line); border: 0; }

/* Dropdown / collapse (vanilla JS-driven) ------------------------------ */
[data-dd-toggle] .dd-chevron { transition: transform .15s ease; }
[data-dd-toggle].dd-open .dd-chevron { transform: rotate(180deg); }
[data-collapse-toggle] .icon-close { display: none; }
[data-collapse-toggle].is-open .icon-open { display: none; }
[data-collapse-toggle].is-open .icon-close { display: inline-block; }
