:root {
    --green: #14783b;
    --green-dark: #0e5f2e;
    --green-soft: #e3f3e9;
    --gold: #c4a34a;
    --gold-soft: #f5edcf;
    --danger: #b95a5a;
    --ink: #1d2a22;
    --muted: #6f7b73;
    --line: #d9dfda;
    --bg: #eef3ef;
    --panel: #ffffff;
    --shadow: 0 16px 38px rgba(22, 62, 38, .13);
    --shadow-sm: 0 4px 14px rgba(22, 62, 38, .08);
    --radius: 10px;
    --radius-sm: 7px;
    --topbar-h: 74px;
    --transition: .22s ease;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: Tajawal, Arial, sans-serif;
    background:
        linear-gradient(120deg, rgba(20, 120, 59, .12), transparent 38%),
        linear-gradient(240deg, rgba(196, 163, 74, .12), transparent 38%),
        var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

body.nav-open {
    overflow: hidden;
}

button,
input,
select,
textarea {
    font: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Topbar ── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: var(--topbar-h);
    padding: 16px 28px;
    background: radial-gradient(circle at top left, rgba(255,255,255,.14), transparent 35%),
                linear-gradient(90deg, #0f4f2b 0%, #1b7e48 100%);
    color: #fff;
    box-shadow: 0 12px 36px rgba(0, 0, 0, .18);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 18px;
    background: linear-gradient(160deg, #ffd85c, #f4c03f);
    color: #1f281e;
    font-weight: 800;
    font-size: 14px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255,255,255,.35);
    box-shadow: 0 10px 24px rgba(0,0,0,.12);
}

.nav {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    justify-content: center;
    padding: 10px 16px;
    border-radius: 999px;
    background: rgba(255,255,255,.1);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255,255,255,.18);
}

.nav a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 46px;
    padding: 0 20px;
    border-radius: 999px;
    background: rgba(255,255,255,.14);
    color: rgba(255,255,255,.9);
    text-decoration: none;
    font-weight: 700;
    letter-spacing: .3px;
    transition: transform .22s ease, background .22s ease, color .22s ease, box-shadow .22s ease;
}

.nav a:hover,
.nav a.active {
    background: rgba(255,255,255,.36);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, .12);
}

.nav-icon {
    font-size: 16px;
}

.user-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-badge {
    padding: 10px 18px;
    border-radius: 999px;
    background: rgba(255,255,255,.16);
    border: 1px solid rgba(255,255,255,.24);
    color: #fff;
    font-weight: 700;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}

.logout-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 18px;
    border-radius: 999px;
    background: rgba(255,255,255,.14);
    color: #fff;
    border: 1px solid rgba(255,255,255,.22);
    transition: background .22s ease, transform .22s ease;
}

.logout-link:hover {
    background: rgba(255,255,255,.26);
    transform: translateY(-1px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex-shrink: 0;
    color: inherit;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #ffeaa0, var(--gold));
    color: #12341f;
    font-weight: 800;
    font-size: 11px;
    border: 3px solid rgba(255, 255, 255, .45);
}

..brand strong,
.brand small {
    display: block;
    line-height: 1.2;
}

.brand small {
    color: rgba(255, 255, 255, .78);
    font-size: 11px;
}

.nav {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    justify-content: center;
    padding: 10px 16px;
    border-radius: 999px;
    background: rgba(255,255,255,.1);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255,255,255,.18);
}

body.page-login .nav,
body.page-login .menu-toggle,
body.page-login .topbar {
    display: none;
}

.nav a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 46px;
    padding: 0 20px;
    border-radius: 999px;
    background: rgba(255,255,255,.14);
    color: rgba(255,255,255,.9);
    text-decoration: none;
    font-weight: 700;
    letter-spacing: .3px;
    transition: transform .22s ease, background .22s ease, color .22s ease, box-shadow .22s ease;
}

.nav a:hover {
    background: rgba(255,255,255,.36);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, .12);
}

.nav a.active {
    background: linear-gradient(180deg, #fff5d1 0%, #f5db84 50%, var(--gold) 100%);
    color: #1f281e;
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(196, 163, 74, .24);
    border: 1px solid rgba(255,255,255,.35);
}

.nav-icon {
    font-size: 16px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, .15);
    color: #fff;
    cursor: pointer;
    transition: background var(--transition);
}

.menu-toggle:hover {
    background: rgba(255, 255, 255, .25);
}

.menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    position: relative;
    transition: background var(--transition);
}

.menu-toggle span::before,
.menu-toggle span::after {
    content: '';
    position: absolute;
    left: 0;
    width: 20px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: transform var(--transition), top var(--transition);
}

.menu-toggle span::before { top: -6px; }
.menu-toggle span::after  { top: 6px; }

.menu-toggle[aria-expanded="true"] span {
    background: transparent;
}

.menu-toggle[aria-expanded="true"] span::before {
    top: 0;
    transform: rotate(45deg);
}

.menu-toggle[aria-expanded="true"] span::after {
    top: 0;
    transform: rotate(-45deg);
}

.nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(18, 31, 24, .5);
    backdrop-filter: blur(2px);
}

.nav-overlay.visible {
    display: block;
}

/* ── Content ── */
.content {
    width: min(1200px, calc(100% - 32px));
    margin: 20px auto 40px;
    flex: 1;
}

.setup-alert,
.toast {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    animation: slideDown .35s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.setup-alert {
    background: var(--gold-soft);
    border: 1px solid #e1ca77;
}

.toast {
    background: var(--green-soft);
    border: 1px solid #b9dec5;
}

.toast-close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: rgba(20, 120, 59, .15);
    color: var(--green-dark);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

/* ── Layout grids ── */
.page-grid,
.split-layout {
    display: grid;
    gap: 20px;
}

.dashboard-grid,
.customers-grid,
.reports-grid {
    grid-template-columns: minmax(0, 1fr) 270px;
}

.split-layout {
    grid-template-columns: minmax(320px, .88fr) minmax(0, 1.12fr);
}

.main-panel,
.side-panel,
.form-panel,
.list-panel,
.chart-card,
.filter-card {
    background: rgba(255, 255, 255, .96);
    border: 1px solid rgba(217, 223, 218, .9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.main-panel,
.form-panel,
.list-panel {
    padding: 20px;
}

.side-panel {
    padding: 18px;
}

.side-panel h2 {
    margin-bottom: 4px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--green-soft);
}

/* ── Section titles ── */
.section-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.section-title.compact {
    align-items: center;
}

.section-title p {
    margin: 0 0 4px;
    color: var(--muted);
    font-weight: 800;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .3px;
}

h1, h2 {
    margin: 0;
}

h1 { font-size: clamp(20px, 4vw, 26px); }
h2 { font-size: clamp(16px, 3vw, 18px); }

.section-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ── Buttons (design system) ── */
.ui-icon {
    display: block;
    flex-shrink: 0;
}

.btn,
.mini-btn,
.act-btn {
    border: 0;
    border-radius: 10px;
    min-height: 44px;
    padding: 0 18px;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
    line-height: 1;
    transition: transform .16s ease, box-shadow .16s ease, background .16s ease, border-color .16s ease;
}

.btn:hover,
.act-btn:hover {
    transform: translateY(-1px);
}

.btn:active,
.act-btn:active {
    transform: translateY(0) scale(.98);
}

.btn-primary,
.btn.primary {
    background: linear-gradient(180deg, #1a8545 0%, var(--green) 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(20, 120, 59, .28);
}

.btn-primary:hover,
.btn.primary:hover {
    background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%);
    box-shadow: 0 6px 18px rgba(20, 120, 59, .32);
}

.btn-gold,
.btn.gold {
    background: linear-gradient(180deg, #d4b85a 0%, var(--gold) 100%);
    color: #1f281e;
    box-shadow: 0 4px 14px rgba(196, 163, 74, .32);
}

.btn-gold:hover,
.btn.gold:hover {
    background: linear-gradient(180deg, var(--gold) 0%, #b8943f 100%);
}

.btn-ghost,
.btn.muted {
    background: #fff;
    color: var(--ink);
    border: 1.5px solid var(--line);
    box-shadow: none;
}

.btn-ghost:hover,
.btn.muted:hover {
    background: #f5f8f6;
    border-color: #c5cfc8;
}

.btn-danger,
.btn.danger {
    background: linear-gradient(180deg, #c96868 0%, var(--danger) 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(185, 90, 90, .28);
}

.btn-danger:hover,
.btn.danger:hover {
    background: linear-gradient(180deg, var(--danger) 0%, #9e4848 100%);
}

.btn.outline {
    background: #fff;
    border: 2px solid var(--green);
    color: var(--green-dark);
    box-shadow: none;
}

.btn.outline:hover {
    background: var(--green-soft);
}

.mini-btn {
    min-height: 36px;
    padding: 0 14px;
    font-size: 13px;
    border-radius: 8px;
    background: linear-gradient(180deg, #1a8545 0%, var(--green) 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(20, 120, 59, .22);
}

.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.form-actions .btn-primary {
    flex: 1;
    min-width: 180px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.modal-actions .btn {
    flex: 1;
    min-width: 0;
}

/* ── Mobile tabs (shipments) ── */
/* ── Mobile view tabs ── */
.view-tabs,
.mobile-tabs {
    display: none;
    gap: 10px;
    margin-bottom: 16px;
}

.view-tabs button,
.mobile-tabs button {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 16px;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--muted);
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .04);
    transition: all .18s ease;
}

.view-tabs button:hover,
.mobile-tabs button:hover {
    border-color: #c5cfc8;
    color: var(--ink);
}

.view-tabs button.active,
.mobile-tabs button.active {
    background: linear-gradient(180deg, #f5fbf7, var(--green-soft));
    border-color: var(--green);
    color: var(--green-dark);
    box-shadow: 0 4px 14px rgba(20, 120, 59, .14);
}

/* ── Ledger switch (وارد / صادر) ── */
.ledger-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 20px;
}

.ledger-switch-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 88px;
    padding: 16px 18px;
    border-radius: var(--radius);
    border: 2px solid var(--line);
    background: #fff;
    color: var(--ink);
    text-decoration: none;
    overflow: hidden;
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease, background .18s ease;
}

.ledger-switch-btn::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 5px;
    border-radius: 0 4px 4px 0;
    opacity: 0;
    transition: opacity var(--transition);
}

.ledger-switch-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.ledger-switch-icon {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    border-radius: 16px;
    background: #f3f5f4;
    border: 1.5px solid var(--line);
    color: var(--muted);
}

.ledger-switch-icon .ui-icon {
    display: block;
}

.ledger-switch-body {
    display: grid;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.ledger-switch-body strong {
    font-size: clamp(20px, 3.5vw, 24px);
    line-height: 1.1;
}

.ledger-switch-body small {
    color: var(--muted);
    font-weight: 700;
    font-size: 12px;
    line-height: 1.35;
}

.ledger-switch-meta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.ledger-switch-check {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--green);
    color: #fff;
}

.ledger-switch-out.is-active .ledger-switch-check {
    background: var(--gold);
    color: #1f281e;
}

.ledger-switch-count {
    display: grid;
    place-items: center;
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 14px;
    background: rgba(0, 0, 0, .06);
    color: var(--muted);
}

/* صادر — ذهبي */
.ledger-switch-out {
    border-color: #e8d9a8;
}

.ledger-switch-out .ledger-switch-icon {
    background: linear-gradient(145deg, #fffdf5, #fff8e6);
    border-color: #e1ca77;
    color: #9a7b1a;
}

.ledger-switch-out.is-active .ledger-switch-icon {
    background: linear-gradient(145deg, var(--gold), #b8943f);
    border-color: #a88732;
    color: #1f281e;
    box-shadow: 0 4px 12px rgba(196, 163, 74, .35);
}

.ledger-switch-out::before {
    background: var(--gold);
}

.ledger-switch-out.is-active {
    border-color: var(--gold);
    background: linear-gradient(135deg, #fffdf5 0%, #fff8e6 55%, #fff 100%);
    box-shadow: 0 10px 28px rgba(196, 163, 74, .22);
}

.ledger-switch-out.is-active::before {
    opacity: 1;
}

.ledger-switch-out.is-active .ledger-switch-body strong {
    color: #7a6218;
}

.ledger-switch-out.is-active .ledger-switch-count {
    background: var(--gold);
    color: #1f281e;
}

/* وارد — أخضر */
.ledger-switch-in {
    border-color: #b9dec5;
}

.ledger-switch-in .ledger-switch-icon {
    background: linear-gradient(145deg, #f5fbf7, var(--green-soft));
    border-color: #b9dec5;
    color: var(--green-dark);
}

.ledger-switch-in.is-active .ledger-switch-icon {
    background: linear-gradient(145deg, var(--green), var(--green-dark));
    border-color: var(--green-dark);
    color: #fff;
    box-shadow: 0 4px 12px rgba(20, 120, 59, .3);
}

.ledger-switch-in::before {
    background: var(--green);
}

.ledger-switch-in.is-active {
    border-color: var(--green);
    background: linear-gradient(135deg, #f5fbf7 0%, var(--green-soft) 55%, #fff 100%);
    box-shadow: 0 10px 28px rgba(20, 120, 59, .18);
}

.ledger-switch-in.is-active::before {
    opacity: 1;
}

.ledger-switch-in.is-active .ledger-switch-body strong {
    color: var(--green-dark);
}

.ledger-switch-in.is-active .ledger-switch-count {
    background: var(--green);
    color: #fff;
}

.ledger-header {
    text-align: center;
    padding: 16px 12px;
    margin: -20px -20px 18px;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: 3px double var(--line);
}

.ledger-header.compact {
    margin: -20px -20px 14px;
    padding: 12px;
}

.ledger-header-out {
    background: linear-gradient(180deg, #fffdf5, #fff);
}

.ledger-header-in {
    background: linear-gradient(180deg, var(--green-soft), #fff);
}

.ledger-header h1 {
    font-size: clamp(28px, 6vw, 36px);
    letter-spacing: 2px;
    margin-bottom: 4px;
}

.ledger-header p {
    margin: 0;
    color: var(--muted);
    font-weight: 700;
    font-size: 14px;
}

.ledger-form,
.ledger-list {
    border-top: 4px solid var(--green);
}

.ledger-list {
    border-top-color: var(--gold);
}

.ledger-table-wrap {
    border: 2px solid var(--line);
}

.ledger-table th {
    font-size: 13px;
    white-space: nowrap;
}

.ledger-table th:last-child,
.ledger-table td.actions-cell {
    width: 220px;
}

.ledger-table .phone-hint {
    display: block;
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
    margin-top: 2px;
}

.badge {
    display: inline-flex;
    min-width: 52px;
    justify-content: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 12px;
}

.badge-out {
    background: #fff8e6;
    color: #7a6218;
}

.badge-in {
    background: var(--green-soft);
    color: var(--green-dark);
}

.stat-card.gold {
    background: #fff8e6;
}

/* ── Record action toolbar ── */
.actions-cell {
    min-width: 200px;
    vertical-align: middle;
}

.record-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px;
    background: linear-gradient(180deg, #fafcfa, #f3f6f4);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8);
}

.act-btn {
    min-height: 38px;
    padding: 0 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
}

.act-btn:hover {
    transform: none;
}

.act-sms {
    flex: 1;
    min-width: 88px;
    background: linear-gradient(180deg, #d4b85a, var(--gold));
    color: #1f281e;
    box-shadow: 0 2px 8px rgba(196, 163, 74, .3);
}

.act-sms:hover {
    background: linear-gradient(180deg, var(--gold), #b8943f);
    box-shadow: 0 3px 10px rgba(196, 163, 74, .38);
}

.act-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 9px;
}

.act-group .inline-delete {
    display: contents;
}

.act-icon {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
    border-radius: 7px;
    color: var(--muted);
    background: transparent;
}

.act-edit {
    color: #2563b0;
}

.act-edit:hover {
    background: #e8f2ff;
    color: #1a4a8a;
}

.act-delete {
    color: var(--danger);
}

.act-delete:hover {
    background: #fdeaea;
    color: #9e4848;
}

.act-print {
    color: var(--ink);
}

.act-print:hover {
    background: #eef2ef;
    color: var(--green-dark);
}

.edit-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: 10px;
    background: linear-gradient(90deg, #fff8e6, #fffdf5);
    border: 1.5px solid #e1ca77;
    font-weight: 700;
}

.form-panel.is-editing {
    border: 2px solid var(--gold);
    box-shadow: 0 0 0 4px rgba(196, 163, 74, .15);
}

.row-editing {
    background: #fffdf5 !important;
    outline: 2px solid var(--gold);
    outline-offset: -2px;
}

.inline-delete {
    display: inline;
    margin: 0;
}

.modal-subtitle {
    margin: -6px 0 4px;
    color: var(--muted);
    font-weight: 700;
    font-size: 14px;
}

.message-templates {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
}

.template-btn {
    border: 1.5px solid var(--line);
    border-radius: 999px;
    padding: 7px 14px;
    background: #fff;
    color: var(--green-dark);
    font-weight: 800;
    font-size: 12px;
    cursor: pointer;
    transition: all .15s ease;
}

.template-btn:hover {
    background: var(--green-soft);
    border-color: #b9dec5;
}

.modal-panel [readonly] {
    background: #f5f7f5;
    color: var(--muted);
}

/* ── Tables ── */
.table-card {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    -webkit-overflow-scrolling: touch;
}

.table-card::-webkit-scrollbar {
    height: 6px;
}

.table-card::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 3px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

.responsive-table {
    min-width: 720px;
}

.ledger-table.responsive-table {
    min-width: 1100px;
}

th {
    background: var(--green);
    color: #fff;
    font-weight: 800;
    position: sticky;
    top: 0;
    z-index: 1;
}

th,
td {
    padding: 12px 14px;
    border-bottom: 1px solid #edf0ed;
    text-align: right;
    vertical-align: middle;
}

tbody tr {
    transition: background var(--transition);
}

tbody tr:hover {
    background: #f8fbf8;
}

tbody tr:last-child td {
    border-bottom: 0;
}

.status {
    display: inline-flex;
    min-width: 82px;
    justify-content: center;
    padding: 5px 10px;
    border-radius: 999px;
    background: var(--green-soft);
    color: var(--green-dark);
    font-weight: 800;
    font-size: 12px;
}

/* ── Analytics ── */
.analytics {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: 16px;
    margin-top: 18px;
}

.chart-card,
.filter-card {
    padding: 18px;
}

.bar-chart {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    align-items: end;
    gap: 10px;
    height: 180px;
    margin-top: 16px;
    padding: 12px;
    background: repeating-linear-gradient(to top, #edf0ed, #edf0ed 1px, transparent 1px, transparent 32px);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

.bar-chart span {
    display: block;
    border-radius: 4px 4px 0 0;
    background: var(--green);
    transition: height .4s ease;
}

.bar-chart span:nth-child(even) {
    background: var(--gold);
}

.filter-card {
    display: grid;
    align-content: start;
    gap: 14px;
}

/* ── Forms ── */
.filter-card label,
.form-grid label,
.modal-panel label,
.report-filters label {
    display: grid;
    gap: 7px;
    color: var(--ink);
    font-weight: 700;
    font-size: 14px;
}

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid #cfd7d1;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    background: #fff;
    color: var(--ink);
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(20, 120, 59, .12);
    outline: none;
}

input::placeholder,
textarea::placeholder {
    color: #a0aaa4;
}

textarea {
    resize: vertical;
    min-height: 100px;
}

.form-grid,
.report-filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.login-grid {
    min-height: calc(100vh - var(--topbar-h));
    display: grid;
    place-items: center;
    padding: 48px 24px;
    background: radial-gradient(circle at top right, rgba(34, 94, 56, .08), transparent 20%),
                linear-gradient(180deg, #f7fbf8 0%, #e7efe7 100%);
}

.login-panel {
    width: min(580px, 100%);
    padding: 36px 36px 32px;
    border-radius: calc(var(--radius) * 1.4);
    background: rgba(255,255,255,.97);
    box-shadow: 0 30px 80px rgba(20, 80, 40, .14);
    border: 1px solid rgba(30, 90, 40, .09);
    position: relative;
}

.login-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: radial-gradient(circle at top left, rgba(255, 216, 92, .14), transparent 28%);
}

.login-panel,
.login-panel * {
    position: relative;
    z-index: 1;
}

.login-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 26px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(31, 127, 71, .12);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.login-brand .brand-mark {
    width: 64px;
    height: 64px;
    border-radius: 22px;
    font-size: 25px;
    font-weight: 900;
    background: linear-gradient(160deg, #ffd85c, #f4c03f);
    color: #1f281e;
    box-shadow: 0 14px 30px rgba(0,0,0,.14);
    display: grid;
    place-items: center;
}

.login-header h2 {
    margin: 0;
    font-size: 28px;
    letter-spacing: .2px;
}

.login-header p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.6;
}

.login-badge {
    padding: 11px 18px;
    border-radius: 999px;
    background: rgba(31, 127, 71, .14);
    color: #0d3b25;
    font-weight: 800;
    border: 1px solid rgba(31, 127, 71, .2);
}

.login-form {
    grid-template-columns: 1fr;
    gap: 18px;
}

.login-form label {
    font-size: 15px;
}

.login-form input {
    border: 1px solid rgba(31, 92, 56, .16);
    box-shadow: inset 0 2px 8px rgba(22, 94, 47, .04);
}

.login-form input:focus {
    border-color: #1f7f47;
    box-shadow: 0 0 0 4px rgba(31, 127, 71, .12);
}

.form-alert {
    margin-bottom: 18px;
    padding: 16px;
    border-radius: var(--radius-sm);
    background: rgba(185, 90, 90, .14);
    border: 1px solid rgba(185, 90, 90, .3);
    color: var(--danger);
}

.login-panel .actions.form-actions {
    margin-top: 26px;
    padding-top: 0;
    border-top: none;
}
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.filters {
    margin: 0 0 16px;
}

.filters input {
    flex: 1;
    min-width: 160px;
}

.inline-form {
    padding: 16px;
    margin-bottom: 16px;
    border-radius: var(--radius-sm);
    background: #f7faf7;
    border: 1px solid var(--line);
}

.inline-form input,
.inline-form select {
    flex: 1;
    min-width: 130px;
}

.report-filters {
    margin-bottom: 16px;
}

/* ── Stat & person cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.side-panel .stats-grid {
    grid-template-columns: 1fr;
}

.stat-card,
.person-card {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 12px;
    align-items: center;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fffaf0;
    transition: transform var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.stat-card.mint {
    background: var(--green-soft);
}

.stat-card span {
    grid-row: span 2;
    font-size: 28px;
}

.stat-card strong {
    font-size: clamp(18px, 3vw, 22px);
    line-height: 1.2;
}

.stat-card small,
.person-card span,
.person-card small {
    color: var(--muted);
    font-weight: 700;
    font-size: 13px;
}

.person-card {
    grid-template-columns: 1fr;
    background: #fff;
    margin-top: 12px;
}

.person-card strong {
    font-size: 15px;
}

/* ── Modal ── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(18, 31, 24, .45);
    backdrop-filter: blur(3px);
}

.modal.open {
    display: flex;
    animation: fadeIn .2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal-panel {
    position: relative;
    display: grid;
    gap: 14px;
    width: min(540px, 100%);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding: 28px 24px 24px;
    border-radius: var(--radius);
    background: #fff;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .22);
    animation: modalUp .25s ease;
}

@keyframes modalUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.close {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: #f0f2f0;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    transition: background var(--transition);
}

.close:hover {
    background: #e2e6e2;
}

.modal-panel .actions {
    margin-top: 8px;
}

.modal-panel .actions .btn {
    flex: 1;
    min-width: 0;
}

/* ── Empty state ── */
.empty-state {
    padding: 32px 16px;
    text-align: center;
    color: var(--muted);
    font-weight: 700;
}

/* ══════════════════════════════════════
   RESPONSIVE — Tablet (≤ 1024px)
   ══════════════════════════════════════ */
@media (max-width: 1024px) {
    .dashboard-grid,
    .customers-grid,
    .reports-grid {
        grid-template-columns: 1fr;
    }

    .side-panel {
        order: -1;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .side-panel .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

    .analytics {
        grid-template-columns: 1fr;
    }

    .split-layout {
        grid-template-columns: 1fr;
    }

    .view-tabs,
    .mobile-tabs {
        display: flex;
    }

    .ledger-switch {
        gap: 10px;
        margin-bottom: 14px;
    }

    .ledger-switch-btn {
        min-height: 76px;
        padding: 12px 14px;
        gap: 10px;
    }

    .ledger-switch-icon {
        width: 46px;
        height: 46px;
        font-size: 22px;
    }

    .ledger-switch-body small {
        display: none;
    }

    .ledger-switch-count {
        min-width: 30px;
        height: 30px;
        font-size: 12px;
    }

    .split-layout .form-panel.hidden-mobile,
    .split-layout .list-panel.hidden-mobile {
        display: none;
    }
}

/* ══════════════════════════════════════
   RESPONSIVE — Mobile (≤ 768px)
   ══════════════════════════════════════ */
@media (max-width: 768px) {
    :root {
        --topbar-h: 64px;
    }

    .topbar {
        padding: 8px 16px;
        gap: 12px;
    }

    .brand-mark {
        width: 42px;
        height: 42px;
        font-size: 10px;
    }

    .brand small {
        display: none;
    }

    .menu-toggle {
        display: flex;
    }

    .nav {
        position: fixed;
        top: var(--topbar-h);
        right: 0;
        left: 0;
        z-index: 95;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        padding: 12px 16px 20px;
        background: linear-gradient(180deg, var(--green-dark), var(--green));
        box-shadow: 0 12px 30px rgba(4, 42, 20, .3);
        transform: translateY(-110%);
        opacity: 0;
        visibility: hidden;
        transition: transform var(--transition), opacity var(--transition), visibility var(--transition);
    }

    .nav.open {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }

    .nav a {
        min-height: 48px;
        padding: 12px 16px;
        border-radius: var(--radius-sm);
        font-size: 15px;
        color: #fff;
        background: rgba(255,255,255,.08);
        transition: background .2s ease, color .2s ease;
    }

    .nav a:hover,
    .nav a.active {
        color: #1f281e;
        background: linear-gradient(180deg, #f7e5a1 0%, var(--gold) 100%);
        box-shadow: 0 8px 20px rgba(196, 163, 74, .25);
    }

    .content {
        width: 100%;
        max-width: 100%;
        margin-top: 14px;
        margin-bottom: 28px;
        padding: 0 12px;
    }

    .table-card {
        overflow-x: auto;
        max-width: 100%;
    }

    .main-panel,
    .form-panel,
    .list-panel {
        padding: 16px;
    }

    .section-title {
        flex-direction: column;
        align-items: stretch;
    }

    .section-actions {
        width: 100%;
    }

    .section-actions .btn,
    .section-title > .btn {
        flex: 1;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .form-grid,
    .report-filters {
        grid-template-columns: 1fr;
    }

    .actions .btn {
        flex: 1;
        min-width: calc(50% - 5px);
    }

    .inline-form {
        flex-direction: column;
        align-items: stretch;
    }

    .inline-form input,
    .inline-form select {
        width: 100%;
        min-width: 0;
    }

    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filters input,
    .filters select,
    .filters .btn {
        width: 100%;
    }

    /* Card-style tables on mobile */
    .table-card {
        width: 100%;
        max-width: 100%;
    }

    .responsive-table {
        width: 100%;
        min-width: 100%;
    }

    .responsive-table thead {
        display: none;
    }

    .responsive-table tbody tr {
        display: block;
        width: 100%;
        margin-bottom: 12px;
        padding: 14px;
        border: 1px solid var(--line);
        border-radius: var(--radius-sm);
        background: #fafcfa;
        box-sizing: border-box;
    }

    .responsive-table tbody tr:hover {
        background: #f3f8f4;
    }

    .responsive-table tbody tr:last-child {
        margin-bottom: 0;
    }

    .responsive-table td {
        display: block;
        width: 100%;
        padding: 10px 0;
        border-bottom: 1px dashed #e4eae5;
        white-space: normal;
        text-align: right;
        word-break: break-word;
        overflow-wrap: anywhere;
        min-width: 0;
    }

    .responsive-table td:last-child {
        border-bottom: 0;
        padding-top: 10px;
    }

    .responsive-table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 6px;
        font-weight: 800;
        color: var(--muted);
        font-size: 12px;
        white-space: normal;
    }

    .responsive-table td:first-child {
        padding-top: 0;
        padding-bottom: 10px;
        border-bottom: 2px solid var(--green-soft);
        margin-bottom: 4px;
    }

    .responsive-table td:first-child::before {
        display: none;
    }

    .responsive-table td.actions-cell {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .responsive-table td.actions-cell::before {
        align-self: flex-start;
    }

    .record-actions {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        min-width: 0;
    }

    .act-sms {
        width: 100%;
    }

    .act-group {
        width: 100%;
        justify-content: center;
    }

    .ledger-header {
        margin: -16px -16px 14px;
    }

    .ledger-header.compact {
        margin: -16px -16px 12px;
    }

    .bar-chart {
        height: 140px;
        gap: 6px;
    }
    /* Ledger-specific mobile fixes: force ledger tables into card-style rows */
    .ledger-table.responsive-table {
        width: 100% !important;
        min-width: 100% !important;
    }

    .ledger-table.responsive-table thead {
        display: none;
    }

    .ledger-table.responsive-table tbody tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        width: 100%;
        margin-bottom: 12px;
        padding: 12px;
        border: 1px solid var(--line);
        border-radius: calc(var(--radius-sm) + 2px);
        background: linear-gradient(180deg, #ffffff, #fbfdfb);
        box-sizing: border-box;
        transition: box-shadow .18s ease, transform .12s ease;
    }

    .ledger-table.responsive-table tbody tr:hover {
        transform: translateY(-4px);
        box-shadow: 0 10px 30px rgba(20, 120, 59, .06);
    }

    .ledger-table.responsive-table td {
        display: block;
        width: 100%;
        padding: 8px 0;
        border-bottom: 1px dashed #e9efe9;
        text-align: right;
        white-space: normal;
        word-break: break-word;
        overflow-wrap: anywhere;
        font-size: 14px;
    }

    .ledger-table.responsive-table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 6px;
        font-weight: 800;
        color: #6b6f65;
        font-size: 12px;
        opacity: 0.95;
    }

    /* Emphasize key values */
    .ledger-table.responsive-table td strong,
    .ledger-table.responsive-table td .status,
    .ledger-table.responsive-table td .badge {
        display: inline-block;
        color: var(--ink);
        font-weight: 800;
    }

    .ledger-table.responsive-table td:first-child {
        padding-top: 6px;
        padding-bottom: 10px;
        border-bottom: 2px solid var(--green-soft);
        margin-bottom: 6px;
        grid-column: 1 / -1;
    }

    .ledger-table.responsive-table td.actions-cell {
        display: flex;
        gap: 8px;
        flex-wrap: nowrap;
        justify-content: flex-end;
        padding-top: 10px;
        border-bottom: 0;
        grid-column: 1 / -1;
    }

    .ledger-table.responsive-table td.actions-cell .act-btn {
        flex: 0 0 auto;
        min-width: 44px;
        height: 38px;
        padding: 0 10px;
        border-radius: 8px;
    }

    /* Compact the overall panels and headings on small screens */
    .main-panel,
    .form-panel,
    .list-panel {
        padding: 12px;
        border-radius: 10px;
    }

    .ledger-header h1,
    .section-title h1,
    .section-title h2 {
        text-align: center;
        font-size: clamp(18px, 4vw, 24px);
        margin: 4px 0 8px;
    }

    .table-card {
        padding: 8px;
    }

    /* Make action buttons visually consistent */
    .act-btn {
        padding: 8px 10px;
        font-size: 13px;
    }

    .modal {
        padding: 0;
        align-items: flex-end;
    }

    .modal-panel {
        width: 100%;
        max-height: 92vh;
        border-radius: var(--radius) var(--radius) 0 0;
        padding: 24px 18px 18px;
    }

    .modal-panel .actions {
        flex-direction: column;
    }

    .modal-panel .actions .btn {
        width: 100%;
    }
}

/* ══════════════════════════════════════
   RESPONSIVE — Small phones (≤ 420px)
   ══════════════════════════════════════ */
@media (max-width: 420px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card span {
        font-size: 24px;
    }

    .actions .btn {
        min-width: 100%;
    }

    .ledger-switch {
        grid-template-columns: 1fr;
    }

    .ledger-switch-btn {
        min-height: 68px;
    }

    /* Ensure ledger rows stack as single column on very small phones */
    .ledger-table.responsive-table tbody tr {
        grid-template-columns: 1fr !important;
    }

    .ledger-table.responsive-table td.actions-cell .act-btn {
        flex: 1 1 100%;
        min-width: 0;
    }
}

/* ── Print ── */
@media print {
    .topbar,
    .menu-toggle,
    .nav-overlay,
    .mobile-tabs,
    .view-tabs,
    .ledger-switch,
    .record-actions,
    .act-btn,
    .act-group,
    .btn,
    .mini-btn,
    .toast,
    .setup-alert,
    .side-panel,
    .filters,
    .modal {
        display: none !important;
    }

    .content {
        width: 100%;
        margin: 0;
    }

    .main-panel,
    .form-panel,
    .list-panel {
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .responsive-table {
        min-width: 100%;
    }

    .responsive-table thead {
        display: table-header-group;
    }

    .responsive-table tbody tr {
        display: table-row;
        margin: 0;
        padding: 0;
        border: 0;
        background: transparent;
    }

    .responsive-table td {
        display: table-cell;
        text-align: right;
        padding: 8px;
        border-bottom: 1px solid #ddd;
    }

    .responsive-table td::before {
        display: none;
    }
}
