:root {
    --bg: #fdf3f6;
    --bg-strong: #f8e7ef;
    --panel: #fffafc;
    --card: #fff4f8;
    --ink: #3a2b32;
    --muted: #7a5c67;
    --line: #f1d8e3;
    --wine: #c75d7d;
    --wine-dark: #a84c69;
    --rose: #e7a6bc;
    --gold: #d8b98a;
    --ivory: #fff6fa;
    --green: #3c7b5f;
    --red: #af3d4f;
    --warning: #ca8a2a;
    --shadow: 0 14px 30px rgba(134, 70, 90, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: Arial, sans-serif; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.login-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
}

.login-panel {
    width: min(440px, 90vw);
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(8px);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: var(--shadow);
    padding: 36px 30px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}
.brand-icon {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--wine), #7f3245);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 26px;
    font-weight: 700;
    box-shadow: 0 12px 24px rgba(93, 30, 42, 0.25);
}
.brand-icon-logo {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: inherit;
}
.brand-name {
    font-size: 1.9rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--wine);
}
.brand-subtitle {
    letter-spacing: 0.25em;
    color: var(--rose);
    font-size: 0.72rem;
    font-weight: 700;
}

.app-shell {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.sidebar {
    width: 260px;
    min-width: 260px;
    background: #ff1d8d;
    border-right: 1px solid #e8197f;
    padding: 24px 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    align-self: flex-start;
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 8px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.22);
}
.brand-block .brand-icon {
    width: 64px;
    height: 64px;
    font-size: 20px;
    background: #fff;
    border-radius: 12px;
    padding: 5px;
    flex: 0 0 64px;
    display: grid;
    place-items: center;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.08);
}
.brand-block .brand-icon-logo {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
    border-radius: 8px;
}
.login-brand .brand-logo-mark {
    display: block;
    width: 86px;
    height: 86px;
    flex: 0 0 86px;
    object-fit: contain;
}
.brand-block .brand-name {
    font-size: 1.05rem;
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
    overflow: visible;
}
.nav-item {
    display: block;
    padding: 9px 12px;
    border-radius: 12px;
    color: #fceaf3;
    font-weight: 600;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}
.nav-item:hover, .nav-item.active {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.18);
    color: #ffffff;
}
.user-card {
    margin-top: auto;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 6px 18px rgba(92, 34, 40, 0.08);
}
.user-name {
    font-weight: 700;
    margin-bottom: 4px;
    color: #fff;
}
.user-role {
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 8px;
    text-transform: capitalize;
}
.user-card .btn { min-height: 32px; padding: 6px 10px; border-radius: 8px; font-size: 0.84rem; }

.main-content {
    flex: 1;
    padding: 22px 28px 28px;
    min-width: 0;
}
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 12px;
    padding: 6px 0 18px;
    border-bottom: 1px solid var(--line);
}
.eyebrow {
    font-size: 0.72rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 6px;
}
.page-heading {
    margin: 0;
    font-size: clamp(1.8rem, 2vw, 2.5rem);
    color: var(--wine);
}
.topbar-actions { display: flex; gap: 12px; }

.btn {
    border: none;
    border-radius: 12px;
    padding: 10px 18px;
    cursor: pointer;
    font-weight: 700;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn-primary {
    background: linear-gradient(135deg, var(--wine), #7d384d);
    color: #fff;
    box-shadow: 0 10px 22px rgba(93, 30, 42, 0.18);
}
.btn-primary:hover { filter: brightness(1.04); }
.btn-secondary {
    background: #f6eee9;
    color: var(--wine-dark);
    border: 1px solid var(--line);
}
.btn-block { width: 100%; }
.btn-success {
    background: var(--green);
    color: #fff;
}
.btn-danger {
    background: var(--red);
    color: #fff;
}

.content-wrap {
    display: grid;
    gap: 18px;
}
.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 18px;
    margin-bottom: 8px;
}
.summary-card {
    background: linear-gradient(180deg, #ffffff 0%, #fffdf8 100%);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 20px 22px;
    box-shadow: var(--shadow);
}
.summary-label {
    color: var(--muted);
    font-size: 0.8rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 10px;
}
.summary-value {
    font-size: clamp(1.7rem, 2vw, 2.3rem);
    font-weight: 700;
    color: var(--wine);
    margin: 0;
}
.two-col {
    display: grid;
    grid-template-columns: 1.3fr 0.7fr;
    gap: 18px;
}
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 20px;
}
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.panel-title {
    margin: 0;
    font-size: 1.2rem;
    color: var(--wine);
}
.table-wrap {
    overflow: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    padding: 12px 10px;
    border-bottom: 1px solid #f0e5df;
    text-align: left;
    vertical-align: top;
}
th {
    color: var(--muted);
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    background: #faf6f3;
}

.list { list-style: none; margin: 0; padding: 0; }
.list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #f1e6df;
}
.badge {
    background: #f8ece8;
    color: var(--wine);
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.72rem;
    font-weight: 700;
}
.badge.warning { background: #fff0d4; color: var(--warning); }
.badge.success { background: #e7f6ee; color: var(--green); }
.badge.danger { background: #fde7ea; color: var(--red); }

.form-stack {
    display: grid;
    gap: 14px;
}
label {
    display: grid;
    gap: 8px;
    font-size: 0.92rem;
    color: var(--ink);
    font-weight: 600;
}
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 12px;
    padding: 11px 12px;
    color: var(--ink);
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid rgba(93, 30, 42, 0.12);
    border-color: rgba(93, 30, 42, 0.2);
}
.grid-2, .grid-3, .grid-4 {
    display: grid;
    gap: 14px;
}
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 12px;
}
.muted { color: var(--muted); }
.alert {
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 14px;
    font-weight: 600;
}
.alert-success { background: #eaf8ef; color: var(--green); border: 1px solid #cfead9; }
.alert-danger { background: #fdebed; color: var(--red); border: 1px solid #f8d0d7; }

.bill-layout {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 18px;
}
.bill-items {
    border: 1px solid var(--line);
    border-radius: 16px;
    overflow: hidden;
    background: #fff;
}
.small {
    font-size: 0.82rem;
    color: var(--muted);
}
.inline-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.summary-box {
    background: var(--ivory);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 18px;
}
.summary-box .line {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px dashed var(--line);
}
.summary-box .line:last-child { border-bottom: 0; }
.total-row {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--wine);
}

@media (max-width: 980px) {
    .app-shell { display: block; }
    .sidebar { position: static; width: 100%; min-width: 0; height: auto; border-right: none; border-bottom: 1px solid var(--line); }
    .two-col, .bill-layout { grid-template-columns: 1fr; }
    .summary-grid { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
}

@media (max-width: 900px) {
    .sales-history-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .main-content { padding: 18px 16px 24px; }
    .summary-grid, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .topbar { flex-direction: column; align-items: flex-start; }
}

@media print {
    .sidebar, .topbar, .topbar-actions, .no-print, .btn, form, .panel:not(.print-panel) { display: none !important; }
    body { background: #fff; }
    .main-content { padding: 0; }
    .print-panel { display: block !important; }
    .thermal-box {
        width: 100%;
        max-width: 420px;
        margin: 0 auto;
        font-family: monospace;
        font-size: 12px;
        line-height: 1.5;
    }
}

.search-results {
    display: grid;
    gap: 6px;
    margin-top: 8px;
    max-height: 280px;
    overflow-y: auto;
}
.search-results[hidden] { display: none; }
.search-result {
    display: grid;
    gap: 4px;
    width: 100%;
    padding: 11px 13px;
    text-align: left;
    color: var(--ink);
    background: #fffdfb;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
}
.search-result:hover, .search-result:focus-visible {
    border-color: var(--gold);
    background: var(--ivory);
}
.search-result:disabled { cursor: not-allowed; opacity: 0.62; }
.search-result span { color: var(--muted); font-size: 0.84rem; }
.billing-table { min-width: 1050px; }
.billing-table input { min-width: 82px; padding: 8px; border-radius: 7px; }
.quantity-control { display: flex; align-items: center; gap: 5px; }
.quantity-control input { width: 64px; min-width: 64px; text-align: center; }
.quantity-control button {
    width: 30px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--ivory);
    color: var(--wine);
    font-weight: 700;
    cursor: pointer;
}
.btn-small { padding: 7px 10px; font-size: 0.78rem; }
.payment-summary { align-self: start; }
.save-bill-button { min-height: 48px; font-size: 1rem; }
.purchase-table { width: 100%; min-width: 0; table-layout: fixed; }
.purchase-table th, .purchase-table td { padding: 8px 5px; vertical-align: middle; }
.purchase-table th:nth-child(1) { width: 14%; }
.purchase-table th:nth-child(2) { width: 14%; }
.purchase-table th:nth-child(3) { width: 7%; }
.purchase-table th:nth-child(4) { width: 7%; }
.purchase-table th:nth-child(5) { width: 12%; }
.purchase-table th:nth-child(6) { width: 12%; }
.purchase-table th:nth-child(7) { width: 9%; }
.purchase-table th:nth-child(8) { width: 7%; }
.purchase-table th:nth-child(9) { width: 9%; }
.purchase-table th:nth-child(10) { width: 9%; }
.purchase-table input { width: 100%; min-width: 0; padding: 7px 6px; border-radius: 7px; font-size: 0.84rem; }
.purchase-table td:last-child { white-space: nowrap; }
.purchase-row-amount { white-space: nowrap; font-weight: 700; }
.label-preview {
    width: min(100%, 360px);
    min-height: 170px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    text-align: center;
    border: 1px dashed var(--gold);
    background: #fff;
}
.label-preview code { font: 700 1.1rem monospace; }
.tax-mode-label { margin: 8px 0; }
.field-label { display: block; margin-bottom: 8px; font-size: 0.92rem; font-weight: 600; }
.payment-method-options { display: flex; flex-wrap: wrap; gap: 8px; }
.payment-method-options .active { background: var(--wine); border-color: var(--wine); color: #fff; }
.bill-payment-form { align-content: start; grid-template-rows: max-content max-content; }
.bill-payment-form > .grid-2 { width: 100%; align-items: start; }
.amount-received-input { width: 100%; max-width: 260px; min-width: 0; }
.bill-payment-form .save-bill-button { width: auto; min-width: 165px; align-self: start; justify-self: start; }
.whatsapp-form { display: grid; gap: 8px; max-width: 560px; margin-top: 20px; }
.whatsapp-row { display: grid; grid-template-columns: minmax(180px, 1fr) auto; gap: 10px; align-items: center; }
.whatsapp-row input { min-width: 0; }
.whatsapp-form p { margin: 0; }

.main-content:has(#billing-form) { padding-top: 12px; padding-bottom: 4px; }
.billing-page { gap: 8px; }
.billing-page { min-width: 0; }
.billing-page > .panel { min-width: 0; }
.billing-page .panel { padding: 12px 14px; }
.billing-page .section-heading { margin-bottom: 9px; }
.billing-page label { gap: 5px; }
.billing-page input, .billing-page select { padding: 8px 10px; border-radius: 8px; }
.billing-entry-grid { display: grid; grid-template-columns: 1fr 1.15fr; gap: 18px; align-items: start; }
.billing-entry-grid .grid-2 { gap: 8px; }
.billing-entry-grid .search-results { max-height: 120px; }
.billing-entry-grid .small { min-height: 1em; margin: 6px 0 0; }
.product-lookup { display: flex; align-items: end; gap: 8px; }
.product-lookup label { flex: 1; min-width: 0; }
.product-lookup > .btn { flex: 0 0 auto; }
.product-lookup > .btn.active { background: var(--wine); border-color: var(--wine); color: #fff; }
.scan-mode-feedback { margin: 5px 0 0; }
.barcode-dialog { width: min(560px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 12px; padding: 16px; color: var(--ink); box-shadow: var(--shadow); }
.barcode-dialog::backdrop { background: rgba(18, 14, 15, 0.65); }
.barcode-dialog-content { display: grid; gap: 10px; }
.barcode-dialog .section-heading { margin-bottom: 0; }
.barcode-dialog video { display: block; width: 100%; max-height: 55vh; min-height: 220px; background: #171717; object-fit: cover; border-radius: 8px; }
.barcode-dialog p { margin: 0; }
.billing-items-panel .table-wrap { max-width: 100%; max-height: 240px; overflow: auto; }
.billing-page .billing-table { width: 100%; min-width: 0; table-layout: fixed; }
.billing-page .billing-table th, .billing-page .billing-table td { padding: 7px 6px; vertical-align: middle; }
.billing-page .billing-table th:nth-child(1) { width: 25%; }
.billing-page .billing-table th:nth-child(2) { width: 18%; }
.billing-page .billing-table th:nth-child(3) { width: 12%; }
.billing-page .billing-table th:nth-child(4) { width: 14%; }
.billing-page .billing-table th:nth-child(5) { width: 10%; }
.billing-page .billing-table th:nth-child(6) { width: 12%; }
.billing-page .billing-table th:nth-child(7) { width: 9%; }
.billing-page .billing-table input { min-width: 0; width: 100%; padding: 6px; }
.billing-product-code { display: block; color: var(--muted); font-size: 0.76rem; }
.billing-page .quantity-control { gap: 3px; }
.billing-page .quantity-control input { min-width: 38px; width: 42px; padding: 5px 2px; }
.billing-page .quantity-control button { width: 26px; height: 30px; }
.billing-page .btn { padding: 8px 12px; border-radius: 9px; }
.billing-page .bill-layout { gap: 14px; }
.billing-page .payment-summary { padding: 10px 14px; }
.billing-page .payment-summary .line { padding: 5px 0; }
.billing-page .bill-payment-form { gap: 8px; }
.billing-page .bill-payment-form > .grid-2 { gap: 8px; }
.billing-page .bill-save-actions { align-items: center; }
.purchase-total-row { display: flex; align-items: end; gap: 16px; margin-top: 14px; }
.purchase-total-row label { width: min(100%, 280px); }
.purchase-total-row .small { padding-bottom: 10px; }
.purchase-page { gap: 12px; }
.purchase-page .panel, .purchase-form .panel { min-width: 0; padding: 14px 16px; }
.purchase-page .section-heading { margin-bottom: 10px; }
.purchase-form { min-width: 0; gap: 12px; }
.purchase-form .table-wrap { max-width: 100%; overflow-x: auto; }
.sales-actions { gap: 5px; }
.sales-actions .btn { padding: 6px 8px; font-size: 0.74rem; white-space: nowrap; }
.sales-history-filters {
    display: grid;
    grid-template-columns: minmax(180px, 1.4fr) repeat(2, minmax(130px, 1fr)) minmax(130px, 0.9fr) auto;
    align-items: end;
    gap: 12px;
}
.sales-history-filter-actions { flex-wrap: nowrap; }
.stock-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.stock-actions form { margin: 0; }
.stock-edit-form { display: flex; min-width: 150px; align-items: center; gap: 6px; }
.stock-edit-form input { min-width: 70px; max-width: 92px; padding: 6px 8px; }
.stock-edit-form .btn { padding: 6px 8px; }

@media (max-width: 640px) {
    .quantity-control { gap: 3px; }
    .billing-table { min-width: 900px; }
    .purchase-table { min-width: 900px; }
    .whatsapp-row { grid-template-columns: 1fr; }
    .billing-entry-grid { grid-template-columns: 1fr; }
    .product-lookup { align-items: end; }
    .billing-page .billing-table { min-width: 680px; }
    .purchase-total-row { align-items: stretch; flex-direction: column; }
    .sales-history-filters { grid-template-columns: 1fr; }
}
