:root {
    --app-primary: #4f46e5;
    --app-bg: #f8fafc;
    --card-bg: #ffffff;
    --surface: var(--surface);
    --surface-input: #f8fafc;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: rgba(15, 23, 42, 0.06);
    --sidebar-w: 240px;
    --r: 10px;      /* bo góc chính dùng chung */
    --r-sm: 6px;    /* bo góc nhỏ cho item bên trong */
}

/* Chế độ tối */
html[data-theme="dark"] {
    --app-bg: #0f172a;
    --card-bg: #1e293b;
    --surface: #334155;
    --surface-input: #0f172a;
    --text-main: var(--surface);
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: rgba(0, 0, 0, 0.4);
}

html[data-theme="dark"] body { color: var(--text-main); }

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--app-bg);
    color: var(--text-main);
    padding-bottom: calc(90px + env(safe-area-inset-bottom)); /* chừa cho bottom nav */
}

a { color: inherit; }

/* ============================ SIDEBAR (desktop) ============================ */
.sidebar { display: none; }

.brand {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.4rem;
    font-weight: 600;
    padding: 4px 14px 24px;
    display: flex; align-items: center; gap: 10px;
}

/* Ô vuông nâu – nhận dạng thương hiệu Ví Sub */
.wallet-ico {
    display: inline-block;
    width: 22px; height: 22px;
    background: linear-gradient(135deg, #92400e, #b45309);
    border-radius: 5px;
    flex-shrink: 0;
    vertical-align: middle;
}

.side-nav { display: flex; flex-direction: column; gap: 4px; }

.side-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--r);
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.95rem;
}
.side-link .ic { font-size: 1.2rem; }
.side-link:hover { background: var(--surface); }
.side-link.active { background: #eef2ff; color: var(--app-primary); }
.sidebar-version { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; font-size: 0.7rem; color: var(--text-muted); letter-spacing: 0.03em; }

/* ============================ HEADER / DASHBOARD ========================== */
.app-header {
    background: linear-gradient(135deg, #6366f1, var(--app-primary));
    color: white;
    padding: 25px 20px 40px;
    border-bottom-left-radius: 28px;
    border-bottom-right-radius: 28px;
}
.app-header.compact { padding-bottom: 28px; }

.logo {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.back-link { text-decoration: none; font-size: 1.8rem; line-height: 1; }

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}
.dashboard-card {
    background: rgba(255, 255, 255, 0.15);
    padding: 18px;
    border-radius: var(--r);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}
.dashboard-card p { font-size: 0.8rem; opacity: 0.9; margin-bottom: 4px; }
.dashboard-card h1 { font-size: 1.6rem; font-weight: 700; }
.sub-hint { font-size: 0.72rem; opacity: 0.85; }
.header-meta { margin-top: 14px; font-size: 0.82rem; opacity: 0.9; }

.app-container { padding: 20px; max-width: 760px; margin: -25px auto 0; }
/* Trang phụ (lịch, sửa, phân tích) dùng header gọn -> không kéo nội dung lên */
.app-header.compact ~ .app-container { margin-top: 0; }

/* ============================ HORIZONTAL SCROLL / CHIPS =================== */
.horizontal-scroll-container {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 5px 0 15px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}
.horizontal-scroll-container::-webkit-scrollbar { display: none; }

.chip {
    display: inline-block;
    white-space: nowrap;
    padding: 9px 16px;
    background: var(--card-bg);
    border-radius: 20px;
    text-decoration: none;
    color: var(--text-main);
    font-size: 0.88rem;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.chip.active { background: var(--text-main); color: white; }

/* ============================ UPCOMING BANNER ============================ */
.upcoming-banner {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
    padding: 12px 16px;
    border-radius: var(--r);
    font-size: 0.85rem;
    margin-bottom: 6px;
}

/* ============================ SUB LIST ================================== */
.section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 22px 0 10px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}
.view-controls { margin-left: auto; display: flex; gap: 4px; }
.view-toggle-btn {
    background: var(--surface);
    border: none;
    border-radius: 8px;
    width: 32px; height: 32px;
    font-size: 1rem;
    cursor: pointer;
    color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background .15s, color .15s;
}
.view-toggle-btn:hover { background: var(--border); color: var(--text-main); }
.view-toggle-btn.active { background: #eef2ff; color: var(--app-primary); }

/* Compact list mode */
.sub-list.compact { gap: 4px; }
.sub-list.compact .sub-card {
    padding: 9px 12px;
    border-radius: 10px;
    align-items: center;
}
.sub-list.compact .service-icon {
    width: 30px; height: 30px;
    font-size: 0.95rem; border-radius: 8px;
}
.sub-list.compact .sub-meta { display: none; }
.sub-list.compact .sub-actions { display: none; }
.sub-list.compact .sub-name { font-size: 0.9rem; }
.sub-list.compact .sub-price { font-size: 0.9rem; }
.sub-list.compact .period-tag { font-size: 0.68rem; }
.sub-list-wrap {
    max-height: 60vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    padding-right: 2px;
}
.sub-list-wrap::-webkit-scrollbar { width: 5px; }
.sub-list-wrap::-webkit-scrollbar-track { background: transparent; }
.sub-list-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sub-list { display: flex; flex-direction: column; gap: 12px; }

.sub-card {
    background: var(--card-bg);
    padding: 14px 16px;
    border-radius: var(--r);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    box-shadow: 0 2px 6px var(--shadow);
}
.sub-card.paused { opacity: 0.6; }

.sub-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.service-icon {
    width: 42px; height: 42px;
    border-radius: var(--r);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; flex-shrink: 0;
}
.sub-details { min-width: 0; }
.sub-name { font-weight: 700; font-size: 1.02rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sub-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.due-soon { color: #f59e0b; font-weight: 600; }

.tag-paused {
    font-size: 0.65rem; background: #e2e8f0; color: #475569;
    padding: 2px 8px; border-radius: var(--r-sm); font-weight: 600;
}

.sub-analytics { text-align: right; flex-shrink: 0; }
.sub-price { font-weight: 700; font-size: 1.02rem; white-space: nowrap; }
.period-tag { font-size: 0.72rem; color: var(--text-muted); }
.sub-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; }
.act-link {
    font-size: 0.78rem; font-weight: 600; text-decoration: none;
    color: var(--app-primary); background: var(--surface);
    padding: 6px 11px; border-radius: var(--r-sm); line-height: 1;
}
.act-link.danger { color: #ef4444; background: #fef2f2; }
button.act-link, button.btn-danger-outline { border: none; cursor: pointer; font-family: inherit; font-size: inherit; }
button.btn-danger-outline { width: 100%; background: transparent; }
.empty { color: var(--text-muted); font-size: 0.9rem; padding: 10px 2px; }

/* ============================ FORM ===================================== */
.main-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--r);
    box-shadow: 0 4px 12px var(--shadow);
    margin-top: 16px;
}
.form-label {
    font-size: 0.82rem; font-weight: 600; color: var(--text-muted);
    margin-bottom: 6px; display: block;
}
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin: -4px 0 12px 2px; }

input, select {
    width: 100%;
    padding: 14px;
    margin-bottom: 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--r);
    font-size: 1rem;
    outline: none;
    background: var(--surface-input);
    color: var(--text-main);
}
input:focus, select:focus { border-color: var(--app-primary); background: var(--card-bg); }

.form-row { display: flex; gap: 10px; }
.form-row > * { flex: 1; }

.template-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; max-height: 260px; overflow-y: auto; }
.template-chip {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 10px 10px; background: var(--surface);
    border: 1.5px solid transparent; border-radius: var(--r-sm);
    font-size: 0.84rem; cursor: pointer; text-align: left;
    transition: border-color .15s, background .15s; color: var(--text-main);
    min-height: 44px; /* touch target */
}
.template-chip:hover { border-color: var(--app-primary); background: #f5f3ff; }
.template-chip.active { background: #eef2ff; border-color: var(--app-primary); }
.tpl-icon { width: 30px; height: 30px; border-radius: var(--r-sm); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 1rem; }
.tpl-name { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-price { color: var(--text-muted); font-size: 0.78rem; white-space: nowrap; flex-shrink: 0; }
html[data-theme="dark"] .template-chip:hover { background: #1e1b4b; }
html[data-theme="dark"] .template-chip.active { background: #1e1b4b; }

.tpl-section { margin-bottom: 12px; }
.tpl-toggle {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; background: none; border: none; cursor: pointer;
    padding: 4px 0 8px; font-size: 0.82rem; font-weight: 600;
    color: var(--text-muted); font-family: inherit;
}
.tpl-toggle:hover { color: var(--text-main); }

.label-with-action {
    display: flex; align-items: center; justify-content: space-between;
}
.calc-btn {
    background: none; border: 1.5px solid var(--app-primary); color: var(--app-primary);
    border-radius: var(--r-sm); padding: 3px 10px; font-size: 0.78rem; font-weight: 600;
    cursor: pointer; font-family: inherit; line-height: 1.6;
    transition: background .15s, color .15s;
}
.calc-btn:hover { background: var(--app-primary); color: #fff; }

.custom-period-row {
    display: flex; gap: 8px; margin-bottom: 12px;
}
.custom-period-row input  { flex: 1; margin-bottom: 0; }
.custom-period-row select { flex: 1; margin-bottom: 0; }

.btn-secondary-outline {
    display: block; text-align: center; margin-top: 10px; padding: 13px;
    border: 1.5px solid var(--border); color: var(--text-muted); border-radius: 14px;
    text-decoration: none; font-weight: 600; font-size: 0.88rem;
    transition: border-color .15s, color .15s;
}
.btn-secondary-outline:hover { border-color: var(--app-primary); color: var(--app-primary); }

/* ============================ HOME LAYOUT / WIDE MODE ==================== */
.home-col-add { margin-top: 0; }

@media (min-width: 900px) {
    body.wide-mode .app-container { max-width: 1400px; }

    body.wide-mode .home-layout {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
        align-items: start;
    }
    body.wide-mode .home-col-subs { grid-column: 1; }

    /* Transparent chain: col-add → card → form → panels become grid items */
    body.wide-mode .home-col-add { display: contents; }
    body.wide-mode .add-sub-card { display: contents; }
    body.wide-mode .add-sub-toggle { display: none; }
    body.wide-mode #add-sub-form { display: contents; } /* inline display:none removed by JS */
    body.wide-mode form.sub-form { display: contents; }

    body.wide-mode .form-emoji-panel {
        grid-column: 2;
        background: var(--card-bg);
        border-radius: var(--r);
        padding: 16px;
        box-shadow: 0 4px 12px var(--shadow);
        position: sticky;
        top: 16px;
        margin-top: 16px;
        overflow: hidden;
        min-width: 0;
    }
    body.wide-mode .form-detail-panel {
        grid-column: 3;
        background: var(--card-bg);
        border-radius: var(--r);
        padding: 20px;
        box-shadow: 0 4px 12px var(--shadow);
        margin-top: 16px;
        min-width: 0;
    }
    body.wide-mode .template-list { max-height: 220px; }
}

.emoji-grid {
    display: grid; grid-template-columns: repeat(8, 1fr);
    gap: 6px; margin-bottom: 14px;
}
.emoji-btn {
    aspect-ratio: 1; background: var(--surface); border: 1.5px solid transparent;
    border-radius: 10px; font-size: 1.2rem; cursor: pointer; padding: 0;
}
.emoji-btn.active { border-color: var(--app-primary); background: #eef2ff; }

.star-row { display: flex; gap: 6px; margin-bottom: 14px; }
.star {
    background: none; border: none; font-size: 1.8rem; cursor: pointer;
    color: #cbd5e1; padding: 0; line-height: 1;
}
.star.on { color: #f59e0b; }

.check-row {
    display: flex; align-items: center; gap: 8px; width: auto;
    font-size: 0.88rem; color: var(--text-muted); margin-bottom: 14px; cursor: pointer;
}
.check-row input { width: auto; margin: 0; }

.add-sub-toggle {
    display: flex; align-items: center; justify-content: space-between;
    cursor: pointer; font-weight: 700; font-size: 0.95rem;
    user-select: none; padding: 2px 0;
}
.add-sub-toggle:hover { color: var(--app-primary); }

.btn-submit {
    width: 100%; padding: 16px; background: var(--app-primary); color: white;
    border: none; border-radius: 14px; font-size: 1rem; font-weight: 700;
    cursor: pointer; box-shadow: 0 4px 12px rgba(79,70,229,0.3);
    text-decoration: none; display: block; text-align: center;
}
.btn-submit:active { transform: scale(0.98); }
.btn-danger-outline {
    display: block; text-align: center; margin-top: 12px; padding: 14px;
    border: 1.5px solid #fecaca; color: #ef4444; border-radius: 14px;
    text-decoration: none; font-weight: 600; transition: background .15s;
}
.btn-danger-outline:hover { background: #fef2f2; }

/* ============================ CALENDAR ================================= */
.cal-nav { display: flex; align-items: center; gap: 16px; }
.cal-arrow {
    width: 36px; height: 36px; border-radius: 10px;
    background: rgba(255,255,255,0.2); color: #fff; text-decoration: none;
    display: flex; align-items: center; justify-content: center; font-size: 1.3rem;
}
.cal-title { font-weight: 600; font-size: 1.05rem; }

/* Nút biểu tượng + tooltip (xuất .ics) */
.tooltip-wrap { position: relative; display: inline-flex; margin-left: auto; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 12px;
    background: rgba(255, 255, 255, 0.2); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; text-decoration: none;
}
.icon-btn:active { transform: scale(0.94); }
.tooltip {
    position: absolute; top: calc(100% + 8px); right: 0;
    background: var(--text-main); color: var(--card-bg);
    padding: 8px 12px; border-radius: 10px;
    font-size: 0.8rem; font-weight: 600; white-space: nowrap;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
    opacity: 0; visibility: hidden; transform: translateY(-4px);
    transition: opacity .15s, transform .15s, visibility .15s; z-index: 60;
}
/* Mũi tên nhỏ chỉ lên nút */
.tooltip::before {
    content: ""; position: absolute; bottom: 100%; right: 14px;
    border: 6px solid transparent; border-bottom-color: var(--text-main);
}
.tooltip-wrap:hover .tooltip,
.tooltip-wrap:focus-within .tooltip,
.tooltip-wrap.show .tooltip {
    opacity: 1; visibility: visible; transform: translateY(0);
}

.calendar { background: var(--card-bg); border-radius: 18px; padding: 10px; box-shadow: 0 4px 10px rgba(0,0,0,0.03); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head { margin-bottom: 4px; }
.cal-weekday { text-align: center; font-size: 0.72rem; font-weight: 700; color: var(--text-muted); padding: 4px 0; }
.cal-cell {
    min-height: 64px; border-radius: 10px; background: var(--surface-input);
    padding: 4px; font-size: 0.7rem; overflow: hidden;
}
.cal-cell.muted { opacity: 0.4; }
.cal-cell.has-subs { cursor: pointer; }
.cal-cell.has-subs:hover { background: var(--surface); }
/* Dùng box-shadow inset thay outline: viền nằm GỌN trong ô, không lệch vào khe lưới */
.cal-cell.is-today { box-shadow: inset 0 0 0 2px var(--app-primary); }
.cal-daynum { font-weight: 600; font-size: 0.78rem; margin-bottom: 2px; }
.cal-event {
    border-radius: 6px; padding: 2px 4px; margin-bottom: 2px;
    font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ce-icon { font-size: 0.8rem; }
/* Ô lịch hẹp trên mobile -> chỉ hiện icon cho gọn; tên hiện ở desktop */
.ce-name { display: none; margin-left: 3px; }
@media (min-width: 900px) {
    .ce-name { display: inline; }
    .cal-cell { min-height: 84px; }
}

/* ============================ INSIGHTS ================================= */

/* Health card – redesign */
.health-card { padding: 20px; }
.health-top { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.health-score-wrap { display: flex; align-items: baseline; gap: 2px; flex-shrink: 0; }
.health-score {
    font-family: 'Fredoka', sans-serif;
    font-size: 3.2rem; font-weight: 700; line-height: 1;
}
.health-score.grade-good { color: #22c55e; }
.health-score.grade-ok  { color: #f59e0b; }
.health-score.grade-bad { color: #ef4444; }
.health-score-max { font-size: 0.88rem; color: var(--text-muted); }
.health-info { flex: 1; min-width: 0; }
.health-grade { font-weight: 700; font-size: 1.05rem; margin-bottom: 4px; }
.health-desc { font-size: 0.8rem; color: var(--text-muted); }

.health-bar-track {
    height: 8px; background: var(--surface); border-radius: 4px;
    overflow: hidden; margin-bottom: 16px;
}
.health-bar-fill {
    height: 100%; border-radius: 4px;
    transition: width .6s cubic-bezier(.4,0,.2,1);
}
.health-bar-fill.grade-good { background: #22c55e; }
.health-bar-fill.grade-ok  { background: #f59e0b; }
.health-bar-fill.grade-bad { background: #ef4444; }

.health-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 8px;
}
.health-stat {
    background: var(--surface-input); border-radius: 12px; padding: 12px 14px;
}
.health-stat-val { font-weight: 700; font-size: 0.95rem; }
.health-stat-label { font-size: 0.7rem; color: var(--text-muted); margin-top: 3px; }

/* Tổng đã chi (hiện trên card sub) */
.spent-total { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut { width: 150px; height: 150px; transform: rotate(0deg); }
.donut-track { fill: none; stroke: var(--surface); stroke-width: 4; }
.donut-seg { fill: none; stroke-width: 4; }
.legend { list-style: none; flex: 1; min-width: 160px; }
.legend li {
    display: grid;
    grid-template-columns: 12px 1fr auto auto;
    align-items: center;
    column-gap: 8px;
    font-size: 0.85rem; padding: 5px 0; font-weight: 600;
}
.legend .dot { width: 12px; height: 12px; border-radius: 50%; }
.legend-cat { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-pct { text-align: right; font-weight: 700; }
.legend-amt { text-align: right; color: var(--text-muted); font-weight: 500; white-space: nowrap; }

.rec-list { display: flex; flex-direction: column; gap: 10px; }
.rec-card {
    display: flex; gap: 12px; align-items: flex-start;
    background: var(--card-bg); padding: 14px; border-radius: 14px;
    border-left: 5px solid var(--border); box-shadow: 0 4px 10px rgba(0,0,0,0.03);
}
.rec-card.lvl-danger { border-left-color: #ef4444; }
.rec-card.lvl-warn { border-left-color: #f59e0b; }
.rec-card.lvl-info { border-left-color: #3b82f6; }
.rec-card.lvl-ok { border-left-color: #22c55e; }
.rec-icon { font-size: 1.3rem; }
.rec-title { font-weight: 700; font-size: 0.92rem; }
.rec-detail { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }

.badge { font-size: 0.65rem; padding: 2px 8px; border-radius: 8px; font-weight: 700; }
.badge-ok { background: #dcfce7; color: #15803d; }
.badge-warn { background: #fee2e2; color: #b91c1c; }

/* ============================ BOTTOM NAV (mobile) ====================== */
.bottom-navbar {
    position: fixed; bottom: 0; left: 0; right: 0; height: 75px;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--card-bg); display: flex;
    justify-content: space-around; align-items: center;
    border-top: 1px solid var(--border); box-shadow: 0 -4px 12px rgba(0,0,0,0.03);
    z-index: 999;
}
.nav-tab { text-align: center; text-decoration: none; color: var(--text-muted); font-size: 0.72rem; font-weight: 600; }
.nav-icon { font-size: 1.35rem; margin-bottom: 3px; }
.nav-tab.active { color: var(--app-primary); }

/* ============================================================
   RESPONSIVE — Desktop (>= 900px): hiện sidebar, ẩn bottom nav.
   Đây là chỗ fix "menu lệch trên mobile": dưới 900px sidebar
   display:none hoàn toàn nên nội dung không bị đẩy lệch.
   ============================================================ */
@media (min-width: 900px) {
    body { padding-bottom: 0; }

    .sidebar {
        display: block;
        position: fixed; top: 0; left: 0; bottom: 0;
        width: var(--sidebar-w);
        background: var(--card-bg);
        border-right: 1px solid var(--border);
        padding: 22px 14px;
        z-index: 50;
    }
    .app-shell { margin-left: var(--sidebar-w); }
    .bottom-navbar { display: none; }

    .app-header { border-radius: 0 0 28px 28px; }
    .app-container { padding: 24px 28px 40px; }
}

/* ============================ PROFILE PAGE ================================ */
.profile-header { display: flex; align-items: center; gap: 16px; padding: 18px 20px; }
.profile-icon {
    width: 64px; height: 64px; border-radius: 18px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.9rem; flex-shrink: 0;
}
.profile-info { flex: 1; min-width: 0; }
.profile-name {
    font-size: 1.15rem; font-weight: 700;
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.profile-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 3px; }
.profile-price { font-size: 1rem; font-weight: 700; margin-top: 6px; }
.profile-renew { font-size: 0.78rem; color: var(--text-muted); margin-top: 3px; }

.profile-stats {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 8px; margin-bottom: 0;
}
.profile-stat {
    background: var(--card-bg); border-radius: 14px;
    padding: 14px 10px; text-align: center;
    box-shadow: 0 2px 8px var(--shadow);
}
.profile-stat-val { font-size: 0.95rem; font-weight: 700; }
.profile-stat-label { font-size: 0.66rem; color: var(--text-muted); margin-top: 3px; }

/* Payment history */
.history-list {
    background: var(--card-bg); border-radius: 18px;
    overflow: hidden; box-shadow: 0 4px 10px var(--shadow);
}
.history-item {
    display: grid; grid-template-columns: 12px 1fr auto auto;
    align-items: center; gap: 12px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.dot-paid { background: #22c55e; }
.dot-upcoming { background: #f59e0b; }
.history-date { font-size: 0.88rem; font-weight: 600; }
.history-amount { font-weight: 700; font-size: 0.88rem; white-space: nowrap; text-align: right; }
.history-badge {
    font-size: 0.72rem; font-weight: 600; padding: 3px 8px;
    border-radius: 8px; white-space: nowrap;
}
.badge-done { background: #dcfce7; color: #15803d; }
.badge-upcoming { background: #fef9c3; color: #a16207; }

html[data-theme="dark"] .badge-done { background: #14532d; color: #86efac; }
html[data-theme="dark"] .badge-upcoming { background: #451a03; color: #fcd34d; }
html[data-theme="dark"] .history-item.upcoming { background: rgba(245,158,11,0.08); }

/* ============================ DAY DETAIL (inline, below calendar) ======= */
.cal-cell.day-active {
    background: rgba(79, 70, 229, 0.1);
    box-shadow: inset 0 0 0 2px var(--app-primary);
}
.day-detail {
    background: var(--card-bg);
    border-radius: 18px;
    padding: 16px;
    margin-top: 12px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.04);
}
.day-detail-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 12px;
}
.day-detail-header span { font-weight: 700; font-size: 0.95rem; }
.day-detail-close {
    background: var(--surface); border: none;
    width: 28px; height: 28px; border-radius: 50%;
    font-size: 0.8rem; color: var(--text-muted);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.day-modal-item {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 13px; background: var(--surface-input); border-radius: 12px;
    margin-bottom: 8px;
}
.day-modal-item:last-child { margin-bottom: 0; }
.day-modal-icon {
    width: 38px; height: 38px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; flex-shrink: 0;
}
.day-modal-name { font-weight: 700; font-size: 0.92rem; }
.day-modal-price { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

/* ============================ DATA TOOLS ============================= */
.data-msg {
    margin: 0 0 12px;
    padding: 10px 14px;
    background: #dcfce7;
    color: #166534;
    border-radius: var(--r-sm);
    font-size: 0.85rem;
    font-weight: 600;
}
html[data-theme="dark"] .data-msg { background: #14532d; color: #bbf7d0; }

.data-tools-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}
.data-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 16px;
    border-radius: var(--r-sm);
    font-size: 0.83rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: opacity 0.15s;
    white-space: nowrap;
}
.data-btn:hover { opacity: 0.82; }
.btn-export { background: #0ea5e9; color: #fff; }
.btn-ics    { background: #8b5cf6; color: #fff; }
.btn-import { background: #10b981; color: #fff; }
.btn-clear  { background: #ef4444; color: #fff; }
.btn-reset  { background: #f97316; color: #fff; }
.data-import-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.import-replace-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
}

/* ============================ HTMX ============================= */
#htmx-bar {
    position: fixed;
    top: 0; left: 0;
    height: 3px;
    width: 0;
    background: var(--app-primary);
    z-index: 10000;
    opacity: 0;
    transition: width 0.3s ease, opacity 0.3s;
    pointer-events: none;
}
.sub-card.htmx-swapping {
    opacity: 0;
    transform: translateX(16px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

/* ============================ THEME TOGGLE ============================= */
.theme-toggle {
    position: fixed;
    top: calc(14px + env(safe-area-inset-top));
    right: 14px;
    z-index: 1000;
    width: 42px; height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text-main);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 3px 12px var(--shadow);
}
.theme-toggle:active { transform: scale(0.94); }

/* ============================ ANALYTICS PANEL ============================ */
.analytics-card { padding: 16px; margin-top: 16px; }

/* Tabs */
.analytics-tabs {
    display: flex; gap: 4px; margin-bottom: 14px;
    padding-bottom: 12px; border-bottom: 1.5px solid var(--border);
}
.atab {
    flex: 1; padding: 7px 4px; border: none; background: none;
    font-size: 0.78rem; font-weight: 600; color: var(--text-muted);
    cursor: pointer; font-family: inherit; border-radius: var(--r-sm);
    transition: color .15s, background .15s;
}
.atab:hover { background: var(--surface); color: var(--text-main); }
.atab.active { background: var(--app-primary); color: #fff; }

/* Total row */
.analytics-total-row {
    display: flex; justify-content: space-between; align-items: flex-start;
    background: var(--surface); border-radius: var(--r-sm); padding: 12px 14px;
    margin-bottom: 4px;
}
.analytics-total-val { font-size: 1.1rem; font-weight: 700; }
.analytics-total-secondary { font-size: 0.92rem !important; color: var(--text-muted); }
.analytics-total-lbl { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }

/* Group title */
.analytics-group-title {
    font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
    color: var(--text-muted); margin: 14px 0 8px;
}

/* Category bars */
.analytics-cats { display: flex; flex-direction: column; gap: 8px; }
.analytics-cat-row {
    display: grid;
    grid-template-columns: 8px minmax(56px,80px) 1fr 30px auto;
    align-items: center; gap: 8px;
}
.analytics-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.analytics-cat-name { font-size: 0.78rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.analytics-bar-wrap { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.analytics-bar { height: 100%; border-radius: 3px; min-width: 2px; }
.analytics-pct { font-size: 0.7rem; color: var(--text-muted); text-align: right; }
.analytics-amt { font-size: 0.76rem; font-weight: 600; text-align: right; white-space: nowrap; }
.analytics-amt small { font-weight: 400; color: var(--text-muted); }

/* Category group (Phân loại tab) */
.analytics-cat-group { margin-bottom: 14px; }
.analytics-cat-group:last-child { margin-bottom: 0; }
.analytics-cat-header {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px; background: var(--surface); border-radius: var(--r-sm);
    margin-bottom: 6px;
}
.analytics-cat-header-amt { margin-left: auto; font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }

/* Service rows */
.analytics-svcs { display: flex; flex-direction: column; }
.analytics-svc-row {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 0; border-bottom: 1px solid var(--border);
}
.analytics-svc-row:last-child { border-bottom: none; }
.analytics-svc-icon {
    width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 1rem;
}
.analytics-svc-info { flex: 1; min-width: 0; }
.analytics-svc-name { font-size: 0.82rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.analytics-svc-sub { font-size: 0.7rem; color: var(--text-muted); }
.analytics-svc-amt { font-size: 0.82rem; font-weight: 700; white-space: nowrap; flex-shrink: 0; }
.analytics-svc-amt small { font-weight: 400; font-size: 0.68rem; color: var(--text-muted); }
