/* ─── Tokens ─────────────────────────────────────── */
:root {
    --c-bg: #f0f4f1;
    --c-panel: #ffffff;
    --c-ink: #0e1a12;
    --c-ink2: #3a4a3f;
    --c-muted: #6b7a70;
    --c-line: #dbe5de;
    --c-green: #176b3e;
    --c-green-d: #0f5230;
    --c-green-l: #eaf4ee;
    --c-green-m: #c8e8d4;
    --c-blue: #1d4ed8;
    --c-red: #c0360f;
    --c-red-l: #fef0eb;
    --c-amber: #b45309;
    --c-amber-l: #fef9eb;
    --sidebar: 232px;
    --radius: 10px;
    --shadow: 0 1px 4px rgba(0, 0, 0, .06), 0 4px 20px rgba(0, 0, 0, .07);
    --shadow-lg: 0 8px 48px rgba(0, 0, 0, .16);
}

/* ─── Reset ──────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    font-family: Inter, system-ui, -apple-system, sans-serif;
    background: var(--c-bg);
    color: var(--c-ink);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.55;
}

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

button {
    cursor: pointer;
}

img,
svg {
    display: block;
}

textarea {
    resize: vertical;
}

/* ─── Sidebar ────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar);
    background: #0c1f14;
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    gap: 8px;
    z-index: 30;
    transition: transform .24s cubic-bezier(.4, 0, .2, 1);
    overflow-y: auto;
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 6px 4px 18px;
    border-bottom: 1px solid #1e3828;
    margin-bottom: 6px;
}

.brand-mark {
    width: 40px;
    height: 40px;
    background: #1a7a4a;
    border-radius: 9px;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 800;
    color: #fff;
    letter-spacing: .04em;
    flex-shrink: 0;
}

.brand-eyebrow {
    font-size: 10px;
    font-weight: 700;
    color: #4d7a5e;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.brand-name {
    font-size: 14px;
    font-weight: 700;
    color: #d4ead9;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 148px;
}

.nav-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: #7aaa8d;
    font-size: 13.5px;
    font-weight: 600;
    border-radius: 8px;
    text-align: left;
    transition: background .13s, color .13s;
}

.nav-btn svg {
    flex-shrink: 0;
    opacity: .8;
}

.nav-btn:hover {
    background: #162d1e;
    color: #b8d9c4;
}

.nav-btn.active {
    background: #1a7a4a;
    color: #fff;
}

.nav-btn.active svg {
    opacity: 1;
}

.sidebar-bottom {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid #1e3828;
    display: grid;
    gap: 8px;
}

.meta-date {
    font-size: 11px;
    color: #4d7a5e;
}

.meta-count {
    font-size: 12px;
    font-weight: 700;
    color: #7aaa8d;
}

.mode-badge {
    font-size: 11px;
    font-weight: 700;
    color: #3ecf78;
    background: #0f2b1c;
    padding: 5px 10px;
    border-radius: 20px;
    width: fit-content;
    border: 1px solid #1d4a30;
}

/* ─── Overlay & mobile header ─────────────────────── */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 29;
}

.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 54px;
    background: #0c1f14;
    align-items: center;
    padding: 0 14px;
    gap: 12px;
    z-index: 28;
}

.mobile-menu-btn {
    background: none;
    border: none;
    color: #d4ead9;
    padding: 6px;
    border-radius: 6px;
    display: flex;
}

.mobile-menu-btn:hover {
    background: #1e3828;
}

.mobile-view-title {
    font-size: 16px;
    font-weight: 700;
    color: #d4ead9;
    flex: 1;
}

.mobile-shop-name {
    font-size: 12px;
    color: #4d7a5e;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Shell ──────────────────────────────────────── */
.app-shell {
    margin-left: var(--sidebar);
    min-height: 100vh;
    padding: 28px 26px;
}

/* ─── Page header ────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.page-eyebrow {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--c-muted);
    margin-bottom: 2px;
}

.page-title {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -.4px;
    color: var(--c-ink);
}

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

/* ─── Views ──────────────────────────────────────── */
.view {
    display: none;
}

.active-view {
    display: block;
}

/* ─── Cards ──────────────────────────────────────── */
.card {
    background: var(--c-panel);
    border: 1px solid var(--c-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.card-heading {
    font-size: 13px;
    font-weight: 700;
    color: var(--c-ink2);
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--c-line);
}

/* ─── Fields ──────────────────────────────────────── */
.field-label {
    display: grid;
    gap: 5px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--c-ink2);
}

.field-input {
    width: 100%;
    border: 1.5px solid var(--c-line);
    border-radius: 8px;
    padding: 9px 11px;
    font-size: 14px;
    color: var(--c-ink);
    background: #fff;
    outline: none;
    transition: border-color .14s, box-shadow .14s;
}

.field-input:focus {
    border-color: var(--c-green);
    box-shadow: 0 0 0 3px rgba(23, 107, 62, .11);
}

.field-input::placeholder {
    color: #aabcb2;
}

/* ─── Buttons ────────────────────────────────────── */
.btn-primary,
.btn-ghost,
.btn-danger {
    border: none;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 700;
    transition: background .13s, box-shadow .13s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--c-green);
    color: #fff;
}

.btn-primary:hover {
    background: var(--c-green-d);
    box-shadow: 0 2px 8px rgba(23, 107, 62, .25);
}

.btn-primary:active {
    transform: scale(.98);
}

.btn-ghost {
    background: var(--c-green-l);
    color: var(--c-green-d);
    border: 1px solid var(--c-green-m);
}

.btn-ghost:hover {
    background: #d8efe3;
}

.btn-danger {
    background: var(--c-red-l);
    color: var(--c-red);
    border: 1px solid #f5c8ba;
}

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

.compact {
    padding: 6px 10px;
    font-size: 13px;
}

.full-w {
    width: 100%;
    justify-content: center;
}

.link-btn {
    background: none;
    border: none;
    font-weight: 700;
    font-size: 13px;
    padding: 3px 7px;
    border-radius: 5px;
    cursor: pointer;
}

.link-edit {
    color: var(--c-blue);
}

.link-edit:hover {
    background: #eff3ff;
}

.link-del {
    color: var(--c-red);
}

.link-del:hover {
    background: var(--c-red-l);
}

/* ─── Search box ─────────────────────────────────── */
.search-box {
    border: 1.5px solid var(--c-line);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    outline: none;
    background: #fff;
    color: var(--c-ink);
    transition: border-color .14s;
    width: 220px;
}

.search-box:focus {
    border-color: var(--c-green);
}

/* ─── Table ──────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--c-line);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th {
    background: #f5f8f5;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--c-muted);
    text-align: left;
    padding: 10px 12px;
    white-space: nowrap;
}

td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--c-line);
    vertical-align: middle;
}

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

tbody tr:hover td {
    background: #fafcfa;
}

.row-actions {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
}

.empty-cell {
    text-align: center;
    color: var(--c-muted);
    padding: 36px 12px;
    font-size: 13px;
}

/* ─── Billing layout ─────────────────────────────── */
.billing-layout {
    display: grid;
    grid-template-columns: 1fr 308px;
    gap: 20px;
    align-items: start;
}

.bill-meta-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 14px;
}

.add-item-row {
    display: grid;
    grid-template-columns: 1fr 90px 100px 68px;
    gap: 10px;
    align-items: end;
    margin-bottom: 14px;
}

.grow {
    min-width: 0;
}

.qty-field,
.unit-field {
    min-width: 0;
}

.add-btn {
    height: 40px;
    padding: 0 14px;
}

/* ─── Receipt card ────────────────────────────────── */
.summary-col {
    display: grid;
    gap: 16px;
    position: sticky;
    top: 20px;
}

.receipt-card {
    font-size: 13px;
}

.receipt-shop-name {
    font-size: 16px;
    font-weight: 800;
    text-align: center;
    margin-bottom: 3px;
}

.receipt-shop-detail {
    text-align: center;
    color: var(--c-muted);
    font-size: 11px;
    white-space: pre-line;
}

.receipt-divider {
    border-top: 1px dashed #b8cfc0;
    margin: 10px 0;
}

.receipt-line-item {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 2px 0;
}

.receipt-total-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 18px;
    font-weight: 800;
    border-top: 1px dashed #b8cfc0;
    padding-top: 10px;
    margin-top: 8px;
}

.qr-slot {
    display: grid;
    place-items: center;
    margin-top: 10px;
}

.summary-actions-card {
    display: grid;
    gap: 10px;
}

.balance-strip {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--c-green-l);
    border: 1px solid var(--c-green-m);
    border-radius: 8px;
    padding: 10px 13px;
    font-weight: 700;
    font-size: 15px;
    color: var(--c-ink);
}

/* ─── Inventory form ─────────────────────────────── */
.product-form {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    align-items: end;
}

.product-form .btn-primary {
    min-height: 40px;
}

.tel-wrap {
    display: flex;
    gap: 6px;
}

.tel-input {
    flex: 1;
    min-width: 0;
}

.tel-btn {
    flex-shrink: 0;
}

/* ─── Settings ───────────────────────────────────── */
.settings-layout {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 20px;
    align-items: start;
}

.settings-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    align-items: start;
}

.settings-form>label:nth-child(3) {
    grid-column: span 2;
}

.settings-form>button {
    margin-top: 4px;
}

.settings-info-col {
    display: grid;
    gap: 16px;
}

.info-card {}

.mode-info-text {
    font-size: 13px;
    color: var(--c-ink2);
    margin-top: 8px;
    line-height: 1.6;
}

/* ─── Modal ──────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 20, 12, .65);
    display: grid;
    place-items: center;
    z-index: 40;
    padding: 16px;
}

.modal {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    width: min(460px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-wide {
    width: min(580px, 100%);
}

.modal-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 18px;
}

.modal-title {
    font-size: 19px;
    font-weight: 800;
    margin-top: 2px;
}

.tab-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.tab {
    flex: 1;
    padding: 9px;
    border: 1.5px solid var(--c-line);
    background: transparent;
    font-weight: 600;
    font-size: 13px;
    border-radius: 8px;
    transition: all .13s;
}

.tab.active {
    background: var(--c-green);
    color: #fff;
    border-color: var(--c-green);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.qr-center {
    display: grid;
    place-items: center;
    padding: 20px 0;
}

.hint-text {
    text-align: center;
    font-size: 12px;
    color: var(--c-muted);
    margin-top: 4px;
}

.modal-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--c-line);
    flex-wrap: wrap;
}

.modal-grand-total {
    font-size: 20px;
    font-weight: 800;
}

.modal-foot-actions {
    display: flex;
    gap: 8px;
}

/* Bill detail table */
.detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.detail-table th {
    background: #f5f8f5;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--c-muted);
    padding: 8px 10px;
    text-align: left;
}

.detail-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--c-line);
}

.detail-table tr:last-child td {
    border-bottom: none;
}

/* ─── Badges ─────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
}

.badge-green {
    background: var(--c-green-l);
    color: var(--c-green-d);
}

.badge-red {
    background: var(--c-red-l);
    color: var(--c-red);
}

.badge-amber {
    background: var(--c-amber-l);
    color: var(--c-amber);
}

/* ─── Toast ──────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 20px;
    border-radius: 9px;
    background: #0c1f14;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    z-index: 60;
    box-shadow: var(--shadow-lg);
    white-space: nowrap;
    pointer-events: none;
}

.toast.error {
    background: #991b1b;
}

.toast.warning {
    background: #92400e;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .03em;
}

.status-paid {
    background: #eaf7ef;
    color: #176b3e;
    border: 1px solid #cfe8d8;
}

.status-pending {
    background: #fff4e5;
    color: #b45309;
    border: 1px solid #f5d7a1;
}

.payment-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    background: #eef4ff;
    color: #1d4ed8;
    border: 1px solid #d7e4ff;
}

/* ─── Loader ─────────────────────────────────────── */
.loader-overlay {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(240, 244, 241, .8);
    z-index: 70;
    backdrop-filter: blur(2px);
}

.loader-card {
    display: flex;
    gap: 12px;
    align-items: center;
    background: #fff;
    padding: 16px 24px;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    font-weight: 700;
    font-size: 14px;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 3px solid var(--c-line);
    border-top-color: var(--c-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ─── Utility ────────────────────────────────────── */
.hidden {
    display: none !important;
}

.telugu {
    font-family: 'Noto Sans Telugu', Inter, sans-serif;
}

.muted {
    color: var(--c-muted);
}

.text-sm {
    font-size: 12px;
}

.text-red {
    color: var(--c-red);
}

.text-green {
    color: var(--c-green);
}

/* ─── Responsive ─────────────────────────────────── */
@media (max-width: 960px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-header {
        display: flex;
    }

    .app-shell {
        margin-left: 0;
        padding: 66px 16px 24px;
    }

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

    .summary-col {
        position: static;
    }

    .product-form {
        grid-template-columns: 1fr 1fr;
    }

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

    .settings-info-col {
        grid-template-columns: 1fr 1fr;
        display: grid;
    }
}

@media (max-width: 640px) {
    .bill-meta-row {
        grid-template-columns: 1fr;
    }

    .add-item-row {
        grid-template-columns: 1fr 1fr;
    }

    .add-item-row .grow {
        grid-column: 1/-1;
    }

    .add-item-row .add-btn {
        grid-column: 1/-1;
        width: 100%;
    }

    .product-form {
        grid-template-columns: 1fr;
    }

    .settings-form {
        grid-template-columns: 1fr;
    }

    .settings-form>label:nth-child(3) {
        grid-column: span 1;
    }

    .header-actions {
        width: 100%;
    }

    .header-actions .search-box {
        width: 100%;
    }

    .modal-foot-actions {
        width: 100%;
        flex-direction: column;
    }

    .modal-foot-actions button {
        width: 100%;
    }

    .settings-info-col {
        grid-template-columns: 1fr;
    }

    .page-title {
        font-size: 22px;
    }
}

/* PWA Installation Button */
.pwa-install-btn {
    background: #176b3e;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    margin-right: 8px;
    white-space: nowrap;
}

.pwa-install-btn.hidden {
    display: none;
}

/* Status and Payment Badges */
.status-badge,
.payment-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.status-paid {
    background: #dcfce7;
    color: #166534;
}

.status-pending {
    background: #fef3c7;
    color: #92400e;
}

.payment-badge {
    background: #dbeafe;
    color: #1e40af;
}