/* ===== Cross-document view transitions ===== */
@view-transition { navigation: auto; }

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: .2s;
    animation-timing-function: ease;
}

/* ===== DaisyUI theme override — brand blue ===== */
:root,
[data-theme="light"] {
    --p:  221.2 83.2% 53.3%;
    --pf: 221.2 83.2% 43.3%;
    --pc: 0 0% 100%;
}

/* ===== Reset & Base ===== */
[hidden] { display: none !important; }

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary:   #2563eb;
    --primary-h: #1d4ed8;
    --danger:    #dc2626;
    --danger-h:  #b91c1c;
    --success:   #16a34a;
    --success-h: #15803d;
    --muted:     #6b7280;
    --border:    #e5e7eb;
    --bg:        #f9fafb;
    --card-bg:   #ffffff;
    --text:      #111827;
    --radius:    8px;
    --font-size: 16px;
}

html {
    background: var(--bg);
    min-height: 100dvh;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: var(--font-size);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overscroll-behavior-y: none;
    min-height: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

a, button, [role="button"] { touch-action: manipulation; }

/* ===== App Navbar ===== */
.app-navbar {
    background: var(--primary);
    color: #fff;
    padding: 0 1.25rem;
    align-items: center;
    justify-content: space-between;
    height: calc(56px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
}

/* Push content below the fixed header */
.has-header .page-container {
    padding-top: calc(56px + 1.5rem);
}

/* Desktop navbar: visible on desktop, hidden on mobile */
.app-navbar-desktop { display: flex; }
.app-navbar-mobile  { display: none; }

@media (max-width: 768px) {
    .app-navbar-desktop { display: none !important; }
    .app-navbar-mobile  { display: flex !important; padding: env(safe-area-inset-top, 0px) .5rem 0; }
}

.app-nav-brand {
    font-size: 1.35rem;
    font-weight: 800;
    color: #fff;
    text-decoration: none;
    letter-spacing: .04em;
    flex-shrink: 0;
}

.app-nav-links {
    display: flex;
    align-items: center;
    gap: .15rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}
.app-nav-links::-webkit-scrollbar { display: none; }

.app-nav-links a {
    color: rgba(255,255,255,.85);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    padding: .35rem .65rem;
    border-radius: 6px;
    white-space: nowrap;
    transition: background .12s, color .12s;
}
.app-nav-links a:hover {
    color: #fff;
    background: rgba(255,255,255,.12);
}

.app-nav-end {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-shrink: 0;
}

.app-nav-user {
    color: rgba(255,255,255,.65);
    font-size: .85rem;
    text-decoration: none;
}

.app-nav-logout {
    color: rgba(255,255,255,.9);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    padding: .3rem .75rem;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,.25);
    transition: background .12s;
}
.app-nav-logout:hover { background: rgba(255,255,255,.12); }

.app-nav-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,.8);
    padding: .5rem;
    border-radius: 8px;
    transition: background .12s, color .12s;
}
.app-nav-icon-btn:hover { background: rgba(255,255,255,.12); color: #fff; }

.mob-title {
    flex: 1;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Mobile Bottom Navigation ===== */
.app-btm-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: #fff;
    border-top: 1px solid var(--border);
    z-index: 300;
    box-shadow: 0 -1px 8px rgba(0,0,0,.06);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    display: none; /* shown only on mobile via media query */
    height: calc(58px + env(safe-area-inset-bottom, 0px));
    /* translateZ(0) forces GPU compositing without the stacking-context
       side-effects of will-change: transform that break position:fixed on iOS */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.bn-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--muted);
    font-size: .68rem;
    font-weight: 600;
    gap: .18rem;
    letter-spacing: .01em;
    user-select: none;
    transition: color .12s;
    padding: .3rem .25rem;
    border-top: 2px solid transparent;
    transition: color .12s, border-color .12s;
}
.bn-link svg { flex-shrink: 0; }
.bn-link.active { color: var(--primary); border-top-color: var(--primary); }
.bn-link:active { color: var(--primary); }

/* ===== Page Container ===== */
.page-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1rem 2rem;
}

/* ===== Flash Messages ===== */
.flash {
    padding: .85rem 1.1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .97rem;
    font-weight: 500;
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    transition: opacity .4s ease, transform .4s ease;
    border-left: 4px solid transparent;
}
.flash.flash-hiding {
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
}
.flash-success {
    background: #f0fdf4;
    color: #166534;
    border-color: #16a34a;
    border: 1px solid #86efac;
    border-left: 4px solid #16a34a;
}
.flash-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fca5a5;
    border-left: 4px solid #dc2626;
}
.flash-info {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #93c5fd;
    border-left: 4px solid #2563eb;
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: .5rem;
}

.page-header-actions {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.info-list a { color: var(--primary); text-decoration: none; }
.info-list a:hover { text-decoration: underline; }

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 1.5rem 0 .75rem;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .3rem;
    padding: .55rem 1.1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s, box-shadow .15s;
    touch-action: manipulation;
    white-space: nowrap;
}
.btn:hover { background: #f3f4f6; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-h); border-color: var(--primary-h); color: #fff; }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger-h); border-color: var(--danger-h); color: #fff; }

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}
.btn-success:hover { background: var(--success-h); border-color: var(--success-h); color: #fff; }

.btn-warning {
    background: #d97706;
    color: #fff;
    border: none;
}
.btn-warning:hover, .btn-warning:active { background: #b45309; }

.btn-sm {
    padding: .3rem .65rem;
    font-size: .875rem;
    min-height: 34px;
}
.btn-block { width: 100%; }
.btn-cancel { color: var(--muted); border-color: transparent; background: transparent; }
.btn-cancel:hover { background: var(--bg); border-color: var(--border); }
.btn-danger-ghost { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger); color: #fff; }
.btn-submit-wide { flex: 2; }
.btn-disabled {
    opacity: .4;
    cursor: default;
    pointer-events: none;
}

.card-actions { display: flex; gap: .4rem; margin-left: auto; }
.field-with-badge { display: flex; align-items: center; gap: .6rem; }
.field-with-badge .form-input { flex: 1; }

/* ── Touch targets ── */
.btn { min-height: 44px; }
.btn-sm { min-height: 36px; }

/* ===== Table ===== */
.table-wrapper { overflow-x: auto; }

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.table th {
    background: #f8fafc;
    text-align: left;
    padding: .7rem 1rem;
    font-weight: 600;
    font-size: .85rem;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}

.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f9fafb; }

.row-inactive td { color: var(--muted); }

.text-right { text-align: right; }
.actions { white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 2rem; }

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 600;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-muted   { background: #f3f4f6; color: var(--muted); }
.badge-warn    { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-pay     { background: #dbeafe; color: #1e40af; }

/* ===== Audit activity feed ===== */
.audit-feed {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    margin-top: .75rem;
}
.audit-entry {
    display: flex;
    gap: .85rem;
    align-items: flex-start;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .8rem 1rem;
}
.audit-entry-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: .1rem;
}
.audit-icon-create     { background: #dcfce7; color: #166534; }
.audit-icon-update     { background: #dbeafe; color: #1e40af; }
.audit-icon-delete     { background: #fee2e2; color: #991b1b; }
.audit-icon-deactivate { background: #fef9c3; color: #854d0e; }
.audit-entry-body  { flex: 1; min-width: 0; }
.audit-entry-main  { font-size: .97rem; line-height: 1.4; }
.audit-who  { font-weight: 600; color: var(--text); }
.audit-verb { margin: 0 .25rem; color: var(--muted); }
.audit-what { font-weight: 500; color: var(--text); }
.audit-entry-detail {
    margin-top: .2rem;
    font-size: .85rem;
    color: var(--muted);
    word-break: break-all;
}
.audit-entry-time {
    margin-top: .25rem;
    font-size: .78rem;
    color: var(--muted);
}

/* ===== Stock colours ===== */
.stock-ok   { color: var(--success); font-weight: 700; }
.stock-zero { color: var(--danger);  font-weight: 700; }
.inv-unit   { font-size: .8rem; color: var(--muted); margin-left: .15rem; }

.inv-stock {
    font-size: 14px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    flex-shrink: 0;
}
.inv-stock .inv-unit { font-size: 12px; color: var(--muted); margin-left: .15rem; font-weight: 400; }
.inv-stock-ok   { color: var(--success); }
.inv-stock-low  { color: #d97706; }
.inv-stock-out  { color: var(--danger); }
.inv-stock-zero { color: var(--danger); }

.inv-card-out { border-left: 3px solid var(--danger); }
.inv-card-low { border-left: 3px solid #f59e0b; }
.inv-card-inactive { opacity: .55; }
.inv-threshold { font-size: 12px; color: #d97706; }

/* ===== Card ===== */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

/* ===== Info card ===== */
.info-card { margin-bottom: 1.5rem; }

.info-list {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: .5rem 1rem;
}
.info-list dt { font-weight: 600; color: var(--muted); }
.muted { color: var(--muted); }

/* ===== Login page ===== */
.login-wrap {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    min-height: 80vh;
    padding-top: 5rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.25rem 2rem;
    box-shadow: 0 4px 24px rgba(0,0,0,.08);
}

.login-logo {
    display: flex;
    justify-content: center;
    margin-bottom: .75rem;
    color: var(--primary);
}

.login-title {
    text-align: center;
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: .2rem;
    letter-spacing: -.01em;
}

.login-subtitle {
    text-align: center;
    color: var(--muted);
    font-size: .9rem;
    margin-bottom: 1.75rem;
}

.login-card .form { max-width: 100%; }

/* ===== Forms ===== */
.form { max-width: 560px; }

.form-group { margin-bottom: 1.1rem; }

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: .35rem;
    font-size: .95rem;
    color: var(--text);
}

.form-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: .65rem .9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    background: var(--card-bg);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
    min-height: 48px;
}
.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-input:disabled { background: #f3f4f6; color: var(--muted); }
select.form-input { cursor: pointer; appearance: auto; }

.form-actions {
    display: flex;
    gap: .75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.form-activate { margin-top: .75rem; }

/* ===== Home — today summary ===== */
.home-today {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: .85rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.home-today-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .75rem;
}

.home-today-title {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
}

.home-today-link {
    font-size: .8rem;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
.home-today-link:hover { text-decoration: underline; }

.home-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 2fr;
    gap: .5rem;
}

.home-stat {
    text-align: center;
    padding: .4rem .25rem;
    border-radius: 6px;
}

.home-stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.02em;
}

.home-stat-accent .home-stat-value {
    color: var(--success);
    white-space: nowrap;
}

.home-stat-masked .home-stat-value {
    filter: blur(6px);
    user-select: none;
    -webkit-user-select: none;
}

.home-stat[onclick] { cursor: pointer; }

.home-eye-icon {
    display: inline-flex;
    vertical-align: middle;
    opacity: .55;
    margin-left: .2rem;
}

.home-stat-label {
    font-size: .7rem;
    color: var(--muted);
    margin-top: .2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .15rem;
}

/* Revenue breakdown (cash vs. debt) shown inside the revenue stat tile */
.home-stat-breakdown {
    display: flex;
    gap: .5rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: .35rem;
}
.home-stat-masked .home-stat-breakdown { filter: blur(6px); user-select: none; -webkit-user-select: none; }
.home-stat-breakdown-item {
    font-size: .68rem;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

/* Customer debt warning in export order form */
.cust-debt-warning {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: var(--radius);
    padding: .3rem .6rem;
    font-size: .85rem;
    color: #92400e;
}

/* Debt badge in ps-item dropdown rows */
.ps-item-debt {
    font-size: .75rem;
    font-weight: 700;
    color: var(--danger);
}


/* ===== Home — recent history section headers ===== */
.home-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 1rem 0 .4rem;
}
.home-section-title {
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}
.home-section-link {
    font-size: .8rem;
    color: var(--primary);
    text-decoration: none;
}

/* ===== Home — primary action cards (Nhập / Xuất) ===== */
.home-primary-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .6rem;
    margin-bottom: .6rem;
}

.home-cta {
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .9rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
    transition: background .1s;
    user-select: none;
}
.home-cta:active { background: #f0f1f2; transform: scale(.98); }

.home-cta-icon {
    width: 38px;
    height: 38px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.home-cta-text { display: flex; flex-direction: column; gap: .05rem; min-width: 0; }
.home-cta-label { font-size: .9rem; font-weight: 700; line-height: 1.2; }
.home-cta-sub   { font-size: .7rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.home-cta-import { border-left-color: var(--primary); }
.home-cta-import .home-cta-icon { background: #eff6ff; color: #2563eb; }
.home-cta-export { border-left-color: var(--success); }
.home-cta-export .home-cta-icon { background: #f0fdf4; color: #16a34a; }

/* ===== Home — secondary navigation grid ===== */
.home-nav-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .5rem;
    margin-bottom: .75rem;
}

.home-nav-item {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .6rem .85rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    font-size: .875rem;
    font-weight: 600;
    transition: background .1s;
    user-select: none;
}
.home-nav-item:active { background: #f0f1f2; }

.home-nav-icon {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.home-nav-inventory .home-nav-icon { background: #ecfeff; color: #0e7490; }
.home-nav-debt      .home-nav-icon { background: #fef2f2; color: #991b1b; }
.home-nav-products  .home-nav-icon { background: #f5f3ff; color: #5b21b6; }
.home-nav-audit     .home-nav-icon { background: #f3f4f6; color: var(--muted); }


/* ===== Coloured text ===== */
.import-text        { color: #2563eb; font-variant-numeric: tabular-nums; }
.export-text        { color: #16a34a; font-variant-numeric: tabular-nums; }
.debt-text          { color: #dc2626; font-variant-numeric: tabular-nums; }
.supplier-debt-text { color: #d97706; font-variant-numeric: tabular-nums; }

/* ===== Transaction cards ===== */
.table-desktop { display: none; }

.tx-cards {
    display: flex;
    flex-direction: column;
    gap: .45rem;
    margin-bottom: .75rem;
}

.tx-card {
    display: block;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: var(--radius);
    padding: .85rem 1rem;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
    color: inherit;
    text-decoration: none;
}
a.tx-card:active { background: #f0f1f2; }

.tx-card-export  { border-left-color: #16a34a; }
.tx-card-import  { border-left-color: #2563eb; }
.tx-card-totals  { background: var(--bg); }

.tx-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: .3rem;
    gap: .5rem;
}

.tx-card-name {
    font-weight: 700;
    font-size: 14px;
    line-height: 1.3;
    flex: 1;
}

.tx-card-date {
    font-size: 10px;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.tx-card-sub {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: .4rem;
}

.tx-card-foot {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .5rem;
    margin-top: .35rem;
}

.tx-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .2rem .4rem;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.tx-card-amount {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.01em;
    white-space: nowrap;
    flex-shrink: 0;
}

.tx-card-unit { font-size: .8rem; }

.tx-card-debt {
    font-size: .8rem;
    font-weight: 600;
    color: var(--danger);
}
.tx-card-meta .tx-card-debt { width: 100%; }

.tx-empty {
    text-align: center;
    color: var(--muted);
    padding: 1.5rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .95rem;
}

/* ===== Overview grid ===== */
.overview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.75rem;
}
@media (max-width: 600px) { .overview-grid { grid-template-columns: 1fr; } }

.overview-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
}

.overview-stock { border-left: 4px solid var(--primary); }

.ov-label {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    margin-bottom: .4rem;
}

.ov-big {
    font-size: 3rem;
    font-weight: 900;
    color: var(--primary);
    line-height: 1;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.03em;
}

.ov-sub {
    font-size: .95rem;
    color: var(--muted);
    margin-top: .15rem;
    margin-bottom: .85rem;
}

.ov-detail { display: flex; gap: .5rem; flex-wrap: wrap; }

.ov-pill {
    display: inline-block;
    padding: .2rem .65rem;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 600;
    text-decoration: none;
}
.pill-ok   { background: #dcfce7; color: #166534; }
.pill-warn { background: #fef3c7; color: #92400e; }

/* Quick links */
.quick-links {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .6rem;
    margin-top: .75rem;
}
.quick-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: .65rem .5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: .9rem;
    gap: .35rem;
    transition: background .12s;
}
.quick-btn:hover    { background: #e5e7eb; }
.quick-import       { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.quick-import:hover { background: #dbeafe; }
.quick-export       { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.quick-export:hover { background: #dcfce7; }

/* ===== Net badge ===== */
.net-badge {
    display: inline-block;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: .9rem;
}
.net-positive { background: #dcfce7; color: #166534; }
.net-negative { background: #fee2e2; color: #991b1b; }
.net-zero     { background: #f3f4f6; color: var(--muted); }

/* ===== Section header ===== */
.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: .1rem;
}
.view-all-link {
    font-size: .85rem;
    color: var(--primary);
    text-decoration: none;
}
.view-all-link:hover { text-decoration: underline; }

.recent-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 1.75rem;
}
@media (max-width: 680px) { .recent-grid { grid-template-columns: 1fr; } }

.view-all {
    text-align: right;
    margin-top: .5rem;
    font-size: .9rem;
}
.view-all a { color: var(--primary); text-decoration: none; }
.view-all a:hover { text-decoration: underline; }

.nowrap { white-space: nowrap; }

/* ===== Period tabs (statistics) ===== */
.period-tabs {
    display: flex;
    background: var(--border);
    border-radius: calc(var(--radius) + 3px);
    padding: 3px;
    gap: 3px;
    margin-bottom: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.period-tabs::-webkit-scrollbar { display: none; }

.period-tab {
    flex-shrink: 0;
    padding: .45rem .85rem;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    font-size: .88rem;
    white-space: nowrap;
    border: none;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, box-shadow .15s, color .15s;
}
.period-tab:hover { color: var(--text); }
.period-tab-active {
    color: var(--text);
    background: var(--card-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

/* ===== Top list ===== */
.top-list {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: top-counter;
}

.top-list-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .5rem 0;
    border-bottom: 1px solid var(--border);
    counter-increment: top-counter;
}
.top-list-item:last-child { border-bottom: none; }

.top-list-item::before {
    content: counter(top-counter);
    min-width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: .75rem;
    font-weight: 700;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.top-list-item:first-child::before { background: #fef9c3; border-color: #fbbf24; color: #92400e; }
.top-list-item:nth-child(2)::before { background: #f1f5f9; border-color: #94a3b8; color: #475569; }
.top-list-item:nth-child(3)::before { background: #fff7ed; border-color: #fdba74; color: #7c2d12; }

.top-list-name { font-weight: 500; font-size: 14px; line-height: 1.3; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); text-decoration: none; }
a.top-list-name:hover { color: var(--primary); }
.top-list-right { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; }
.top-list-amount { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.top-list-sub { font-size: 11px; color: var(--muted); white-space: nowrap; margin-top: 1px; }

/* ===== Daily breakdown ===== */
.daily-section { margin-bottom: 1rem; }

.daily-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    text-align: left;
}
.daily-toggle:hover { background: var(--bg); }
.daily-arrow { font-size: .8rem; color: var(--muted); }

.daily-body {
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    overflow: hidden;
}
.daily-body .table-wrapper { margin: 0; }
.daily-body .table { border-radius: 0; box-shadow: none; }

/* ===== Drill-down links ===== */
.stats-links {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    margin-top: 1.25rem;
    margin-bottom: .5rem;
}

.stats-link {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .85rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    font-size: .97rem;
    transition: background .1s;
}
.stats-link::after { content: "→"; margin-left: auto; color: var(--muted); }
.stats-link:hover { background: var(--bg); }
.stats-link-export { border-left: 3px solid #16a34a; }
.stats-link-import { border-left: 3px solid #2563eb; }

/* ===== Form helpers ===== */
.label-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: .35rem;
}
.label-row label { margin-bottom: 0; }

.link-hint {
    font-size: .85rem;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
}
.link-hint:hover { text-decoration: underline; }

.field-hint {
    display: block;
    font-size: .8rem;
    color: var(--muted);
    margin-top: .3rem;
}

.label-optional {
    font-size: .8rem;
    font-weight: 400;
    color: var(--muted);
}

.empty-hint {
    padding: .85rem 1rem;
    background: #fef9c3;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    color: #92400e;
    font-size: .95rem;
}
.empty-hint a { color: #92400e; font-weight: 700; }

/* ===== Order form ===== */
.form-section {
    border-bottom: 1px solid var(--border);
    padding-bottom: 1.25rem;
    margin-bottom: 1.25rem;
}
.form-section:last-child { border-bottom: none; margin-bottom: 0; }

.form-section-title,
.form-section-label {
    font-size: .78rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: .75rem;
}

.form-row-2 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1rem;
}
@media (max-width: 560px) { .form-row-2 { grid-template-columns: 1fr; } }
.initial-payment-row { margin-top: 1rem; }

/* Table foot totals */
tfoot .totals-row td {
    border-top: 2px solid var(--border);
    padding-top: .85rem;
    font-size: 1rem;
}

/* ===== KPI cards ===== */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}

.kpi-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.kpi-label {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: .05em;
    margin-bottom: .3rem;
}

.kpi-value {
    font-size: clamp(.82rem, 3.2vw, 1.45rem);
    font-weight: 800;
    line-height: 1.2;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: -.02em;
    overflow-wrap: anywhere;
}

.kpi-sub {
    font-size: .78rem;
    color: var(--muted);
    margin-top: .25rem;
}

.kpi-revenue { border-left: 3px solid #16a34a; }
.kpi-cost    { border-left: 3px solid #dc2626; }
.kpi-profit  { border-left: 3px solid #2563eb; }
.kpi-revenue .kpi-value { color: #16a34a; }
.kpi-cost    .kpi-value { color: #dc2626; }
.kpi-profit  .kpi-value { color: #2563eb; }

@media (max-width: 800px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px)  { .kpi-row { grid-template-columns: 1fr; } }

/* ===== Stats two-column grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75rem;
    margin-bottom: 1rem;
}
@media (max-width: 700px) { .stats-grid { grid-template-columns: 1fr; } }

.stats-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    margin-bottom: 1rem;
}
.stats-grid .stats-card { margin-bottom: 0; }
.stats-card .section-title { margin-bottom: .75rem; }

.stats-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .6rem;
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--border);
}
.stats-card-title { font-size: 14px; font-weight: 600; color: var(--text); }
.stats-card-link  { font-size: 12px; color: var(--primary); white-space: nowrap; }

.section-subtitle {
    font-size: .75rem;
    font-weight: 400;
    color: var(--muted);
    text-transform: none;
    letter-spacing: 0;
}

/* ===== Rank badge ===== */
.rank-num {
    display: inline-flex;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    font-size: .72rem;
    font-weight: 700;
    background: #e5e7eb;
    color: var(--muted);
    flex-shrink: 0;
}
.rank-1 { background: #fef3c7; color: #92400e; }
.rank-2 { background: #f1f5f9; color: #374151; }
.rank-3 { background: #fde8d4; color: #9a3412; }

/* ===== Product name/code ===== */
.prod-name { font-weight: 600; line-height: 1.3; }
.prod-code { font-size: .78rem; color: var(--muted); }

/* ===== Low stock colours ===== */
.stock-low      { color: #d97706; }
.stock-critical { color: #dc2626; }

/* ===== Alert cards ===== */
.alert-card {
    border-left: 3px solid #ef4444;
}
.alert-card-warn {
    border-left: 3px solid #f59e0b;
}
.alert-card-head {
    margin-bottom: .75rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--border);
}
.alert-card-label {
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin-bottom: .2rem;
}
.alert-card-total {
    font-size: 16px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.01em;
    color: #ef4444;
}
.alert-card-supplier .alert-card-total { color: #d97706; }
.alert-card-footer { margin-top: .75rem; }
.alert-card-supplier {
    border-left: 3px solid #f59e0b;
}

/* ===== Debtor/low-stock lists ===== */
.debtor-list, .low-stock-list { margin-bottom: .25rem; }

.debtor-row, .low-stock-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .45rem 0;
}
.debtor-row    { border-bottom: 1px solid var(--border); }
.low-stock-row { border-bottom: 1px solid var(--border); }
.debtor-row:last-child, .low-stock-row:last-child { border-bottom: none; }

.debtor-name   { font-weight: 500; font-size: .875rem; color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.debtor-amount { font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; padding-left: .5rem; }
.low-stock-name { font-weight: 500; font-size: .875rem; flex: 1; min-width: 0; }
.low-stock-qty  { font-size: .85rem; font-weight: 600; white-space: nowrap; color: #d97706; }

.debtor-info { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.debtor-right { display: flex; align-items: center; gap: .6rem; flex-shrink: 0; }
.debtor-meta { font-size: .8rem; color: var(--muted); }
.debtor-pay-btn { white-space: nowrap; }

/* ===== Payment breakdown ===== */
.pay-breakdown { padding: .25rem 0; }

.pay-method-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .7rem 0;
    border-bottom: 1px solid var(--border);
}
.pay-method-row:last-child { border-bottom: none; }

.pay-method-name  { font-weight: 600; }
.pay-method-count { font-size: .82rem; color: var(--muted); margin-top: .1rem; }
.pay-method-rev   { font-weight: 700; color: var(--success); font-size: 1rem; }

/* ===== hide-desktop / hide-mobile utilities ===== */
.hide-desktop { display: none; }

/* ===== Filter bar ===== */
.filter-bar {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .65rem .75rem;
    margin-bottom: .75rem;
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.filter-fields {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    flex: 1;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    min-width: 130px;
    flex: 1;
}

.filter-field label {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.filter-field .form-input {
    padding: .35rem .6rem;
    font-size: 14px;
    min-height: 36px;
    border-radius: 6px;
}

.filter-actions {
    display: flex;
    gap: .4rem;
    align-items: flex-end;
}
.filter-actions .btn {
    height: 36px;
    min-height: 36px;
    padding: 0 .85rem;
    font-size: 14px;
}

.filter-summary {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    align-items: center;
    padding: .35rem .1rem;
    margin-bottom: .5rem;
    font-size: .95rem;
    color: var(--muted);
}
.filter-summary strong { font-variant-numeric: tabular-nums; }
.filter-summary-sep { color: var(--muted); }
.csv-link { color: var(--primary); font-size: 12px; white-space: nowrap; text-decoration: none; margin-left: auto; }
.csv-link:hover { text-decoration: underline; }

/* ===== Custom date range form ===== */
.custom-date-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: .65rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .75rem 1rem;
    margin-bottom: 1rem;
}
.custom-date-form .filter-field { min-width: 150px; flex: 1; }
@media (max-width: 480px) {
    .custom-date-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .custom-date-form .filter-field { min-width: 0; }
    .custom-date-form .btn { grid-column: 1 / -1; justify-content: center; }
}

/* ===== Pay-order cards ===== */
.pay-order-cards { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }
.pay-order-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; }
.pay-order-head { display: flex; flex-wrap: wrap; gap: .35rem .5rem; align-items: center; margin-bottom: .65rem; }
.pay-order-date { font-weight: 600; font-size: .9rem; }
.pay-order-name { font-size: .9rem; flex: 1; }
.pay-order-debt { font-size: .9rem; font-weight: 700; margin-left: auto; }

/* ===== Pagination ===== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: .75rem;
    padding: 1rem 0;
}

.page-info {
    font-size: .9rem;
    color: var(--muted);
    font-weight: 500;
}

/* ===== Product search combobox ===== */
.product-search { position: relative; }

.ps-dropdown {
    display: none;
    position: absolute;
    top: 100%; left: 0; right: 0;
    background: var(--card-bg);
    border: 1.5px solid var(--primary);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 220px;
    overflow-y: auto;
    z-index: 200;
    box-shadow: 0 6px 16px rgba(0,0,0,.1);
    -webkit-overflow-scrolling: touch;
}
.ps-dropdown.open { display: block; }

.ps-item {
    padding: .75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    -webkit-tap-highlight-color: transparent;
}
.ps-item:last-child { border-bottom: none; }
.ps-item:active, .ps-item:hover { background: var(--bg); }

.ps-item-name { font-size: 1rem; font-weight: 600; color: var(--text); }
.ps-item-meta { display: flex; justify-content: space-between; align-items: center; margin-top: .1rem; }
.ps-item-code { font-size: .8rem; color: var(--muted); }
.ps-item-stock { font-size: .75rem; color: var(--success); }
.ps-item-stock-empty { color: var(--danger); }

.stock-hint { display: block; font-size: .8rem; margin-top: .2rem; color: var(--success); }
.stock-hint-empty { color: var(--danger); }

/* htmx loading state for buttons with hx-indicator="this" */
button.htmx-request { opacity: .65; pointer-events: none; }

.ps-empty {
    padding: .75rem 1rem;
    color: var(--muted);
    font-size: .9rem;
    text-align: center;
}

/* ===== Summary list (replaces debt-summary grid) ===== */
.summary-list {
    padding: 0;
    margin: .75rem 0 1rem;
    overflow: hidden;
}
.summary-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .6rem 1rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
}
.summary-row:last-child { border-bottom: none; }
.summary-row-alert { background: #fff8f8; }
.summary-label {
    font-size: 13px;
    color: var(--muted);
    flex-shrink: 0;
}
.summary-value {
    font-size: 14px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    text-align: right;
}

/* ===== Multi-step form wizard ===== */
.step-indicator {
    display: flex;
    align-items: flex-start;
    margin-bottom: 1.25rem;
}
.step-dot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .3rem;
    flex: 0 0 auto;
    width: 64px;
}
.step-dot-circle {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .82rem;
    font-weight: 700;
    color: var(--muted);
    transition: background .2s, border-color .2s, color .2s;
}
.step-dot.active .step-dot-circle {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}
.step-dot.done .step-dot-circle {
    border-color: var(--success);
    background: var(--success);
    color: #fff;
}
.step-dot-label {
    font-size: .7rem;
    color: var(--muted);
    text-align: center;
    white-space: nowrap;
}
.step-dot.active .step-dot-label { color: var(--primary); font-weight: 600; }
.step-dot.done   .step-dot-label { color: var(--success); }

.step-connector {
    flex: 1;
    height: 2px;
    background: var(--border);
    margin-top: 14px;
    align-self: flex-start;
    transition: background .2s;
}
.step-connector.done { background: var(--success); }

.form-step { display: none; }
.form-step.active {
    display: block;
    animation: stepFadeIn .18s ease;
}
@keyframes stepFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.step-dot.done { cursor: pointer; }

.step-nav {
    display: flex;
    gap: .75rem;
    margin-top: 1.25rem;
}
.step-nav .btn { flex: 1; justify-content: center; }

.items-summary {
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.items-summary:empty { display: none; }
.summary-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
    padding: .5rem .85rem;
    font-size: .9rem;
    border-bottom: 1px solid var(--border);
}
.summary-line:last-child { border-bottom: none; }
.summary-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.summary-info { color: var(--muted); font-size: .85rem; white-space: nowrap; }

/* ===== Export form: item cards ===== */
.item-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: .85rem;
}

.item-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .75rem;
}

.item-card-label {
    font-weight: 700;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
}

.item-remove-btn {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    padding: .25rem .4rem;
    border-radius: 6px;
    -webkit-tap-highlight-color: transparent;
}
.item-remove-btn:hover,
.item-remove-btn:active { color: var(--danger); background: #fee2e2; }

.item-card-numbers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75rem;
    margin-top: .6rem;
}

.item-card-subtotal {
    grid-column: span 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .6rem .9rem;
    font-size: .95rem;
}
.item-card-subtotal strong { color: var(--success); font-size: 1.05rem; }

/* ===== Safe area for bottom-anchored DaisyUI modals ===== */
.modal-bottom .modal-box {
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
}

/* ===== Sticky grand total bar ===== */
.grand-total-bar {
    position: sticky;
    bottom: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .85rem 1.1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 -2px 8px rgba(0,0,0,.07);
    margin: .5rem 0;
    z-index: 10;
}
.grand-total-label { font-weight: 600; font-size: 1rem; color: var(--muted); }
.grand-total-amount { font-size: 1.4rem; font-weight: 800; color: var(--success); }

/* ===== Inventory stock bar ===== */
.stock-bar-wrap {
    display: flex;
    align-items: center;
    gap: .6rem;
}
.stock-bar {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
    min-width: 40px;
}
.stock-bar-fill {
    height: 100%;
    border-radius: 99px;
    background: var(--success);
    transition: width .3s;
}
.stock-bar-fill.low  { background: #f59e0b; }
.stock-bar-fill.zero { background: var(--border); }

/* ===== Top progress bar (HTMX requests) ===== */
#page-progress {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    left: 0;
    width: 0;
    height: 3px;
    background: var(--primary);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
}
#page-progress.active {
    opacity: 1;
    animation: progress-indeterminate 1.2s ease infinite;
}
@keyframes progress-indeterminate {
    0%   { width: 0;   margin-left: 0; }
    50%  { width: 75%; margin-left: 10%; }
    100% { width: 10%; margin-left: 100%; }
}

/* ===== Submit button loading spinner ===== */
.btn-loading {
    opacity: .75;
    pointer-events: none;
}
.btn-loading::after {
    content: '';
    display: inline-block;
    width: 13px;
    height: 13px;
    margin-left: 7px;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btn-spin .55s linear infinite;
    vertical-align: -2px;
}
.btn:not(.btn-primary):not(.btn-danger).btn-loading::after {
    border-color: rgba(0,0,0,.15);
    border-top-color: var(--text);
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ===== Stats page section dividers ===== */
.tk-section-label {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    margin: 1rem 0 .5rem;
}

.tk-period-range {
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    font-size: .8rem;
    color: var(--text);
}

/* ===== Payment method chips ===== */
.pay-chips-row {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.pay-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .6rem .85rem;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.pay-chip:last-child { border-bottom: none; }
.pay-chip-left { display: flex; align-items: center; gap: .5rem; }
.pay-chip-method { font-weight: 600; color: var(--text); }
.pay-chip-count  { font-size: 12px; color: var(--muted); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 1px 7px; }
.pay-chip-amount { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }

/* ===== Công nợ — segmented tab bar ===== */
.cn-tabs {
    display: flex;
    background: var(--border);
    border-radius: calc(var(--radius) + 3px);
    padding: 3px;
    gap: 3px;
    margin-bottom: 1rem;
}
.cn-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .1rem;
    padding: .55rem .5rem;
    border-radius: var(--radius);
    border: none;
    background: transparent;
    cursor: pointer;
    transition: background .15s, box-shadow .15s, color .15s;
    color: var(--muted);
}
.cn-tab.active {
    background: var(--card-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,.12);
    color: var(--text);
}
.cn-tab-label {
    font-size: .75rem;
    font-weight: 600;
}
.cn-tab-amount {
    font-size: .95rem;
    font-weight: 800;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    letter-spacing: -.01em;
}
.cn-tab-recv.active .cn-tab-amount { color: var(--danger); }
.cn-tab-pay.active  .cn-tab-amount { color: #d97706; }
.cn-tab-zero {
    font-size: .8rem;
    color: var(--muted);
}

/* ===== Công nợ — debt cards ===== */
.cn-list {
    display: flex;
    flex-direction: column;
    gap: .45rem;
    margin-bottom: .75rem;
}
.cn-card-recv { border-left-color: #ef4444; }
.cn-card-pay  { border-left-color: #f59e0b; }
.cn-pay-amount { color: #d97706; font-variant-numeric: tabular-nums; }

/* Age badges */
.cn-age-badge {
    display: inline-block;
    font-size: .68rem;
    font-weight: 700;
    padding: .05rem .35rem;
    border-radius: 999px;
    margin-left: .25rem;
    vertical-align: middle;
}
.cn-age-warn {
    background: #fef3c7;
    color: #92400e;
}
.cn-age-old {
    background: #fee2e2;
    color: #b91c1c;
}

/* ===== Công nợ page search ===== */
.cn-search-wrap {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1rem;
}
.cn-search-input { flex: 1; }
.cn-count { font-size: .85rem; white-space: nowrap; }
.cn-empty-search { padding: .6rem 0 .25rem; font-size: .9rem; }
.cn-capped-notice {
    margin-top: .75rem;
    padding: .6rem .75rem;
    background: #fef9c3;
    border: 1px solid #fde047;
    border-radius: var(--radius);
    font-size: .82rem;
    color: #713f12;
    line-height: 1.5;
}

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
}
.empty-icon  { font-size: 3rem; margin-bottom: .5rem; }
.empty-title { font-size: 1.1rem; font-weight: 700; color: var(--text); margin-bottom: .25rem; }
.empty-sub   { font-size: .9rem; }

/* =============================================================
   MOBILE BREAKPOINT
   ============================================================= */

@media (max-width: 768px) {
    /* Show mobile elements */
    .app-btm-nav { display: flex; }

    /* Main content padding — push above bottom nav + safe area */
    .page-container {
        min-height: calc(100dvh - 56px - env(safe-area-inset-top, 0px));
        padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px) + 1rem);
        padding-left: .85rem;
        padding-right: .85rem;
        padding-top: 1rem;
    }
    .has-header .page-container {
        padding-top: calc(56px + env(safe-area-inset-top, 0px) + 1rem);
    }

    /* Sub-page mode: hide bottom nav, remove its padding from container */
    html.sub-page .app-btm-nav { display: none !important; }
    html.sub-page .page-container { padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)); }
    html.sub-page .app-navbar-mobile .app-nav-end { display: none; }
    html.sub-page .page-title { display: none; }

    /* Hide redundant page-content back buttons on mobile (header has one) */
    html.sub-page .page-back { display: none; }

    /* Hide less-critical table columns */
    .hide-mobile   { display: none !important; }
    .hide-desktop  { display: block !important; }

    /* Make form full-width on mobile */
    .form { max-width: 100%; }

    /* Page title */
    .page-title { font-size: 1.3rem; }

    /* Page header: tighter bottom margin */
    .page-header { margin-bottom: .85rem; }

    /* On sub-pages the title is in the mobile navbar — single lone add button goes full-width */
    html.sub-page .page-header .page-header-actions:only-child > .btn:only-child { width: 100%; justify-content: center; }

    /* Stack form actions — full-width buttons */
    .form-actions { flex-direction: column; }
    .form-actions .btn { flex: 1; justify-content: center; width: 100%; }

    /* Table: tighter padding on mobile */
    .table th { padding: .5rem .6rem; font-size: .82rem; }
    .table td { padding: .55rem .6rem; font-size: .95rem; }

    /* Card: less padding */
    .card { padding: 1rem; }

    /* Section title: less margin */
    .section-title { font-size: 1.1rem; margin: 1.1rem 0 .6rem; }

    /* Filter bar: 2-column grid */
    .filter-bar { flex-direction: column; flex-wrap: nowrap; gap: .5rem; }
    .filter-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .4rem; width: 100%; }
    .filter-field  { min-width: 0; }
    .filter-field:only-child { grid-column: 1 / -1; }
    .filter-field input[type="date"] { min-width: 0; width: 100%; }
    .filter-actions { width: 100%; }
    .filter-actions .btn { flex: 1; justify-content: center; }

    /* Filter summary: smaller */
    .filter-summary { font-size: .88rem; gap: .5rem; }

    /* info-list: narrower label column */
    .info-list { grid-template-columns: 90px 1fr; font-size: .92rem; }

    /* Login */
    .login-wrap { padding-top: 2rem; }
    .login-card { padding: 1.75rem 1.25rem; }

    /* Home stats: tighter */
    .home-stat-value { font-size: 14px; }
    .home-cta { padding: .75rem .85rem; gap: .65rem; }
    .home-cta-icon { width: 32px; height: 32px; border-radius: 7px; }
    .home-cta-icon svg { width: 17px; height: 17px; }
    .home-cta-label { font-size: .82rem; }
    .home-cta-sub { display: none; }

    /* Overview cards: tighter */
    .overview-card { padding: 1.1rem; }
    .ov-big { font-size: 2.4rem; }

    /* KPI cards: tighter */
    .kpi-card { padding: .85rem 1rem; }
    .kpi-value { font-size: 14px; }


    /* Grand total bar: above bottom nav */
    .grand-total-bar {
        bottom: calc(60px + env(safe-area-inset-bottom, 0px) + .5rem);
    }
}

