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

:root {
    --bg: #0f0f23;
    --surface: #1a1a2e;
    --surface-hover: #252542;
    --border: #2e2e4a;
    --text: #e0e0e0;
    --text-dim: #a0a0b0;
    --accent: #4ecdc4;
    --accent-dark: #3db8b0;
    --danger: #ff6b6b;
    --danger-dark: #e85a5a;
    --success: #6bcb77;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overscroll-behavior-y: none;
}

#app { max-width: 600px; margin: 0 auto; padding: 16px; }

header {
    text-align: center;
    padding: 16px 0 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

header h1 { font-size: 1.4rem; margin-bottom: 4px; }

.rates {
    display: flex;
    justify-content: center;
    gap: 16px;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.rates span span { color: var(--accent); font-weight: 600; }
.rates-hint {
    font-size: 0.7rem;
    color: var(--text-dim);
    opacity: 0.7;
    margin-left: 2px;
    cursor: pointer;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
    flex: 0 0 auto;
    min-width: 56px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab-btn.active {
    background: var(--surface);
    color: var(--accent);
    font-weight: 600;
}

.tab-btn:active { background: var(--surface-hover); }

/* Panels */
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.hidden { display: none !important; }

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.card h2, .card-header h2 {
    font-size: 1rem;
    color: var(--accent);
}

/* Week Selector */
.week-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.week-selector button {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.week-selector button:active { background: var(--surface-hover); }

#week-label { font-size: 0.95rem; font-weight: 500; }

/* Day Cells */
.days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.day-cell {
    text-align: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 1px;
    overflow: hidden;
}

.day-cell label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-bottom: 2px;
    text-transform: uppercase;
    font-weight: 600;
}

.day-total {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
    margin-bottom: 2px;
}

.day-sub {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1px;
    font-size: 0.7rem;
    color: var(--text-dim);
}

.day-sub input {
    width: 28px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 0;
    color: var(--text);
    text-align: center;
    font-size: 0.75rem;
    -moz-appearance: textfield;
}

.day-sub input::-webkit-outer-spin-button,
.day-sub input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.day-sub input:focus { outline: none; border-color: var(--accent); }

.day-auto {
    min-width: 14px;
    color: var(--text-dim);
}

.total-miles {
    text-align: center;
    margin-top: 12px;
    font-size: 0.9rem;
    color: var(--text-dim);
}

.total-miles strong { color: var(--accent); font-size: 1.1rem; }

/* Auto-save status */
.save-status {
    font-size: 0.75rem;
    color: var(--text-dim);
    opacity: 0;
    transition: opacity 0.3s;
}
.save-status.show { opacity: 1; color: var(--success); }

/* Form Rows */
.form-row { margin-bottom: 12px; }
.form-row:last-child { margin-bottom: 0; }

.form-row label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.form-row input, .form-row select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    color: var(--text);
    font-size: 1rem;
}

.form-row input:focus, .form-row select:focus { outline: none; border-color: var(--accent); }

/* Calculated Card */
.calc-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.calc-row:last-child { border-bottom: none; }
.calc-row span { color: var(--text-dim); }
.calc-row strong { color: var(--text); }
.calc-row.highlight strong { color: var(--success); font-size: 1.1rem; }

/* Divider between current-week and cumulative */
.calc-divider {
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--border), transparent);
    margin: 8px 0;
}

/* Prominent balance row */
.calc-row.balance {
    background: rgba(78, 205, 196, 0.08);
    padding: 14px 12px;
    margin: 0 -12px;
    border-radius: 8px;
    border: 1px solid rgba(78, 205, 196, 0.25);
}
.calc-row.balance span {
    color: var(--accent);
    font-weight: 500;
    font-size: 0.95rem;
}
.calc-row.balance span small {
    display: block;
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 2px;
    opacity: 0.85;
}
.calc-row.balance strong {
    color: var(--accent);
    font-size: 1.15rem;
}

/* Buttons */
.actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    padding-bottom: 20px;
}

.btn-primary, .btn-secondary, .btn-danger {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: #000;
}
.btn-primary:active { background: var(--accent-dark); }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:active { background: var(--surface-hover); }

.btn-danger {
    background: var(--danger);
    color: #fff;
    width: 100%;
    margin-top: 12px;
}
.btn-danger:active { background: var(--danger-dark); }

/* Pulse animation */
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(78, 205, 196, 0.4); }
    70% { box-shadow: 0 0 0 12px rgba(78, 205, 196, 0); }
    100% { box-shadow: 0 0 0 0 rgba(78, 205, 196, 0); }
}
.pulse-btn { animation: pulse 2s infinite; }

/* Trip Tracker */
.trip-instruction {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 16px;
    line-height: 1.5;
}

.live-stats {
    display: flex;
    justify-content: space-around;
    text-align: center;
    margin: 20px 0;
}

.live-stat label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.live-stat span {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
}

.wake-status {
    text-align: center;
    font-size: 0.8rem;
    color: var(--success);
    margin-bottom: 12px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-backdrop {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    width: 90%;
    max-width: 400px;
    z-index: 1001;
}

.modal-content h3 {
    text-align: center;
    margin-bottom: 16px;
    color: var(--accent);
}

.modal-result {
    text-align: center;
    margin-bottom: 20px;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
}

.modal-result p { margin: 6px 0; }
.modal-result strong { color: var(--accent); }

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

/* Trips list */
.trips-list, .codes-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.trip-item, .code-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.trip-item div:first-child, .code-item div:first-child { flex: 1; }

.trip-item small, .code-item small {
    display: block;
    color: var(--text-dim);
    margin-top: 2px;
    font-size: 0.75rem;
}

.trip-item strong, .code-item strong {
    color: var(--text);
    font-size: 0.9rem;
}

/* Codes */
.code-value {
    font-family: monospace;
    background: var(--surface);
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--accent);
    font-weight: 600;
    font-size: 1rem;
    margin-right: 8px;
}

.delete-btn {
    background: transparent;
    border: none;
    color: var(--danger);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 4px 8px;
}

/* Week List */
.weeks-list { display: flex; flex-direction: column; gap: 12px; }
.week-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.week-item:active { background: var(--surface-hover); }
.week-item small { color: var(--text-dim); }

/* YTD Grid */
.ytd-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.ytd-item {
    background: var(--bg);
    padding: 12px;
    border-radius: 8px;
    text-align: center;
}

.ytd-item label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-bottom: 4px;
    text-transform: uppercase;
}

.ytd-item span {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent);
}

/* Quarterly */
.quarter-block {
    background: var(--bg);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
}
.quarter-block h3 { font-size: 0.9rem; color: var(--accent); margin-bottom: 8px; }
.q-row { display: flex; justify-content: space-between; font-size: 0.85rem; padding: 4px 0; }
.q-row span { color: var(--text-dim); }

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 12px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Responsive */
@media (max-width: 400px) {
    .days-grid { gap: 4px; }
    .day-total { font-size: 0.95rem; }
    .day-sub { font-size: 0.65rem; gap: 1px; }
    .day-sub input { width: 30px; padding: 2px 0; font-size: 0.7rem; }
    .day-auto { min-width: 10px; font-size: 0.6rem; }
    header h1 { font-size: 1.2rem; }
    .live-stats { gap: 8px; }
    .live-stat span { font-size: 1.2rem; }
}

/* ---- New expense / platform styles ---- */
.platform-select {
    background: var(--surface);
    border: 1px solid var(--surface-hover);
    color: var(--text);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    margin-top: 6px;
    width: 100%;
}

.expense-list-box {
    margin: 6px 0;
    border: 1px solid #1f1f2e;
    border-radius: 6px;
    padding: 6px;
    background: #0d0d1a;
    min-height: 36px;
}

.expense-empty {
    color: var(--text-dim);
    font-size: 13px;
    margin: 6px 0;
    text-align: center;
}

.expense-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--surface-hover);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 6px;
    position: relative;
}
.expense-chip:last-child { margin-bottom: 0; }

.expense-desc {
    font-size: 13px;
    color: var(--text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.expense-attrs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
    flex-shrink: 0;
}

.expense-cat {
    background: #1f1f2e;
    color: var(--accent);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    text-transform: uppercase;
}

.expense-amt {
    font-weight: 700;
    min-width: 50px;
    text-align: right;
}

.expense-del {
    background: transparent;
    border: none;
    color: var(--danger);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    margin-left: 4px;
}
.expense-del:active { color: #ff6b6b; }

.btn-ghost {
    background: transparent;
    border: 1px dashed var(--surface-hover);
    color: var(--accent);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
    width: 100%;
    margin-top: 4px;
}
.btn-ghost:active { background: var(--surface); }

/* modal header/body/footer (add to existing modal) */
.modal-header,.modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--surface-hover);
}
.modal-footer { border-bottom: none; border-top: 1px solid var(--surface-hover); justify-content: flex-end; }
.modal-close { background: transparent; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; }
.modal-body { padding: 12px; }

.settings-guidance {
    font-size: 0.82rem;
    line-height: 1.4;
    color: var(--text-dim);
    background: rgba(255,255,255,0.03);
    border-left: 3px solid var(--accent);
    padding: 10px 12px;
    margin-bottom: 12px;
    border-radius: 0 8px 8px 0;
}

/* ---- Income chip styles ---- */
.income-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--surface-hover);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 6px;
    position: relative;
}
.income-chip:last-child { margin-bottom: 0; }

.income-desc {
    font-size: 13px;
    color: var(--text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.income-attrs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
    flex-shrink: 0;
}

.income-amt {
    font-weight: 700;
    min-width: 50px;
    text-align: right;
}

.income-del {
    background: transparent;
    border: none;
    color: var(--danger);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    margin-left: 4px;
}
.income-del:active { color: #ff6b6b; }
