:root {
    --bg: #f6f8fb;
    --panel: #ffffff;
    --ink: #111827;
    --muted: #64748b;
    --line: #e2e8f0;
    --soft-line: #edf2f7;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --accent: #f59e0b;
    --danger: #dc2626;
    --success: #15803d;
    --shadow: 0 10px 30px rgba(15, 23, 42, .06);
    --radius: 10px;
}

body {
    background: var(--bg);
    color: var(--ink);
    font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14.5px;
    letter-spacing: 0;
    line-height: 1.45;
    min-width: 320px;
    -webkit-tap-highlight-color: transparent;
}

.app-shell {
    display: grid;
    grid-template-columns: 248px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: #0f172a;
    color: #fff;
    padding: 20px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1030;
}

.sidebar-head {
    align-items: center;
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    font-size: 21px;
    font-weight: 700;
    letter-spacing: .01em;
    margin-bottom: 20px;
}

.sidebar nav {
    display: grid;
    gap: 6px;
}

.sidebar nav a {
    color: #dbeafe;
    display: block;
    font-weight: 650;
    padding: 11px 12px;
    border-radius: 10px;
    text-decoration: none;
}

.sidebar nav a:hover {
    background: rgba(255, 255, 255, .1);
}

.alert {
    border-radius: var(--radius);
    border-width: 1px;
}

.main {
    padding: 22px;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.topbar-title {
    align-items: center;
    display: flex;
    gap: 10px;
    min-width: 0;
}

.topbar h1 {
    font-size: 25px;
    font-weight: 750;
    margin: 0;
    overflow-wrap: anywhere;
}

.icon-btn {
    align-items: center;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    display: inline-flex;
    font-size: 22px;
    height: 42px;
    justify-content: center;
    line-height: 1;
    width: 42px;
}

.icon-btn:hover {
    background: #eef7f6;
}

.menu-toggle, .sidebar-close, .sidebar-backdrop {
    display: none;
}

.mobile-bottom-nav {
    display: none;
}

.form-control,
.form-select,
.btn {
    min-height: 44px;
}

.form-control,
.form-select {
    background-color: #fff;
    border-color: #d7e0ea;
    border-radius: 10px;
    color: var(--ink);
    padding: 10px 12px;
}

.form-control:focus,
.form-select:focus {
    border-color: rgba(15, 118, 110, .55);
    box-shadow: 0 0 0 .2rem rgba(15, 118, 110, .12);
}

.form-control::placeholder {
    color: #94a3b8;
}

.form-label {
    color: #334155;
    font-size: 12px;
    font-weight: 750;
    margin-bottom: 5px;
}

.btn {
    border-radius: 10px;
    font-weight: 700;
    padding-left: 14px;
    padding-right: 14px;
}

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
}

.btn-success {
    background: var(--success);
    border-color: var(--success);
}

.btn-outline-primary {
    border-color: rgba(15, 118, 110, .5);
    color: var(--brand-dark);
}

.btn-outline-primary:hover {
    background: var(--brand);
    border-color: var(--brand);
}

.btn-outline-success {
    border-color: rgba(21, 128, 61, .45);
    color: var(--success);
}

.btn-sm {
    border-radius: 9px;
    min-height: 34px;
    padding: 5px 10px;
}

.panel, .metric {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}

.panel h2 {
    font-size: 18px;
    font-weight: 750;
    margin: 0 0 14px;
}

.form-header {
    align-items: flex-start;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.form-header h2 {
    margin-bottom: 2px;
}

.form-header p {
    color: var(--muted);
    margin: 0;
}

.form-actions,
.product-form-actions {
    align-self: end;
    display: grid;
    gap: 8px;
}

.filter-form {
    align-items: end;
}

.filter-actions {
    align-items: end;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.grid {
    display: grid;
    gap: 12px;
}

.metrics {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.metric span {
    color: var(--muted);
    display: block;
}

.metric strong {
    display: block;
    font-size: 24px;
    font-weight: 800;
    margin-top: 6px;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at top left, #dff7f3 0, transparent 34%), var(--bg);
}

.login-card {
    width: min(420px, calc(100vw - 32px));
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 30px;
    box-shadow: 0 22px 60px rgba(15, 23, 42, .12);
}

.install-card {
    width: min(760px, calc(100vw - 32px));
}

.install-checks {
    display: grid;
    gap: 8px;
    margin: 16px 0;
}

.install-check {
    align-items: center;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 10px;
    display: flex;
    gap: 8px;
    padding: 9px 10px;
}

.install-check span {
    border-radius: 999px;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    min-width: 34px;
    padding: 3px 7px;
    text-align: center;
}

.install-check.ok span {
    background: var(--success);
}

.install-check.bad span {
    background: var(--danger);
}

.login-card h1 {
    font-size: 28px;
    margin: 0;
}

.login-card p {
    color: var(--muted);
}

.pos-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 16px;
    align-items: start;
}

.purchase-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(360px, 42%);
    gap: 16px;
    align-items: start;
}

.purchase-totals {
    margin-top: 14px;
}

.search-results {
    display: grid;
    gap: 8px;
    margin-bottom: 12px;
}

.invoice-notice {
    align-items: center;
    background: #ecfdf5;
    border: 1px solid #9be3c4;
    border-radius: 10px;
    color: #075f42;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
    padding: 10px;
}

.invoice-notice[hidden] {
    display: none;
}

.invoice-actions,
.invoice-table-actions {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.customer-combo {
    position: relative;
}

.combo-results {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 14px 30px rgba(15, 23, 42, .12);
    display: grid;
    left: 0;
    margin-top: 4px;
    max-height: 240px;
    overflow-y: auto;
    position: absolute;
    right: 0;
    z-index: 1000;
}

.combo-results:empty {
    display: none;
}

.combo-result {
    background: #fff;
    border: 0;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 12px;
    text-align: left;
}

.combo-result:hover {
    background: #f0fdfa;
}

.combo-result small,
.selected-customer small {
    color: var(--muted);
}

.combo-empty {
    color: var(--muted);
    padding: 10px 12px;
}

.selected-customer {
    align-items: center;
    background: #f8fbfd;
    border: 1px solid var(--line);
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
    padding: 8px 10px;
}

.selected-customer[hidden] {
    display: none;
}

.search-result {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    padding: 12px;
    text-align: left;
}

.search-result:hover {
    background: #f8fafc;
}

.totals {
    display: flex;
    align-items: end;
    justify-content: flex-end;
    gap: 14px;
    flex-wrap: wrap;
}

.totals label {
    width: 140px;
}

.pos-amounts {
    display: grid;
    gap: 2px;
    min-width: 170px;
}

.pos-amounts span {
    color: var(--muted);
}

table {
    min-width: max-content;
}

.table-responsive {
    border-radius: var(--radius);
}

.table {
    margin-bottom: 0;
}

.table > :not(caption) > * > * {
    border-bottom-color: var(--soft-line);
    padding: 12px;
    vertical-align: middle;
}

.table thead th {
    background: #f8fafc;
    color: #475569;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .02em;
    text-transform: uppercase;
}

.table tbody tr:hover {
    background: #fbfdff;
}

.pagination {
    gap: 6px;
    margin-top: 14px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.page-link {
    border-color: var(--line);
    border-radius: 9px;
    color: var(--brand-dark);
    min-width: 38px;
    text-align: center;
}

.page-item:first-child .page-link,
.page-item:last-child .page-link {
    border-radius: 9px;
}

.page-item.active .page-link {
    background: var(--brand);
    border-color: var(--brand);
}

.stock-adjust-form {
    display: grid;
    gap: 7px;
    min-width: 300px;
}

.stock-cards {
    display: none;
}

.stock-pill {
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    border-radius: 999px;
    color: #166534;
    display: inline-flex;
    font-weight: 800;
    justify-content: center;
    min-width: 54px;
    padding: 4px 10px;
}

.stock-pill.is-low {
    background: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

@media (max-width: 900px) {
    body.menu-open {
        overflow: hidden;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        bottom: 0;
        box-shadow: 18px 0 35px rgba(15, 23, 42, .25);
        height: 100dvh;
        left: 0;
        max-width: 86vw;
        overflow-y: auto;
        position: fixed;
        top: 0;
        transform: translateX(-105%);
        width: 290px;
    }

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

    .sidebar-backdrop {
        background: rgba(15, 23, 42, .45);
        bottom: 0;
        left: 0;
        position: fixed;
        right: 0;
        top: 0;
        z-index: 1020;
    }

    body.menu-open .sidebar-backdrop,
    .menu-toggle,
    .sidebar-close {
        display: inline-flex;
    }

    .sidebar nav a {
        font-size: 15px;
        padding: 12px;
    }

    .brand {
        margin-bottom: 0;
    }

    .metrics, .pos-grid, .purchase-grid {
        grid-template-columns: 1fr;
    }

    .metrics {
        gap: 10px;
    }

    .metric {
        padding: 13px;
    }

    .metric strong {
        font-size: 21px;
    }

    .topbar {
        align-items: center;
        background: var(--bg);
        gap: 10px;
        position: sticky;
        top: 0;
        z-index: 1010;
        margin: -18px -18px 14px;
        padding: 12px 14px;
        border-bottom: 1px solid var(--line);
    }

    .topbar h1 {
        font-size: 20px;
    }

    .topbar form {
        white-space: nowrap;
    }

    .main {
        padding: 18px 12px 86px;
    }

    .panel {
        padding: 15px;
    }

    .totals {
        align-items: stretch;
        background: var(--panel);
        border-top: 1px solid var(--line);
        bottom: 58px;
        flex-direction: column;
        left: 0;
        padding: 10px 12px;
        position: sticky;
        right: 0;
        z-index: 900;
    }

    .totals label,
    .totals button {
        width: 100%;
    }

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

    .invoice-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .invoice-table-actions {
        display: grid;
        grid-template-columns: 1fr;
        min-width: 110px;
    }

    .combo-results {
        max-height: 210px;
        position: static;
    }

    .combo-result {
        min-height: 46px;
    }

    .mobile-bottom-nav {
        background: #fff;
        border-top: 1px solid var(--line);
        bottom: 0;
        box-shadow: 0 -10px 24px rgba(15, 23, 42, .08);
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        left: 0;
        position: fixed;
        right: 0;
        z-index: 1005;
    }

    .mobile-bottom-nav a {
        color: var(--ink);
        font-size: 12px;
        font-weight: 700;
        min-height: 58px;
        padding: 9px 4px;
        text-align: center;
        text-decoration: none;
    }

    .mobile-bottom-nav a:hover {
        background: #f0fdfa;
    }

    .pos-grid aside {
        display: none;
    }

    .filter-actions,
    .filter-actions .btn {
        width: 100%;
    }

    .stock-table {
        display: none;
    }

    .stock-cards {
        display: grid;
        gap: 12px;
    }

    .stock-card {
        border: 1px solid var(--line);
        border-radius: var(--radius);
        padding: 14px;
    }

    .stock-card-head {
        align-items: flex-start;
        display: flex;
        gap: 10px;
        justify-content: space-between;
    }

    .stock-card h2 {
        font-size: 16px;
        margin: 0;
    }

    .stock-card p {
        color: var(--muted);
        margin: 3px 0 0;
    }

    .stock-card-metrics {
        display: grid;
        gap: 8px;
        grid-template-columns: 1fr 1fr;
        margin: 12px 0;
    }

    .stock-card-metrics span {
        background: #f8fafc;
        border: 1px solid var(--soft-line);
        border-radius: 10px;
        color: var(--muted);
        padding: 9px;
    }

    .stock-card-metrics strong {
        color: var(--ink);
        display: block;
    }

    .stock-card .stock-adjust-form {
        min-width: 0;
    }
}

@media (max-width: 520px) {
    .topbar {
        align-items: stretch;
        flex-direction: row;
    }

    .topbar-title {
        flex: 1;
        min-width: 0;
    }

    .topbar form {
        display: flex;
        justify-content: flex-end;
        gap: 8px;
        width: auto;
    }

    .topbar form span {
        display: none;
    }

    .topbar .btn {
        min-height: 42px;
    }

    .login-card {
        padding: 22px;
    }

    .panel {
        border-left: 0;
        border-right: 0;
        border-radius: 0;
        margin-left: -12px;
        margin-right: -12px;
    }

    .table-responsive {
        border-radius: 0;
        margin-left: -13px;
        margin-right: -13px;
    }
}
