/* ── Reset & Base ── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-brand: #16a34a;
    --nav-h: 46px;
    --nav-bg: var(--color-brand);
    --color-bg: #f5f4f1;
    --color-surface: #ffffff;
    --color-border: #dddbd5;
    --color-border-strong: #b8b5ae;
    --color-text: #1a1917;
    --color-text-muted: #6b6862;
    --color-accent: var(--color-brand);
    --color-accent-bg: color-mix(in srgb, var(--color-brand), white 92%);
    --color-accent-hover: color-mix(in srgb, var(--color-brand), black 15%);
    --color-danger: #dc2626;
    --color-danger-bg: #fef2f2;
    --color-success: #16a34a;
    --color-warning-bg: #fffbeb;
    --color-warning: #92400e;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.10);
    font-size: 14px;
}

html,
body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* ── Typography ── */
h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

h2 {
    font-size: 1.05rem;
    font-weight: 600;
}

h3 {
    font-size: 0.9rem;
    font-weight: 600;
}

a {
    color: var(--color-accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ── Nav ── */
#main-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-h);
    background: var(--nav-bg);
    border-bottom: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.nav-left,
.nav-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-brand {
    font-weight: 800;
    font-size: 1.05rem;
    color: #ffffff;
    letter-spacing: -0.02em;
    text-decoration: none;
    margin-right: 8px;
}

.nav-brand:hover {
    text-decoration: none;
    color: rgba(255, 255, 255, 0.85);
}

.nav-link {
    padding: 5px 10px;
    border-radius: var(--radius-md);
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    text-decoration: none;
}

.nav-link.active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.18);
}

/* ── User Chip ── */
.user-chip-wrap {
    position: relative;
    margin-left: 4px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px 4px 4px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.12);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    color: #ffffff;
    transition: border-color 0.15s, background 0.15s;
}

.user-chip:hover {
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.2);
}

.user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.chevron {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 160px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    z-index: 200;
}

.user-dropdown[hidden] {
    display: none;
}

.dropdown-item {
    display: block;
    padding: 8px 14px;
    font-size: 0.85rem;
    color: var(--color-text);
    text-decoration: none;
    transition: background 0.1s;
}

.dropdown-item:hover {
    background: var(--color-bg);
    text-decoration: none;
}

.dropdown-item--danger {
    color: var(--color-danger);
}

.dropdown-item--danger:hover {
    background: var(--color-danger-bg);
}

.dropdown-divider {
    height: 1px;
    background: var(--color-border);
    margin: 2px 0;
}

/* ── Page Shell ── */
#page-content {
    margin-top: var(--nav-h);
    padding: 16px;
    height: calc(100vh - var(--nav-h));
    overflow: hidden;
}

/* ── Auth Page ── */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.auth-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 360px;
    padding: 28px 28px 24px;
}

.auth-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.02em;
}

.auth-subtitle {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    margin-bottom: 20px;
}

.auth-tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 20px;
    gap: 0;
}

.auth-tab {
    flex: 1;
    padding: 7px 0;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}

.auth-tab.active {
    color: var(--color-accent);
    border-bottom-color: var(--color-accent);
}

/* ── Forms ── */
.form-group {
    margin-bottom: 12px;
}

.form-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.form-input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
    font-family: inherit;
}

.form-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input::placeholder {
    color: #bbb;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 7px 14px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
    font-family: inherit;
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-bg);
    border-color: var(--color-border-strong);
}

.btn-danger {
    background: var(--color-surface);
    color: var(--color-danger);
    border-color: var(--color-border);
}

.btn-danger:hover:not(:disabled) {
    background: var(--color-danger-bg);
    border-color: var(--color-danger);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
    border-color: transparent;
    padding: 4px 8px;
}

.btn-ghost:hover:not(:disabled) {
    background: var(--color-bg);
    color: var(--color-text);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.78rem;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    padding: 5px 7px;
}

/* ── Alert ── */
.alert {
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    margin-bottom: 12px;
    border: 1px solid transparent;
    min-height: 34px;
    visibility: hidden;
}

.alert.is-visible {
    visibility: visible;
}

.alert-error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border-color: #fca5a5;
}

.alert-success {
    background: #f0fdf4;
    color: var(--color-success);
    border-color: #86efac;
}

.alert-warning {
    background: var(--color-warning-bg);
    color: var(--color-warning);
    border-color: #fcd34d;
}

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.page-title {
    font-size: 1rem;
    font-weight: 600;
}

/* ── Toolbar ── */
.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    margin-bottom: 10px;
}

.toolbar-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-right: 2px;
}

.toolbar-sep {
    width: 1px;
    height: 20px;
    background: var(--color-border);
    flex-shrink: 0;
}

.toolbar .form-input {
    width: auto;
    padding: 4px 8px;
    font-size: 0.82rem;
}

.toolbar-date {
    width: 130px;
}

.toolbar select.form-input {
    width: auto;
    min-width: 120px;
}

.dashboard-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 16px;
}

/* ── Table ── */
.table-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow-y: auto;
    flex: 1;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}

.data-table thead th {
    background: var(--color-bg);
    padding: 7px 10px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table thead th:hover {
    color: var(--color-text);
}

.data-table thead th.sort-asc::after {
    content: ' ↑';
    color: var(--color-accent);
}

.data-table thead th.sort-desc::after {
    content: ' ↓';
    color: var(--color-accent);
}

.data-table tbody tr {
    border-bottom: 1px solid var(--color-border);
    transition: background 0.1s;
}


.data-table tbody tr:hover {
    background: var(--color-bg);
}

.data-table td {
    padding: 7px 10px;
    vertical-align: middle;
}

.data-table .col-actions {
    width: 72px;
    text-align: right;
    white-space: nowrap;
}

.data-table .col-amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.data-table .col-date {
    white-space: nowrap;
    color: var(--color-text-muted);
}

.table-empty {
    text-align: center;
    padding: 28px;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

/* ── Modal ── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    padding: 16px;
}

.modal {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--color-border);
}

.modal-title {
    font-size: 0.95rem;
    font-weight: 600;
}

.modal-body {
    padding: 14px 16px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 16px 14px;
    border-top: 1px solid var(--color-border);
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    font-size: 1.1rem;
    line-height: 1;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
}

.modal-close:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

/* ── Category autocomplete ── */
.cat-wrap {
    position: relative;
}

.cat-wrap.is-selected .form-input {
    border-color: var(--color-brand);
    padding-right: 30px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2316a34a'%3E%3Cpath fill-rule='evenodd' d='M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z' clip-rule='evenodd' /%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 18px;
}

.cat-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 300;
    max-height: 180px;
    overflow-y: auto;
    font-size: 0.84rem;
}

.cat-option {
    padding: 6px 10px;
    cursor: pointer;
    transition: background 0.1s;
}

.cat-option:hover,
.cat-option.highlighted {
    background: var(--color-accent-bg);
    color: var(--color-accent);
}

.cat-option--empty {
    color: var(--color-text-muted);
    cursor: default;
}

/* ── Card (profile / generic) ── */
.card-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 24px;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.card-no-padding {
    padding: 0;
}

.card-danger {
    border: 1px solid #fee2e2;
}

.card-danger .card-title,
.card-danger .btn {
    color: #991b1b;
}

/* ── Pagination ── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    font-size: 0.85rem;
}

.pagination-info {
    color: var(--color-text-muted);
}

.pagination-controls {
    display: flex;
    gap: 8px;
}

/* ── Badge ── */
.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--color-bg);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
}

.badge-system {
    background: #f0fdf4;
    color: var(--color-success);
    border-color: #86efac;
}

/* ── Loading / Spinner ── */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-row td {
    text-align: center;
    padding: 24px;
    color: var(--color-text-muted);
}

/* ── Utilities ── */
.text-muted {
    color: var(--color-text-muted);
}

.text-danger {
    color: var(--color-danger);
}

.text-right {
    text-align: right;
}

.flex {
    display: flex;
}

.flex-center {
    display: flex;
    align-items: center;
}

.gap-8 {
    gap: 8px;
}

.mt-8 {
    margin-top: 8px;
}

.mt-12 {
    margin-top: 12px;
}

.mb-0 {
    margin-bottom: 0;
}

.w-full {
    width: 100%;
}

/* ── Confirm dialog ── */
.confirm-msg {
    font-size: 0.88rem;
    color: var(--color-text);
    line-height: 1.5;
}