/* MVM Finance — Mobile-first Design System */

:root {
    --primary: #2c3e50;
    --accent: #3498db;
    --success: #27ae60;
    --danger: #e74c3c;
    --warning: #f39c12;
    --bg: #f8f9fa;
    --surface: #ffffff;
    --text: #2c3e50;
    --text-muted: #7f8c8d;
    --border: #dee2e6;
    --radius-sm: 6px;
    --radius-md: 12px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,.1);
    --nav-height: 64px;
}

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

html { font-size: 16px; height: 100%; -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    overscroll-behavior-y: contain;
    -webkit-tap-highlight-color: transparent;
}

/* --- Layout --- */
.page {
    padding: 16px 16px calc(var(--nav-height) + 24px + env(safe-area-inset-bottom, 0px));
    max-width: 600px;
    margin: 0 auto;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

h1 { font-size: clamp(1.3rem, 4vw, 1.6rem); font-weight: 600; }
h2 { font-size: clamp(1rem, 3.5vw, 1.2rem); font-weight: 600; margin: 16px 0 8px; color: var(--text-muted); }

/* --- Bottom Nav --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
    height: var(--nav-height);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.65rem;
    min-width: 56px;
    min-height: 44px;
    transition: color 0.15s;
}
.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 1.3rem; margin-bottom: 2px; }

.fab-item { position: relative; }
.fab-icon {
    background: var(--accent);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    margin-top: -18px;
    box-shadow: var(--shadow-md);
    transition: transform 0.15s;
}
.fab-item:active .fab-icon { transform: scale(0.92); }

/* --- Cards --- */
.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: 10px 18px;
    min-height: 44px;
    text-decoration: none;
    transition: opacity 0.15s;
    touch-action: manipulation;
}
.btn:active { opacity: 0.85; }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; min-height: 36px; }
.btn-full { width: 100%; }
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 1.1rem;
}
.btn[disabled] { opacity: 0.4; pointer-events: none; }

/* --- Forms --- */
.form-card { background: var(--surface); border-radius: var(--radius-md); padding: 20px 16px; box-shadow: var(--shadow-sm); }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 4px; color: var(--text-muted); }
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group input[type="file"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    min-height: 44px;
    background: var(--surface);
    color: var(--text);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: 2px solid var(--accent);
    border-color: transparent;
}
.field-error { color: var(--danger); font-size: 0.8rem; margin-top: 2px; display: block; }
.help-text { color: var(--text-muted); font-size: 0.8rem; display: block; margin-top: 2px; }

/* --- Messages --- */
.messages { list-style: none; margin-bottom: 16px; }
.messages li { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 8px; font-size: 0.9rem; }
.messages .success { background: #d4edda; color: #155724; }
.messages .error { background: #fde8e8; color: var(--danger); }
.messages .info { background: #d1ecf1; color: #0c5460; }
.error-message { background: #fde8e8; color: var(--danger); padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 0.9rem; }

/* --- Text utilities --- */
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-muted { color: var(--text-muted); }
.muted { color: var(--text-muted); }
.negative { color: var(--danger); }
.empty-state { color: var(--text-muted); text-align: center; padding: 24px 16px; font-size: 0.95rem; }

/* --- Login --- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 16px; }
.login-card { background: var(--surface); padding: 32px 24px; border-radius: var(--radius-md); box-shadow: var(--shadow-md); width: 100%; max-width: 360px; text-align: center; }
.login-card h1 { font-size: 2rem; color: var(--primary); margin-bottom: 4px; }
.login-card .subtitle { color: var(--text-muted); margin-bottom: 24px; }

/* --- Account tree --- */
.account-type-section { margin-bottom: 20px; }
.type-header { text-transform: capitalize; }
.account-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    min-height: 44px;
}
.account-name { text-decoration: none; color: var(--text); font-weight: 500; flex: 1; }
.parent-name { color: var(--text-muted); font-weight: 400; }
.account-balance { font-variant-numeric: tabular-nums; white-space: nowrap; margin-left: 12px; font-size: 0.9rem; }

/* --- Account detail --- */
.balance-header { text-align: center; }
.balance-main { font-size: 1.5rem; font-weight: 600; margin-bottom: 4px; }
.balance-detail { font-size: 0.85rem; display: flex; justify-content: center; gap: 16px; }

/* --- Transaction list --- */
.date-group { margin-bottom: 8px; }
.date-header { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); padding: 8px 0 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.transaction-row {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}
.txn-info { flex: 1; min-width: 0; }
.txn-counterparty { font-weight: 500; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-desc { font-size: 0.8rem; color: var(--text-muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-amount { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 500; font-size: 0.9rem; }
.txn-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* --- Tags --- */
.tag-chip {
    display: inline-flex;
    align-items: center;
    background: #e8f0fe;
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    margin: 2px 2px 0 0;
}
.tag-remove { background: none; border: none; color: var(--text-muted); cursor: pointer; margin-left: 4px; font-size: 0.8rem; }

/* --- Bills --- */
.bill-section { margin-bottom: 20px; }
.overdue-section h2 { color: var(--danger); }
.bill-card {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 8px;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.overdue-card { border-left: 4px solid var(--danger); }
.bill-info { flex: 1; min-width: 0; }
.bill-name { font-weight: 500; display: block; }
.bill-amount { font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.bill-due { font-size: 0.8rem; display: block; }
.bill-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

/* --- Budget --- */
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-label { font-weight: 600; min-width: 80px; text-align: center; }
.income-expense-card { text-align: center; }
.ie-row { display: flex; justify-content: center; gap: 16px; font-size: 0.9rem; margin-bottom: 4px; }
.ie-net { font-size: 1.1rem; font-weight: 600; }
.top-expenses { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.top-expense-row { display: flex; justify-content: space-between; font-size: 0.85rem; padding: 2px 0; }

.budget-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.budget-row.compact { padding: 6px 0; }
.budget-info { display: flex; justify-content: space-between; margin-bottom: 4px; }
.budget-name { font-weight: 500; }
.budget-amounts { font-size: 0.85rem; font-variant-numeric: tabular-nums; color: var(--text-muted); }
.badge-recurring { background: #e8f0fe; color: var(--accent); font-size: 0.65rem; padding: 1px 6px; border-radius: 8px; margin-left: 4px; }

.progress-bar-container {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s;
}
.progress-bar.over-budget { background: var(--danger); }

/* --- Dashboard sections --- */
.dashboard-section { margin-bottom: 20px; }
.section-title { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.pinned-account-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    text-decoration: none;
    color: var(--text);
    box-shadow: var(--shadow-sm);
    min-height: 44px;
    align-items: center;
}

/* --- Search --- */
.search-form {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.search-form input[type="text"] {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    min-height: 44px;
}
.results-count { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 8px; }

/* --- Filters --- */
.filter-panel { margin-bottom: 16px; }
.filter-panel summary { cursor: pointer; color: var(--accent); font-size: 0.9rem; padding: 8px 0; }
.filter-form { display: flex; flex-direction: column; gap: 8px; padding: 8px 0; }
.filter-row { display: flex; gap: 8px; }
.filter-row input, .filter-row select { flex: 1; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.9rem; min-height: 40px; }

/* --- Archive --- */
.archive-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }

/* --- Settings --- */
.settings-links { display: flex; flex-direction: column; gap: 0; margin-top: 16px; }
.settings-link { display: block; padding: 14px 16px; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--accent); font-size: 0.95rem; min-height: 44px; }

/* --- Wizard --- */
.wizard-progress { display: flex; gap: 8px; justify-content: center; margin-bottom: 20px; }
.wizard-progress .step {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--border); color: var(--text-muted); font-weight: 600; font-size: 0.85rem;
}
.wizard-progress .step.active { background: var(--accent); color: white; }
.wizard-row { display: flex; gap: 8px; margin-bottom: 8px; }
.wizard-row input, .wizard-row select { flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.9rem; min-height: 44px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; font-size: 0.95rem; min-height: 44px; }
.checkbox-row input[type="checkbox"] { width: 20px; height: 20px; }

/* --- Amount Input widget --- */
.amount-input { position: relative; }
.amount-display {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1.3rem;
    font-weight: 600;
    text-align: right;
    font-variant-numeric: tabular-nums;
    min-height: 52px;
    background: var(--surface);
    color: var(--text);
    caret-color: transparent;
}
.amount-display:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* --- Date Navigator widget --- */
.date-nav { margin-bottom: 4px; }
.date-nav-row { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: center; }
.date-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    font-size: 0.75rem;
    min-height: 36px;
    min-width: 36px;
    cursor: pointer;
    touch-action: manipulation;
    color: var(--text);
}
.date-btn:active { background: var(--bg); }
.date-display {
    background: none;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 0.9rem;
    font-weight: 600;
    min-height: 36px;
    color: var(--accent);
    cursor: pointer;
}
.date-picker-hidden { position: absolute; opacity: 0; width: 0; height: 0; }
.date-today-btn {
    display: block;
    margin: 6px auto 0;
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.85rem;
}

/* --- Account Picker widget --- */
.account-picker { position: relative; }
.picker-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    min-height: 44px;
}
.picker-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.picker-selected {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    background: #e8f0fe;
    min-height: 44px;
    cursor: pointer;
}
.picker-clear { background: none; border: none; font-size: 1.2rem; color: var(--text-muted); cursor: pointer; padding: 0 4px; }
.picker-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 240px;
    overflow-y: auto;
    z-index: 50;
}
.picker-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 0.9rem;
    min-height: 40px;
    display: flex;
    align-items: center;
}
.picker-item:hover, .picker-item:active { background: var(--bg); }
.picker-create { color: var(--accent); font-style: italic; }
.picker-empty { padding: 10px 12px; color: var(--text-muted); font-size: 0.85rem; }

/* --- Tag Input widget --- */
.tag-input { position: relative; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.tag-text-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    min-height: 40px;
}
.tag-suggestions {
    position: absolute;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 160px;
    overflow-y: auto;
    z-index: 50;
}
.tag-suggestion-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.85rem;
}
.tag-suggestion-item:hover { background: var(--bg); }

/* --- Liability detail --- */
.detail-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 0.9rem; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: none; }

/* --- Amortization table --- */
.amortization-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.amortization-table th { text-align: left; padding: 6px 8px; border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; }
.amortization-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); }
.amortization-table .holiday-row { background: #fff3cd; }

/* --- Bill splits --- */
.split-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.split-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.split-account { font-weight: 500; }
.split-amount-display { font-variant-numeric: tabular-nums; font-size: 0.95rem; }
.split-total { font-weight: 600; font-size: 1.1rem; text-align: right; padding: 12px 0; border-top: 2px solid var(--border); margin-top: 8px; }
.badge-fixed { background: var(--border); color: var(--text-muted); font-size: 0.65rem; padding: 1px 6px; border-radius: 8px; }
.badge-variable { background: #e8f0fe; color: var(--accent); font-size: 0.65rem; padding: 1px 6px; border-radius: 8px; }

/* --- Bill splits form --- */
.splits-section { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.splits-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.splits-header h2 { margin: 0; }
.split-form-row { padding: 12px; margin-bottom: 8px; background: var(--bg); border-radius: var(--radius-sm); }
.split-row-fields { display: flex; gap: 8px; align-items: flex-end; }

/* --- Bill drag-and-drop --- */
.drag-handle { cursor: grab; padding: 0 8px 0 0; color: var(--text-muted); font-size: 1.2rem; display: flex; align-items: center; touch-action: none; }
.drag-handle:active { cursor: grabbing; }
.bill-card.dragging { opacity: 0.8; box-shadow: var(--shadow-md); }
.bill-card-placeholder { border: 2px dashed var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; }

/* --- Inactive bills --- */
.inactive-section { margin-top: 16px; }
.inactive-toggle { cursor: pointer; color: var(--text-muted); font-size: 0.9rem; padding: 8px 0; }
.inactive-card { opacity: 0.6; }

/* --- Budget inline edit --- */
.budget-edit-form { padding: 12px 0 4px; }
.budget-edit-row { margin-bottom: 8px; }
.budget-edit-label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; }
.budget-edit-recurring { margin: 8px 0; }
.budget-edit-buttons { display: flex; gap: 6px; margin-top: 8px; }
.budget-over-label { font-size: 0.75rem; margin-top: 2px; }

/* --- Wizard improvements --- */
.wizard-bill-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.wizard-bill-row:last-child { border-bottom: none; }

/* --- Banking / Imports --- */
.bank-account-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); margin-top: 8px; gap: 8px; flex-wrap: wrap; }
.bank-account-info { flex: 1; min-width: 0; }
.bank-account-info span { display: block; }
.bank-account-actions { display: flex; gap: 4px; flex-shrink: 0; flex-wrap: wrap; }
.import-card { padding: 10px 14px; }
.import-card.matched { opacity: 0.6; }
.import-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.import-info { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: center; }
.import-date { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }
.import-desc { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-amount { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 500; }
.import-actions { display: flex; gap: 4px; margin-top: 6px; }

/* --- Standalone PWA tweaks --- */
@media (display-mode: standalone) {
    .page { padding-top: calc(env(safe-area-inset-top, 0px) + 16px); }
    .bottom-nav { padding-bottom: env(safe-area-inset-bottom, 0px); }
}

/* --- Pull-to-refresh prevention in standalone --- */
body { overscroll-behavior-y: contain; }

/* --- Smooth scrolling --- */
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

/* --- Focus styles for keyboard nav --- */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --- Active states for touch feedback --- */
.btn:active, .nav-item:active, .bill-card:active, .pinned-account-row:active {
    transform: scale(0.98);
}

/* --- Select styling --- */
select {
    appearance: none;
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%237f8c8d' stroke-width='2'/%3E%3C/svg%3E") right 12px center / 12px no-repeat;
    padding-right: 36px;
}

/* --- Desktop widening --- */
@media (min-width: 768px) {
    .page { max-width: 720px; padding-left: 24px; padding-right: 24px; }
    .bill-card { padding: 14px 18px; }
    .budget-row { padding: 12px 0; }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
