:root {
    --primary: #2563EB;
    --primary-dark: #1D4ED8;
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --text: #0F172A;
    --text-muted: #64748B;
    --border: #E2E8F0;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --radius: 12px;
    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #0F172A;
    --surface: #1E293B;
    --text: #F8FAFC;
    --text-muted: #94A3B8;
    --border: #334155;
    color-scheme: dark;
}

/* The hidden attribute must always win (the license gate relies on it) */
[hidden] { display: none !important; }

* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body {
    background: var(--bg); color: var(--text);
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
    transition: background 0.3s, color 0.3s;
    -webkit-text-size-adjust: 100%;
}
button, select, .btn-primary, .btn-secondary { touch-action: manipulation; } /* no double-tap zoom, pinch-zoom still works */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ───────── Header ───────── */
.app-header {
    background: var(--primary); color: white; text-align: center; position: relative;
    padding: calc(24px + env(safe-area-inset-top)) 20px 24px;
}
.app-header h1 { font-size: 1.5rem; font-weight: 700; }
.tagline { font-size: 0.875rem; opacity: 0.9; margin-top: 4px; }

.header-controls {
    position: absolute; top: calc(20px + env(safe-area-inset-top)); right: calc(20px + env(safe-area-inset-right));
    display: flex; gap: 8px;
}
.header-btn {
    background: rgba(255,255,255,0.2); border: none; color: white;
    width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
    font-size: 1.2rem; display: flex; align-items: center; justify-content: center;
    transition: background 0.2s; position: relative;
}
.header-btn:hover { background: rgba(255,255,255,0.35); }
.header-btn:focus-visible { outline-color: #fff; }

.notif-badge {
    position: absolute; top: -2px; right: -2px;
    background: var(--danger); color: white; font-size: 0.65rem; font-weight: 700;
    padding: 2px 5px; border-radius: 10px; min-width: 16px; text-align: center; line-height: 1;
}

/* ───────── Dashboard ───────── */
.dashboard { padding: 20px; max-width: 600px; margin: 0 auto; }
.summary-card { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.summary-item { background: var(--surface); padding: 16px; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,0.1); text-align: center; }
.summary-item .label { display: block; font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.summary-item .value { display: block; font-size: 1.5rem; font-weight: 700; margin-top: 4px; word-break: break-word; }
.summary-item .value.paid { color: var(--success); }

/* View switcher */
.view-switcher {
    display: flex; gap: 4px; background: var(--surface); padding: 4px;
    border-radius: 10px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.view-btn {
    flex: 1; padding: 12px 10px; min-height: 44px; background: transparent; border: none;
    color: var(--text-muted); font-weight: 600; font-size: 0.875rem;
    cursor: pointer; border-radius: 8px; transition: all 0.2s;
}
.view-btn.active { background: var(--primary); color: white; box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3); }

/* Forms, buttons, lists */
.bill-form { background: var(--surface); padding: 16px; border-radius: var(--radius); box-shadow: 0 4px 6px rgba(0,0,0,0.05); margin-bottom: 24px; }
.bill-form input, .bill-form select { width: 100%; padding: 12px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; background: var(--surface); color: var(--text); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn-primary {
    display: block; width: 100%; padding: 14px; min-height: 48px; background: var(--primary); color: white;
    border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer;
    text-align: center; text-decoration: none;
}
.btn-primary:hover { background: var(--primary-dark); }

.data-actions { display: flex; gap: 10px; }
.btn-secondary {
    flex: 1; display: inline-flex; align-items: center; justify-content: center;
    padding: 10px; min-height: 44px; background: var(--surface); border: 1px solid var(--border);
    color: var(--text); border-radius: 8px; font-size: 0.875rem; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-secondary:hover { border-color: var(--primary); }

.bill-list { list-style: none; }
.bill-item { background: var(--surface); padding: 16px; border-radius: var(--radius); margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.bill-item.paid { opacity: 0.6; }
.bill-item.overdue { border-left: 4px solid var(--danger); }
.bill-info { min-width: 0; }
.bill-info h3 { font-size: 1rem; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bill-info .badge { font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; background: var(--border); color: var(--text-muted); }
.bill-info p { font-size: 0.875rem; color: var(--text-muted); }
.bill-actions { display: flex; gap: 4px; flex-shrink: 0; }
.btn-icon { background: none; border: none; font-size: 1.25rem; cursor: pointer; padding: 8px; min-width: 44px; min-height: 44px; border-radius: 50%; color: var(--text); }
.btn-icon:hover { background: var(--border); }
.btn-delete { color: var(--danger); }
.btn-edit { color: var(--primary); }
.btn-edit:hover { background: rgba(37, 99, 235, 0.1); }

.empty-state { text-align: center; color: var(--text-muted); padding: 40px 0; }
.hidden { display: none !important; }

/* ───────── Charts ───────── */
.chart-section { margin-bottom: 24px; }
.chart-toggle { width: 100%; padding: 12px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.chart-container { background: var(--surface); padding: 20px; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-top: 12px; position: relative; height: auto; }
.chart-empty { text-align: center; color: var(--text-muted); padding: 40px 0; font-size: 0.9rem; }
.chart-tabs { display: flex; gap: 4px; margin-bottom: 16px; background: var(--bg); padding: 4px; border-radius: 8px; }
.chart-tab { flex: 1; padding: 10px; min-height: 44px; background: transparent; border: none; color: var(--text-muted); font-weight: 600; font-size: 0.875rem; cursor: pointer; border-radius: 6px; transition: all 0.2s; }
.chart-tab.active { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.chart-wrapper { position: relative; height: 280px; }
.chart-wrapper canvas { max-height: 280px; }

/* ───────── Calendar ───────── */
.calendar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; background: var(--surface); padding: 16px; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.calendar-header h2 { font-size: 1.1rem; font-weight: 700; }
.cal-nav-btn { background: var(--bg); border: none; width: 44px; height: 44px; border-radius: 50%; font-size: 1.5rem; cursor: pointer; color: var(--text); display: flex; align-items: center; justify-content: center; }
.cal-nav-btn:hover { background: var(--primary); color: white; }
.calendar-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; text-align: center; font-size: 0.75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day { aspect-ratio: 1; background: var(--surface); border-radius: 8px; padding: 6px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; cursor: pointer; transition: all 0.2s; border: 2px solid transparent; position: relative; }
.cal-day:hover { border-color: var(--primary); transform: translateY(-1px); }
.cal-day.other-month { opacity: 0.3; }
.cal-day.today { border-color: var(--primary); background: rgba(37, 99, 235, 0.1); }
.cal-day .day-number { font-size: 0.875rem; font-weight: 600; }
.cal-day .bill-dots { display: flex; gap: 2px; margin-top: 4px; flex-wrap: wrap; justify-content: center; }
.bill-dot { width: 6px; height: 6px; border-radius: 50%; }
.cal-day.overdue-day { background: rgba(239, 68, 68, 0.1); }

/* Day detail */
.day-detail { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-top: 16px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
.day-detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.day-detail-header h3 { font-size: 1rem; font-weight: 700; }
.day-detail-list { list-style: none; }
.day-detail-item { padding: 12px; background: var(--bg); border-radius: 8px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.day-detail-item .bill-name { font-weight: 600; font-size: 0.9rem; }
.day-detail-item .bill-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.day-detail-empty { text-align: center; color: var(--text-muted); padding: 20px; font-size: 0.875rem; }

/* ───────── Settings panel ─────────
   app.js toggles the "hidden" class, so we override the global display:none here
   to keep the slide animation. visibility removes it from the tab order when closed. */
.settings-panel {
    position: fixed; top: 0; right: 0; width: 100%; max-width: 380px; height: 100vh; height: 100dvh;
    background: var(--surface); box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    z-index: 200; overflow-y: auto;
    padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
    transform: translateX(0); visibility: visible;
    transition: transform 0.3s ease-in-out, visibility 0s;
}
.settings-panel.hidden {
    display: block !important;
    transform: translateX(100%); visibility: hidden; pointer-events: none;
    transition: transform 0.3s ease-in-out, visibility 0s linear 0.3s;
}
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.panel-header h3 { font-size: 1.2rem; font-weight: 700; }
.panel-body { display: flex; flex-direction: column; gap: 8px; }
.setting-group { margin-bottom: 8px; }
.setting-label { font-weight: 700; font-size: 0.95rem; display: block; margin-bottom: 4px; }
.setting-hint { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 12px; line-height: 1.4; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }

/* Toggle switch */
.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 12px; background: var(--bg); border-radius: 8px; cursor: pointer; position: relative; }
.toggle-row input[type="checkbox"] { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-slider { width: 44px; height: 24px; background: var(--border); border-radius: 12px; position: relative; transition: background 0.2s; }
.toggle-slider::after { content: ''; position: absolute; width: 18px; height: 18px; background: white; border-radius: 50%; top: 3px; left: 3px; transition: transform 0.2s; }
.toggle-row input:checked + .toggle-slider { background: var(--primary); }
.toggle-row input:checked + .toggle-slider::after { transform: translateX(20px); }
.toggle-row input:focus-visible + .toggle-slider { outline: 2px solid var(--primary); outline-offset: 2px; }
.timing-option { display: flex; align-items: center; gap: 10px; padding: 10px; margin-bottom: 8px; background: var(--bg); border-radius: 8px; cursor: pointer; font-size: 0.875rem; min-height: 44px; }
.timing-option input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ───────── Toasts & promo ───────── */
.toast-container {
    position: fixed; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
    z-index: 300; display: flex; flex-direction: column; gap: 8px; max-width: min(320px, calc(100vw - 24px));
}
.toast { background: var(--surface); border-left: 4px solid var(--primary); padding: 12px 16px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); animation: slideIn 0.3s ease-out; transition: opacity 0.3s, transform 0.3s; }
.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
.toast.danger { border-left-color: var(--danger); }
.toast-title { font-weight: 700; font-size: 0.875rem; margin-bottom: 2px; }
.toast-body { font-size: 0.8rem; color: var(--text-muted); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.promo-section { text-align: center; margin-top: 16px; }
.website-link { display: inline-flex; align-items: center; gap: 6px; color: var(--primary); font-weight: 700; text-decoration: none; font-size: 1rem; padding: 10px 20px; background: var(--bg); border-radius: 8px; border: 1px solid var(--border); transition: all 0.2s; }
.website-link:hover { background: var(--primary); color: white; border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2); }

.currency-select { width: 100%; padding: 12px; margin-top: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 0.9rem; cursor: pointer; }
.currency-select:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ───────── Install banner ───────── */
.install-prompt {
    position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 12px 16px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,0.2); z-index: 150;
    max-width: 576px; margin: 0 auto; font-size: 0.875rem;
}
.install-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.btn-small { padding: 10px 16px; min-height: 44px; background: var(--primary); color: #fff; border: 0; border-radius: 8px; font-weight: 600; cursor: pointer; }

/* ───────── License gate ───────── */
.lc-gate {
    position: fixed; inset: 0; z-index: 9999; background: var(--bg);
    display: flex; align-items: flex-start; justify-content: center; overflow-y: auto;
    padding: calc(24px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
}
.lc-panel { width: 100%; max-width: 400px; margin: auto; text-align: center; }
.lc-logo { font-size: 3rem; line-height: 1; margin-bottom: 8px; }
.lc-title { font-size: 1.75rem; font-weight: 800; }
.lc-headline { color: var(--text-muted); font-size: 1rem; margin-top: 4px; }
.lc-heading { font-size: 1.25rem; font-weight: 700; margin-bottom: 8px; }
.lc-heading-danger { color: var(--danger); }
.lc-error-msg { font-size: 0.9rem; margin-bottom: 24px; }

.lc-spinner { width: 40px; height: 40px; border: 4px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

.lc-benefits {
    list-style: none; text-align: left; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; margin: 20px 0; display: grid; gap: 10px; font-size: 0.95rem;
}
.lc-benefits li { display: flex; gap: 10px; align-items: flex-start; }
.lc-price { font-weight: 700; margin: -8px 0 16px; }

.lc-or { display: flex; align-items: center; gap: 12px; margin: 24px 0 16px; color: var(--text-muted); font-size: 0.8rem; }
.lc-or::before, .lc-or::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.lc-label { display: block; text-align: left; font-size: 0.8rem; font-weight: 600; margin-bottom: 6px; }
.lc-input { width: 100%; padding: 12px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; background: var(--surface); color: var(--text); }
.lc-input[aria-invalid="true"] { border-color: var(--danger); }
.lc-error { color: var(--danger); font-size: 0.85rem; text-align: left; margin-bottom: 10px; }
.lc-wide { width: 100%; }
.lc-help { font-size: 0.8rem; color: var(--text-muted); line-height: 1.5; margin-top: 16px; }
.lc-help a, .lc-tip a { color: var(--primary); font-weight: 600; }
.lc-tip { font-size: 0.8rem; color: var(--text-muted); background: var(--surface); border: 1px dashed var(--border); border-radius: 8px; padding: 10px 12px; margin-top: 14px; line-height: 1.5; text-align: left; }
.lc-privacy { font-size: 0.75rem; color: var(--text-muted); line-height: 1.5; margin-top: 18px; }

.lc-install { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 16px 0; text-align: left; }
.lc-install h3 { font-size: 0.95rem; margin-bottom: 12px; text-align: center; }
.lc-steps { padding-left: 20px; display: grid; gap: 8px; font-size: 0.9rem; line-height: 1.4; }
.lc-install .btn-primary { margin-bottom: 4px; }
#lcSuccess .lc-wide { margin-top: 4px; }

@media (max-width: 480px) {
    .cal-day .day-number { font-size: 0.75rem; }
    .bill-dot { width: 4px; height: 4px; }
    .bill-actions { gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}