/* ============ DESIGN SYSTEM ============ */
:root {
    --bg: #f4efe6;
    --surface: #fefcf7;
    --surface-alt: #ebe5d6;
    --border: #e0d9c6;
    --ink: #1c1f1a;
    --ink-soft: #3a3d36;
    --muted: #7a756a;
    --forest: #2f4a3e;
    --forest-light: #4a6e5e;
    --sage: #6b8472;
    --amber: #b87833;
    --rust: #9c4f3a;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}

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

html, body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--forest);
    text-decoration: none;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
}

/* ============ LAYOUT ============ */
.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 8rem;
    position: relative;
    min-height: 100vh;
}

/* ============ HEADER ============ */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.75rem;
    padding-top: 0.5rem;
}

.app-header h1 {
    font-family: var(--serif);
    font-size: 1.5rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    text-transform: capitalize;
}

.eyebrow {
    font-size: 0.72rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.3rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.icon-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.55rem;
    color: var(--ink-soft);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.icon-btn:hover {
    background: var(--surface-alt);
}

.lang-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.4rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--ink-soft);
    display: inline-flex;
    gap: 0.25rem;
    align-items: center;
}

.lang-toggle .active {
    color: var(--forest);
}

.lang-toggle .sep {
    color: var(--muted);
    opacity: 0.4;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--ink-soft);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
}

/* ============ CARDS ============ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 1.75rem 1.5rem;
    margin-bottom: 0.85rem;
}

.card-sm {
    padding: 1.1rem 1rem;
    border-radius: 14px;
}

.hero-amount {
    font-family: var(--serif);
    font-size: 3.2rem;
    line-height: 1;
    font-weight: 500;
    letter-spacing: -0.03em;
    color: var(--forest);
}

.hero-amount.warn { color: var(--amber); }
.hero-amount.over { color: var(--rust); }

.hero-sub {
    margin-top: 0.65rem;
    font-size: 0.85rem;
    color: var(--muted);
}

.hero-sub.over { color: var(--rust); }

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.1rem 1rem;
}

.stat-label {
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.stat-amount {
    font-family: var(--serif);
    font-size: 1.5rem;
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.stat-amount.warn { color: var(--amber); }
.stat-amount.over { color: var(--rust); }
.stat-amount.good { color: var(--forest); }

.stat-sub {
    font-size: 0.74rem;
    color: var(--muted);
    margin-top: 0.4rem;
}

/* ============ PROGRESS BAR ============ */
.progress-section {
    margin-bottom: 1.75rem;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.progress-track {
    height: 8px;
    background: var(--surface-alt);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--sage);
    border-radius: 999px;
    transition: width 0.4s ease;
}

.progress-fill.warn { background: var(--amber); }
.progress-fill.over { background: var(--rust); }

/* ============ SECTION HEADER ============ */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.85rem;
    margin-top: 1.25rem;
}

.section-title {
    font-family: var(--serif);
    font-size: 1.15rem;
    font-weight: 500;
}

.section-link {
    font-size: 0.85rem;
    color: var(--forest);
    font-weight: 500;
}

.section-icon-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--ink-soft);
    font-weight: 500;
    font-size: 0.92rem;
}

/* ============ EXPENSE LIST ============ */
.expense-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
}

.expense-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
}

.expense-row:last-child {
    border-bottom: none;
}

.expense-info {
    flex: 1;
    min-width: 0;
}

.expense-category {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.expense-note {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.15rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.expense-right {
    text-align: right;
    margin-left: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.expense-amount {
    font-family: var(--serif);
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--ink);
}

.expense-date {
    font-size: 0.72rem;
    color: var(--muted);
}

.expense-source-badge {
    display: inline-block;
    font-size: 0.62rem;
    padding: 0.1rem 0.4rem;
    background: var(--surface-alt);
    color: var(--muted);
    border-radius: 999px;
    margin-left: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Click-to-expand for expense cards */
.expense-card {
    border-bottom: 1px solid var(--border);
    position: relative;
}
.expense-card:last-child {
    border-bottom: none;
}
.expense-card .expense-row {
    border-bottom: none;
}
.expense-info-clickable {
    cursor: pointer;
    flex: 1;
    min-width: 0;
    display: block;
    transition: background 0.12s;
    margin: -0.85rem -0.25rem -0.85rem -1rem;
    padding: 0.85rem 0.25rem 0.85rem 1rem;
}
.expense-info-clickable:hover {
    background: var(--surface-alt);
}
.expand-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--muted);
    padding: 0.3rem;
    transition: transform 0.2s ease, color 0.15s;
    border-radius: 4px;
}
.expand-chevron:hover {
    color: var(--ink-soft);
    background: var(--surface-alt);
}
.expense-card .expense-detail {
    display: none;
    padding: 0.85rem 1rem 1rem;
    background: var(--bg);
    border-top: 1px solid var(--border);
}
.expense-toggle:checked ~ .expense-detail {
    display: block;
}
.expense-toggle:checked ~ .expense-row .expand-chevron {
    transform: rotate(180deg);
    color: var(--forest);
}

.date-header {
    padding: 0.6rem 1rem;
    background: var(--surface-alt);
    font-size: 0.78rem;
    color: var(--ink-soft);
    font-weight: 500;
    text-transform: capitalize;
}

.empty-state {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 14px;
    padding: 2rem 1.5rem;
    text-align: center;
    color: var(--muted);
    font-family: var(--serif);
    font-style: italic;
    font-size: 0.95rem;
}

/* ============ FAB ============ */
.fab {
    position: fixed;
    bottom: 5.5rem;
    right: 1.25rem;
    width: 60px;
    height: 60px;
    background: var(--forest);
    color: var(--surface);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(47, 74, 62, 0.35);
    transition: transform 0.15s;
    z-index: 40;
}

.fab:hover { transform: scale(1.05); }
.fab:active { transform: scale(0.95); }

@media (min-width: 520px) {
    .fab {
        right: calc(50% - 240px + 1.25rem);
    }
}

/* ============ BOTTOM NAV ============ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 0.5rem 0 calc(0.5rem + env(safe-area-inset-bottom));
    z-index: 30;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.5rem;
    color: var(--muted);
    font-size: 0.7rem;
    text-decoration: none;
    transition: color 0.15s;
}

.nav-item.active {
    color: var(--forest);
}

.nav-item svg {
    width: 22px;
    height: 22px;
}

/* ============ FORMS ============ */
.form-section {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-size: 0.74rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.form-input,
.form-select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.7rem 0.9rem;
    font-size: 0.95rem;
    color: var(--ink);
    outline: none;
    transition: border-color 0.15s;
}

.form-input:focus,
.form-select:focus {
    border-color: var(--forest);
}

.form-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.form-row .form-input { flex: 1; }

.form-amount {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.55rem 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 130px;
}

.form-amount .currency {
    color: var(--muted);
    font-family: var(--serif);
}

.form-amount input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: var(--serif);
    font-size: 1rem;
    text-align: right;
    min-width: 0;
}

.btn {
    background: var(--forest);
    color: var(--surface);
    border: none;
    border-radius: 12px;
    padding: 0.85rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: background 0.15s;
}

.btn:hover { background: var(--forest-light); }

.btn:disabled {
    background: var(--surface-alt);
    color: var(--muted);
    cursor: not-allowed;
}

.btn-block {
    width: 100%;
}

.btn-ghost {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--ink-soft);
}

.btn-ghost:hover {
    background: var(--surface-alt);
}

.btn-small {
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
    border-radius: 999px;
}

.btn-danger-text {
    color: var(--muted);
    padding: 0.4rem;
}

.btn-danger-text:hover {
    color: var(--rust);
}

/* ============ ITEM LIST (settings) ============ */
.item-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.55rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.item-name {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 0.95rem;
    min-width: 0;
}

.item-amount {
    font-family: var(--serif);
    color: var(--ink);
    font-size: 1rem;
}

.item-freq-pill {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    background: var(--surface-alt);
    border-radius: 999px;
    color: var(--muted);
    text-transform: lowercase;
}

/* Inline edit for income/cost items */
.editable-item .item-row-edit {
    display: none;
}
.editable-item .edit-toggle:checked ~ .item-row-view {
    display: none;
}
.editable-item .edit-toggle:checked ~ .item-row-edit {
    display: flex;
    background: var(--surface);
    border-radius: 10px;
    margin: 0.15rem 0;
}

/* Stacked edit form for income (with day_of_month field) */
.editable-item .edit-form-stacked {
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    background: var(--surface);
    border-radius: 10px;
    margin: 0.15rem 0;
}
.editable-item .edit-toggle:checked ~ .edit-form-stacked {
    display: flex;
}
.edit-form-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.edit-form-actions {
    margin-top: 0.3rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}
.btn-icon.edit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--muted);
    padding: 0.35rem;
    cursor: pointer;
    border-radius: 6px;
    transition: color 0.12s, background 0.12s;
}
.btn-icon.edit-btn:hover {
    color: var(--forest);
    background: var(--surface-alt);
}

/* ============ HIGHLIGHTED SUMMARY CARD ============ */
.summary-card {
    background: var(--forest);
    color: var(--surface);
    border-radius: 16px;
    padding: 1.4rem 1.25rem;
    margin-bottom: 1.5rem;
}

.summary-card .eyebrow {
    color: rgba(254, 252, 247, 0.7);
}

.summary-card .hero-amount {
    color: var(--surface);
}

.summary-card .breakdown {
    font-size: 0.82rem;
    opacity: 0.8;
    margin-top: 0.65rem;
    line-height: 1.7;
}

/* ============ FLASH MESSAGES ============ */
.flash {
    padding: 0.75rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.flash.success {
    background: rgba(107, 132, 114, 0.15);
    color: var(--forest);
    border: 1px solid rgba(107, 132, 114, 0.3);
}

.flash.error {
    background: rgba(156, 79, 58, 0.1);
    color: var(--rust);
    border: 1px solid rgba(156, 79, 58, 0.25);
}

/* ============ IMPORT REVIEW TABLE ============ */
.import-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.import-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    align-items: center;
}

.import-row:last-child { border-bottom: none; }

.import-checkbox {
    width: 20px;
    height: 20px;
    accent-color: var(--forest);
}

.import-desc {
    font-size: 0.9rem;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.import-date {
    font-size: 0.74rem;
    color: var(--muted);
    margin-top: 0.15rem;
}

.import-amount {
    font-family: var(--serif);
    font-weight: 500;
    text-align: right;
    color: var(--ink);
}

.import-category-input {
    margin-top: 0.35rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.3rem 0.5rem;
    font-size: 0.78rem;
    color: var(--ink);
    outline: none;
    width: 100%;
}

/* ============ TAGS / CATEGORY PILLS ============ */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
}

.tag {
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    background: var(--surface-alt);
    color: var(--ink-soft);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
}

.tag.active,
.tag:hover {
    background: var(--forest);
    color: var(--surface);
}

/* ============ REPORTS LIST ============ */
.report-list-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
    transition: background 0.15s;
}

.report-list-item:hover {
    background: var(--surface-alt);
}

.report-list-item-title {
    font-family: var(--serif);
    font-size: 1.1rem;
    color: var(--ink);
}

/* ============ PRINTABLE REPORT ============ */
.report-page {
    max-width: 720px;
    margin: 2rem auto;
    padding: 2.5rem;
    background: var(--surface);
    color: var(--ink);
}

.report-page h1 {
    font-family: var(--serif);
    font-size: 2.4rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
}

.report-page h2 {
    font-family: var(--serif);
    font-size: 1.5rem;
    font-weight: 500;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.report-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1.5rem;
}

.report-summary-item {
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.report-summary-item .eyebrow {
    margin-bottom: 0.3rem;
}

.report-summary-item .amount {
    font-family: var(--serif);
    font-size: 1.6rem;
    font-weight: 500;
}

.report-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
}

.report-table th,
.report-table td {
    text-align: left;
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}

.report-table th {
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
}

.report-table td.amount {
    text-align: right;
    font-family: var(--serif);
    font-weight: 500;
    white-space: nowrap;
}

.report-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
}

.report-bar-label {
    flex: 0 0 130px;
    font-size: 0.9rem;
}

.report-bar-track {
    flex: 1;
    height: 8px;
    background: var(--surface-alt);
    border-radius: 999px;
    overflow: hidden;
}

.report-bar-fill {
    height: 100%;
    background: var(--forest);
}

.report-bar-amount {
    flex: 0 0 90px;
    text-align: right;
    font-family: var(--serif);
    font-weight: 500;
}

.print-button {
    text-align: center;
    margin: 1.5rem 0 2rem;
}

@media print {
    body { background: white; }
    .report-page { box-shadow: none; margin: 0; padding: 1rem; }
    .print-button, .app-header, .bottom-nav, .fab, .back-link { display: none !important; }
}

/* ============ UTILITY ============ */
.muted { color: var(--muted); }
.serif { font-family: var(--serif); }
.italic { font-style: italic; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-2 { margin-top: 0.5rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.text-center { text-align: center; }
