/* ==========================================================================
   PayDue v3 — professional dashboard / analytics components
   ========================================================================== */

/* Page header */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-header .eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.page-header h1 { font-size: 26px; font-weight: 800; letter-spacing: -.025em; margin-top: 2px; }
.page-header p { color: var(--muted); font-size: 14px; margin-top: 2px; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* KPI cards */
.kpi-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 1100px) { .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; } }
.kpi-grid.cols-5 { }
@media (min-width: 1100px) { .kpi-grid.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.kpi {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; box-shadow: var(--shadow-sm);
}
@media (min-width: 640px) { .kpi { padding: 18px 20px; } }
.kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { font-size: 12.5px; font-weight: 650; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi-label svg { width: 15px; height: 15px; }
.kpi-value { font-size: 22px; font-weight: 800; letter-spacing: -.025em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 640px) { .kpi-value { font-size: 26px; } }
.kpi-value small { font-size: 12px; font-weight: 650; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.kpi-foot { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 18px; }
.kpi.primary { background: linear-gradient(140deg, var(--brand-1), var(--brand-2) 75%, var(--brand-3)); border-color: transparent; color: #fff; }
.kpi.primary .kpi-label, .kpi.primary .kpi-foot, .kpi.primary .kpi-value small { color: rgba(255, 255, 255, .75); }
.kpi.primary .meter { background: rgba(255, 255, 255, .18); }
.kpi.primary .meter > i { background: #6ff0a8; }
.kpi.is-danger { border-color: color-mix(in srgb, var(--overdue) 40%, var(--border)); }

.delta { display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; font-weight: 750; padding: 2px 7px; border-radius: 999px; }
.delta svg { width: 12px; height: 12px; }
.delta.up { background: var(--overdue-soft); color: var(--overdue); }     /* spending up = bad */
.delta.down { background: var(--paid-soft); color: var(--paid); }
.delta.flat { background: var(--surface-3); color: var(--muted); }
.kpi.primary .delta { background: rgba(255, 255, 255, .16); color: #fff; }

.meter { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 99px; background: var(--primary); }
.meter.warn > i { background: var(--partial); }
.meter.danger > i { background: var(--overdue); }
.meter.ok > i { background: var(--paid); }

/* Insights */
.insights { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .insights { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .insights { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.insight { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); font-size: 13.5px; font-weight: 550; color: var(--text-2); min-width: 0; }
.insight .icon-tile { width: 34px; height: 34px; border-radius: 10px; }
.insight .icon-tile svg { width: 17px; height: 17px; }

/* Section card header */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 12px; border-bottom: 1px solid var(--border); }
@media (min-width: 640px) { .panel-head { padding: 18px 22px 14px; } }
.panel-head h2 { font-size: 15.5px; font-weight: 750; }
.panel-head p { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.panel-head .link { font-size: 13px; font-weight: 650; color: var(--primary); display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.panel-head .link svg { width: 15px; height: 15px; }
.panel-body { padding: 16px 18px 18px; }
@media (min-width: 640px) { .panel-body { padding: 18px 22px 22px; } }
.panel-body.flush { padding: 0; }

/* 7-day timeline */
.timeline { display: flex; flex-direction: column; }
.tl-day { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 12px; padding: 12px 18px; border-top: 1px solid var(--border); }
.tl-day:first-child { border-top: 0; }
@media (min-width: 640px) { .tl-day { padding: 12px 22px; } }
.tl-date { text-align: center; border-radius: 12px; background: var(--surface-2); padding: 6px 0; align-self: start; }
.tl-date strong { display: block; font-size: 18px; font-weight: 800; line-height: 1.1; }
.tl-date span { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.tl-date.is-today { background: var(--primary); color: #fff; }
.tl-date.is-today span { color: rgba(255, 255, 255, .8); }
.tl-items { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tl-item { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tl-item .title { font-weight: 650; font-size: 14px; }
.tl-item .meta { font-size: 12px; color: var(--muted); }
.tl-item .amount { margin-left: auto; font-weight: 750; white-space: nowrap; font-size: 14px; }

/* Data tables */
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th { text-align: left; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .num, .data-table th.num { text-align: right; white-space: nowrap; }
.data-table .name { display: flex; align-items: center; gap: 10px; min-width: 0; font-weight: 650; }
.table-scroll { overflow-x: auto; }
@media (max-width: 720px) { .data-table .hide-sm { display: none; } }

/* Underline tabs (analytics) */
.tabs-line { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 4px 0 20px; overflow-x: auto; scrollbar-width: none; }
.tabs-line::-webkit-scrollbar { display: none; }
.tabs-line button { border: 0; background: none; cursor: pointer; padding: 10px 14px; font: inherit; font-size: 14px; font-weight: 650; color: var(--muted);
    border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px; }
.tabs-line button:hover { color: var(--text); }
.tabs-line button.is-active { color: var(--text); border-bottom-color: var(--primary); }
.tabs-line .count { font-size: 11.5px; font-weight: 700; color: var(--muted); background: var(--surface-3); border-radius: 99px; padding: 1px 7px; }

/* Bulk actions */
.bill-row.selectable { grid-template-columns: auto auto minmax(0, 1fr) auto; }
@media (min-width: 768px) { .bill-row.selectable { grid-template-columns: auto auto minmax(0, 1fr) 150px 140px auto; } }
.row-check { width: 20px; height: 20px; accent-color: var(--primary); cursor: pointer; }
.bill-row.is-selected { background: var(--primary-soft); }
.bulk-bar {
    position: fixed; z-index: 45; left: 50%; transform: translate(-50%, 120%); bottom: calc(var(--bottom-h) + 16px + env(safe-area-inset-bottom));
    display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px; border-radius: 16px;
    background: var(--text); color: var(--surface); box-shadow: var(--shadow-lg); transition: transform .2s ease, visibility .2s; max-width: calc(100% - 24px);
    visibility: hidden;
}
.bulk-bar.is-open { transform: translate(-50%, 0); visibility: visible; }
@media (min-width: 1024px) { .bulk-bar { bottom: 24px; left: calc(50% + var(--sidebar-w) / 2); } }
.bulk-bar .count { font-weight: 750; font-size: 14px; white-space: nowrap; margin-right: 4px; }
.bulk-bar .btn { height: 36px; padding: 0 12px; font-size: 13px; background: rgba(255, 255, 255, .12); color: inherit; }
[data-theme="dark"] .bulk-bar .btn { background: rgba(0, 0, 0, .08); }
.bulk-bar .btn:hover { background: rgba(255, 255, 255, .2); }
.bulk-bar .btn.danger { background: var(--overdue); color: #fff; }
.bulk-bar .btn span { display: none; }
@media (min-width: 560px) { .bulk-bar .btn span { display: inline; } }

/* Undo toast */
.toast .undo-btn { border: 0; cursor: pointer; font: inherit; font-size: 13px; font-weight: 750; color: var(--primary);
    background: var(--primary-soft); border-radius: 9px; padding: 6px 12px; margin-left: 4px; white-space: nowrap; }
.toast form { margin: 0; align-self: center; }
.toast .toast-progress { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--primary); border-radius: 0 0 0 14px; animation: toast-timer 8s linear forwards; }
.toast { position: relative; overflow: hidden; }
@keyframes toast-timer { from { width: 100%; } to { width: 0; } }

/* Shared bill + misc */
.share-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700; color: var(--upcoming); }
.share-badge svg { width: 12px; height: 12px; }
.pill-stopped { background: var(--surface-3); color: var(--muted); }
.scan-status { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.scan-status .spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-mini { padding: 22px; text-align: center; color: var(--muted); font-size: 13.5px; }
.budget-cta { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--primary); font-size: 12.5px; }

@media (max-width: 1099px) { .kpi-grid.cols-5 > :last-child:nth-child(odd) { grid-column: 1 / -1; } }
