/* ═══════════════════════════════════════════════════════
   Dashboard v2 — Tenant Home Page
   ═══════════════════════════════════════════════════════ */

/* ── Greeting banner ─────────────────────────────────── */
.db-greeting {
    background: linear-gradient(120deg, #8f5c0a 0%, #c9840f 45%, #f6a821 100%);
    border-radius: 20px;
    padding: 1rem 2rem;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    position: relative;
    overflow: hidden;
}
.db-greeting::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(circle, rgba(255,255,255,0.14) 1.5px, transparent 1.5px);
    background-size: 20px 20px;
    -webkit-mask-image: linear-gradient(115deg, #000 0%, #000 40%, transparent 75%);
    mask-image: linear-gradient(115deg, #000 0%, #000 40%, transparent 75%);
    pointer-events: none;
}
.db-greeting::after {
    content: '';
    position: absolute;
    width: 220px; height: 220px;
    border-radius: 50%;
    background: rgba(255,255,255,.07);
    top: -110px;
    left: -60px;
    pointer-events: none;
}
.db-greeting-text h2 {
    font-size: 1.4rem;
    font-weight: 800;
    margin: 0 0 .25rem;
    letter-spacing: -.01em;
}
.db-greeting-text p {
    font-size: .875rem;
    opacity: .8;
    margin: 0;
}
.db-greeting-badges {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.db-badge {
    background: rgba(255,255,255,.15);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,.22);
    border-radius: 14px;
    padding: .6rem 1.1rem;
    text-align: center;
    min-width: 108px;
}
.db-badge-val {
    font-size: 1.3rem;
    font-weight: 800;
    display: block;
    line-height: 1.2;
    direction: ltr;
}
.db-badge-lbl {
    font-size: .72rem;
    opacity: .82;
    display: block;
    margin-top: .2rem;
    white-space: nowrap;
}
@media (max-width: 768px) {
    .db-greeting { flex-direction: column; align-items: flex-start; }
    .db-greeting-badges { justify-content: flex-start; }
}

/* ── KPI grid: one hero metric + three compact ones ────── */
.db-kpi-grid {
    display: grid;
    grid-template-columns: 1.7fr 1fr;
    grid-template-rows: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}
.db-kpi-grid .db-kpi:nth-child(1) { grid-column: 1; grid-row: 1 / 4; }
.db-kpi-grid .db-kpi:nth-child(2) { grid-column: 2; grid-row: 1; }
.db-kpi-grid .db-kpi:nth-child(3) { grid-column: 2; grid-row: 2; }
.db-kpi-grid .db-kpi:nth-child(4) { grid-column: 2; grid-row: 3; }

@media (max-width: 1199px) {
    .db-kpi-grid { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; }
    .db-kpi-grid .db-kpi:nth-child(1) { grid-column: 1 / 3; grid-row: 1; }
    .db-kpi-grid .db-kpi:nth-child(2) { grid-column: 1; grid-row: 2; }
    .db-kpi-grid .db-kpi:nth-child(3) { grid-column: 2; grid-row: 2; }
    .db-kpi-grid .db-kpi:nth-child(4) { grid-column: 1 / 3; grid-row: 3; }
}
@media (max-width: 575px) {
    .db-kpi-grid { grid-template-columns: 1fr; grid-template-rows: auto; }
    .db-kpi-grid .db-kpi:nth-child(1),
    .db-kpi-grid .db-kpi:nth-child(2),
    .db-kpi-grid .db-kpi:nth-child(3),
    .db-kpi-grid .db-kpi:nth-child(4) { grid-column: 1; grid-row: auto; }
}

.db-kpi {
    background: var(--bg-card);
    border: 1px solid var(--card-border-color);
    border-radius: 16px;
    padding: 1.35rem 1.5rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    box-shadow: 0 1px 2px rgba(0,0,0,.03), 0 6px 16px rgba(0,0,0,.035);
    transition: box-shadow .22s, transform .22s;
    position: relative;
    overflow: hidden;
}
[data-theme="dark"] .db-kpi { box-shadow: 0 1px 2px rgba(0,0,0,.2), 0 6px 16px rgba(0,0,0,.25); }
.db-kpi--hero {
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 1.1rem;
    padding: 1.75rem 1.85rem;
}
.db-kpi--hero .db-kpi-icon { width: 58px; height: 58px; font-size: 1.4rem; border-radius: 14px; }
.db-kpi--hero .db-kpi-val  { font-size: 2.5rem; }
.db-kpi--hero .db-kpi-lbl  { font-size: .95rem; }
.db-kpi::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    border-radius: 16px 16px 0 0;
}
.db-kpi:hover { box-shadow: 0 8px 28px rgba(0,0,0,.1); transform: translateY(-2px); }

.db-kpi--indigo::after  { background: linear-gradient(90deg, #c9840f, #f6a821); }
.db-kpi--emerald::after { background: linear-gradient(90deg, #10b981, #34d399); }
.db-kpi--amber::after   { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.db-kpi--rose::after    { background: linear-gradient(90deg, #ef4444, #f87171); }
.db-kpi--sky::after     { background: linear-gradient(90deg, #0ea5e9, #38bdf8); }
.db-kpi--violet::after  { background: linear-gradient(90deg, #ff8a3d, #ff8a3d); }
.db-kpi--teal::after    { background: linear-gradient(90deg, #14b8a6, #2dd4bf); }
.db-kpi--orange::after  { background: linear-gradient(90deg, #f97316, #fb923c); }

.db-kpi-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: 1.15rem;
}
.db-kpi--indigo  .db-kpi-icon { background: rgba(246,168,33,.1);  color: #c9840f; }
.db-kpi--emerald .db-kpi-icon { background: rgba(16,185,129,.1);  color: #10b981; }
.db-kpi--amber   .db-kpi-icon { background: rgba(245,158,11,.1);  color: #d97706; }
.db-kpi--rose    .db-kpi-icon { background: rgba(239,68,68,.1);   color: #ef4444; }
.db-kpi--sky     .db-kpi-icon { background: rgba(14,165,233,.1);  color: #0ea5e9; }
.db-kpi--violet  .db-kpi-icon { background: rgba(139,92,246,.1);  color: #ff8a3d; }
.db-kpi--teal    .db-kpi-icon { background: rgba(20,184,166,.1);  color: #0d9488; }
.db-kpi--orange  .db-kpi-icon { background: rgba(249,115,22,.1);  color: #ea580c; }

.db-kpi-body { flex: 1; min-width: 0; }
.db-kpi-val {
    font-size: 1.7rem;
    font-weight: 800;
    line-height: 1.1;
    color: var(--text-primary);
    direction: ltr;
    text-align: right;
    letter-spacing: -.02em;
}
.db-kpi-lbl {
    font-size: .8rem;
    color: var(--text-tertiary);
    margin-top: .28rem;
    font-weight: 500;
}
.db-kpi-tag {
    display: inline-flex;
    align-items: center;
    gap: .22rem;
    font-size: .71rem;
    font-weight: 600;
    border-radius: 999px;
    padding: .18rem .55rem;
    margin-top: .45rem;
}
.db-kpi-tag--up   { background: rgba(16,185,129,.1);  color: #059669; }
.db-kpi-tag--warn { background: rgba(245,158,11,.1);  color: #b45309; }
.db-kpi-tag--info { background: rgba(246,168,33,.1);  color: #a8660c; }
.db-kpi-tag--down { background: rgba(239,68,68,.1);   color: #dc2626; }

/* ── Stat mini row ────────────────────────────────────── */
.db-stat-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}
@media (max-width: 1199px) { .db-stat-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 575px)  { .db-stat-row { grid-template-columns: repeat(2, 1fr); } }

.db-stat {
    background: var(--bg-card);
    border: 1px solid var(--card-border-color);
    border-radius: 14px;
    padding: 1rem 1.2rem;
    display: flex;
    align-items: center;
    gap: .85rem;
    box-shadow: 0 1px 2px rgba(0,0,0,.03), 0 4px 12px rgba(0,0,0,.03);
    transition: box-shadow .2s, transform .2s;
}
.db-stat:hover { box-shadow: 0 4px 16px rgba(0,0,0,.07); transform: translateY(-2px); }
[data-theme="dark"] .db-stat { box-shadow: 0 1px 2px rgba(0,0,0,.2), 0 4px 12px rgba(0,0,0,.2); }
.db-stat-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: .95rem;
    flex-shrink: 0;
}
.db-stat-num {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.1;
    letter-spacing: -.02em;
}
.db-stat-lbl { font-size: .77rem; color: var(--text-tertiary); font-weight: 500; }

/* ── Panel card ───────────────────────────────────────── */
.db-panel {
    background: var(--bg-card);
    border: 1px solid var(--card-border-color);
    border-radius: 16px;
    overflow: hidden;
    height: 100%;
    box-shadow: 0 1px 2px rgba(0,0,0,.03), 0 8px 20px rgba(0,0,0,.035);
    transition: box-shadow .25s ease, transform .25s ease, border-color .25s ease;
}
.db-panel:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,.04), 0 14px 28px rgba(0,0,0,.06);
    border-color: rgba(246,168,33,.28);
}
[data-theme="dark"] .db-panel { box-shadow: 0 1px 2px rgba(0,0,0,.2), 0 8px 20px rgba(0,0,0,.25); }
[data-theme="dark"] .db-panel:hover { box-shadow: 0 4px 8px rgba(0,0,0,.25), 0 14px 28px rgba(0,0,0,.35); }

.db-panel-head {
    padding: .9rem 1.4rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.db-panel-title {
    font-size: .9rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    display: flex; align-items: center; gap: .6rem;
}
.db-panel-title i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 9px;
    background: currentColor;
    background: color-mix(in srgb, currentColor 12%, transparent);
    font-size: .82rem;
}
.db-panel-meta {
    font-size: .73rem;
    color: var(--text-tertiary);
    background: var(--bg-tertiary);
    border-radius: 999px;
    padding: .18rem .65rem;
}
.db-panel-body { padding: 1.2rem 1.4rem; }

/* ── Chart wrapper ────────────────────────────────────── */
.db-chart-wrap { position: relative; height: 228px; }

/* ── Category bars ────────────────────────────────────── */
.db-cat-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem 0;
    border-bottom: 1px solid var(--border-light);
}
.db-cat-row:last-child { border-bottom: none; }
.db-cat-name {
    font-size: .82rem;
    color: var(--text-secondary);
    flex: 0 0 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.db-cat-track {
    flex: 1;
    height: 7px;
    background: var(--bg-tertiary);
    border-radius: 999px;
    overflow: hidden;
}
.db-cat-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #c9840f, #f6a821);
    transition: width .9s cubic-bezier(.4,0,.2,1);
}
.db-cat-pct {
    font-size: .78rem;
    font-weight: 700;
    color: var(--text-tertiary);
    flex: 0 0 36px;
    text-align: left;
}

/* ── Product table ────────────────────────────────────── */
.db-prod-table { width: 100%; border-collapse: collapse; }
.db-prod-table th {
    font-size: .71rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: .55rem .8rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    white-space: nowrap;
}
.db-prod-table td {
    padding: .72rem .8rem;
    font-size: .84rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
.db-prod-table tr:last-child td { border-bottom: none; }
.db-prod-table tr:hover td { background: var(--surface-hover); }
.db-prod-rank {
    width: 24px; height: 24px;
    border-radius: 6px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .71rem;
    font-weight: 800;
}
.db-prod-rank--1 { background: rgba(251,191,36,.2);  color: #92400e; }
.db-prod-rank--2 { background: rgba(148,163,184,.18); color: #475569; }
.db-prod-rank--3 { background: rgba(251,146,60,.16);  color: #9a3412; }
.db-prod-rank--n { background: var(--bg-tertiary); color: var(--text-tertiary); }

/* ── Status rows ──────────────────────────────────────── */
.db-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .72rem 0;
    border-bottom: 1px solid var(--border-light);
}
.db-status-row:last-child { border-bottom: none; }
.db-status-label { font-size: .84rem; color: var(--text-secondary); display: flex; align-items: center; gap: .5rem; }
.db-status-val   { font-size: .88rem; font-weight: 700; }
.db-status-val--warn   { color: #d97706; }
.db-status-val--danger { color: #ef4444; }
.db-status-val--ok     { color: #10b981; }
.db-status-val--info   { color: #0ea5e9; }

/* ── Quick actions ────────────────────────────────────── */
.db-actions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem;
}
.db-actions-grid--3col { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 991px) {
    .db-actions-grid--3col { grid-template-columns: repeat(2, 1fr); }
}
.db-action {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .9rem 1rem;
    border-radius: 12px;
    text-decoration: none;
    border: 1.5px solid transparent;
    transition: all .18s cubic-bezier(.4,0,.2,1);
    color: inherit;
}
.db-action:hover { transform: translateY(-2px); text-decoration: none; color: inherit; box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.db-action-icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: .95rem;
    flex-shrink: 0;
    transition: transform .18s;
}
.db-action:hover .db-action-icon { transform: scale(1.08); }
.db-action-title { font-size: .84rem; font-weight: 700; color: var(--text-primary); display: block; }
.db-action-sub   { font-size: .72rem; color: var(--text-tertiary); display: block; margin-top: .1rem; }

.db-action--indigo  { background: rgba(246,168,33,.06);  border-color: rgba(246,168,33,.15); }
.db-action--indigo:hover { background: rgba(246,168,33,.1); border-color: rgba(246,168,33,.3); }
.db-action--indigo  .db-action-icon { background: rgba(246,168,33,.14); color: #c9840f; }

.db-action--emerald { background: rgba(16,185,129,.06);  border-color: rgba(16,185,129,.15); }
.db-action--emerald:hover { background: rgba(16,185,129,.1); border-color: rgba(16,185,129,.3); }
.db-action--emerald .db-action-icon { background: rgba(16,185,129,.14); color: #10b981; }

.db-action--sky     { background: rgba(14,165,233,.06);  border-color: rgba(14,165,233,.15); }
.db-action--sky:hover { background: rgba(14,165,233,.1); border-color: rgba(14,165,233,.3); }
.db-action--sky     .db-action-icon { background: rgba(14,165,233,.14); color: #0ea5e9; }

.db-action--amber   { background: rgba(245,158,11,.06);  border-color: rgba(245,158,11,.15); }
.db-action--amber:hover { background: rgba(245,158,11,.1); border-color: rgba(245,158,11,.3); }
.db-action--amber   .db-action-icon { background: rgba(245,158,11,.14); color: #d97706; }

.db-action--violet  { background: rgba(139,92,246,.06);  border-color: rgba(139,92,246,.15); }
.db-action--violet:hover { background: rgba(139,92,246,.1); border-color: rgba(139,92,246,.3); }
.db-action--violet  .db-action-icon { background: rgba(139,92,246,.14); color: #ff8a3d; }

.db-action--rose    { background: rgba(239,68,68,.06);   border-color: rgba(239,68,68,.15); }
.db-action--rose:hover { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.3); }
.db-action--rose    .db-action-icon { background: rgba(239,68,68,.14); color: #ef4444; }

/* ── Low stock list ───────────────────────────────────── */
.db-stock-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem 0;
    border-bottom: 1px solid var(--border-light);
}
.db-stock-item:last-child { border-bottom: none; }
.db-stock-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(239,68,68,.18);
}
.db-stock-name { flex: 1; font-size: .82rem; color: var(--text-secondary); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-stock-qty  { font-size: .78rem; font-weight: 700; color: #ef4444; white-space: nowrap; }
.db-stock-sep  { font-size: .7rem; color: var(--text-tertiary); margin: 0 .2rem; }
.db-stock-min  { font-size: .73rem; color: var(--text-tertiary); }

/* ── Payment ring ─────────────────────────────────────── */
.db-ring-wrap { display: flex; flex-direction: column; align-items: center; gap: .45rem; padding: .5rem 0; }
.db-ring-svg  { transform: rotate(-90deg); }
.db-ring-track { fill: none; stroke: var(--bg-tertiary); stroke-width: 10; }
.db-ring-fill  { fill: none; stroke: #c9840f; stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset .9s ease; }
.db-ring-label { font-size: 1.4rem; font-weight: 800; color: var(--text-primary); }
.db-ring-sub   { font-size: .75rem; color: var(--text-tertiary); text-align: center; }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
    .db-kpi { padding: 1rem 1.1rem; gap: .75rem; }
    .db-kpi-val { font-size: 1.4rem; }
    .db-kpi-icon { width: 42px; height: 42px; font-size: 1rem; }
    .db-panel-body { padding: 0.875rem 1rem; }
    .db-panel-head { padding: .7rem 1rem; }
    .db-chart-wrap { height: 200px; }
    .db-actions-grid { gap: .55rem; }
}

@media (max-width: 575px) {
    .db-greeting { padding: 1.25rem 1.25rem; border-radius: 16px; }
    .db-greeting-text h2 { font-size: 1.15rem; }
    .db-badge { padding: .45rem .8rem; min-width: 86px; }
    .db-badge-val { font-size: 1.1rem; }

    .db-kpi { padding: 0.875rem 1rem; }
    .db-kpi-val { font-size: 1.3rem; }
    .db-kpi-icon { width: 38px; height: 38px; font-size: .9rem; }

    .db-stat { padding: .75rem .9rem; gap: .65rem; }
    .db-stat-icon { width: 34px; height: 34px; font-size: .85rem; }
    .db-stat-num { font-size: 1.2rem; }

    .db-actions-grid { grid-template-columns: 1fr; }
    .db-action { padding: .75rem .875rem; }

    .db-cat-name { flex: 0 0 90px; font-size: .77rem; }
    .db-chart-wrap { height: 180px; }
    .db-panel-head { padding: .6rem .875rem; }
    .db-panel-body { padding: .75rem .875rem; }
}

@media (max-width: 360px) {
    .db-greeting-badges { flex-wrap: wrap; gap: .5rem; }
    .db-badge { min-width: 72px; padding: .4rem .65rem; }
    .db-stat-row { gap: .5rem; }
}

/* ── Datetime strip ──────────────────────────────────── */
.db-datetime {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-top: .55rem;
    font-size: .78rem;
    opacity: .88;
}
.db-datetime-date,
.db-datetime-time {
    display: flex;
    align-items: center;
    gap: .3rem;
    background: rgba(255,255,255,.13);
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 20px;
    padding: .22rem .7rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    letter-spacing: .01em;
}
.db-datetime-time { font-weight: 700; }
.db-datetime-sep {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: rgba(255,255,255,.45);
}
@media (max-width: 480px) {
    .db-datetime { flex-wrap: wrap; }
}

/* ── Dark overrides ───────────────────────────────────── */
[data-theme="dark"] .db-panel,
[data-theme="dark"] .db-kpi,
[data-theme="dark"] .db-stat {
    background: var(--surface) !important;
    border-color: var(--border-color) !important;
    box-shadow: none !important;
}
[data-theme="dark"] .db-panel-head { border-color: var(--border-color); }
[data-theme="dark"] .db-cat-track  { background: rgba(255,255,255,.07); }
[data-theme="dark"] .db-prod-table th { background: rgba(255,255,255,.04); }
[data-theme="dark"] .db-prod-table tr:hover td { background: rgba(255,255,255,.03); }
[data-theme="dark"] .db-ring-track { stroke: rgba(255,255,255,.08); }
[data-theme="dark"] .db-stock-dot  { box-shadow: 0 0 0 3px rgba(239,68,68,.12); }

/* ── Keep the floating AI button clear of the weekly-sales chart ── */
#ai-fab.ai-fab { bottom: 20px; left: 20px; }
