:root {
    --ink: #142033;
    --muted: #4d5d73;
    --paper: #f3f1ea;
    --surface: #fffcf7;
    --navy: #0f2744;
    --topbar-ink: #f4f7fb;
    --line: #d7d1c4;
    --gold: #e8a830;
    --gold-ink: #1c1404;
    --link: #1c4068;
    --nav-active: #efe4c4;
    --ok: #0d6b45;
    --ok-bg: #e5f6ee;
    --warn: #8a4b08;
    --warn-bg: #fff1dc;
    --danger: #8d1d1d;
    --danger-bg: #fde8e8;
    --focus: #0b6bcb;
    --shadow: 0 1px 2px rgba(20, 32, 51, 0.06), 0 10px 28px rgba(20, 32, 51, 0.06);
    --tap: 44px;
    --sidebar: 220px;
    --bottom: 52px;
    --radius: 12px;
    --radius-sm: 8px;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --text-sm: 0.875rem;
    --text-md: 1rem;
    --text-lg: 1.25rem;
    --text-xl: 1.75rem;
    --font: "Segoe UI", system-ui, sans-serif;
    color-scheme: light;
    font-family: var(--font);
}

:root[data-theme="dark"] {
    --ink: #f4f7fb;
    --muted: #c5d0de;
    --paper: #101820;
    --surface: #172433;
    --navy: #0c1c33;
    --topbar-ink: #f4f7fb;
    --line: #31445c;
    --gold: #e8a830;
    --gold-ink: #1c1404;
    --link: #9ecbff;
    --nav-active: #2c3a28;
    --ok: #b6f0d4;
    --ok-bg: #123528;
    --warn: #ffe0b5;
    --warn-bg: #3a2c16;
    --danger: #ffc7c7;
    --danger-bg: #3d1d1d;
    --focus: #9ecbff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
}

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

html,
body,
#app {
    height: 100vh;
    max-height: 100vh;
    margin: 0;
    overflow: hidden;
}

@supports (height: 100svh) {
    html,
    body,
    #app {
        height: 100svh;
        max-height: 100svh;
    }
}

@supports (height: 100dvh) {
    html,
    body,
    #app {
        height: 100dvh;
        max-height: 100dvh;
    }
}

html,
body,
#app {
    height: min(100dvh, var(--vvh, 100dvh));
    max-height: min(100dvh, var(--vvh, 100dvh));
}

body {
    font-size: var(--text-md);
    line-height: 1.4;
    background: var(--paper);
    color: var(--ink);
}

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

button,
.primary,
.ghost,
.nav-link,
.bottomnav a,
.bottomnav button,
input,
select,
textarea {
    min-height: var(--tap);
}

button,
.primary,
.ghost {
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.7rem;
    cursor: pointer;
}

button {
    border: 1px solid transparent;
    background: transparent;
    color: inherit;
}

.primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--gold);
    color: var(--gold-ink);
    border: 1px solid #c48a18;
    text-decoration: none;
    font-weight: 700;
}

.primary:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--topbar-ink);
    border: 1px solid rgba(255, 255, 255, 0.35);
    text-decoration: none;
}

a {
    color: var(--link);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
.nav-link:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

h1,
h2,
h3 {
    line-height: 1.2;
    margin: 0;
    font-weight: 700;
}

h1 {
    font-size: var(--text-lg);
    width: fit-content;
    max-width: 100%;
}

h1:focus {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

h2 {
    font-size: var(--text-md);
}

p {
    margin: 0;
}

.skip-link {
    position: absolute;
    left: var(--space-2);
    top: var(--space-2);
    z-index: 40;
    background: var(--surface);
    color: var(--ink);
    min-height: var(--tap);
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 0.7rem;
    transform: translateY(-160%);
}

.skip-link:focus {
    transform: none;
}

.shell,
.auth-shell {
    height: 100vh;
    max-height: 100vh;
    margin-top: var(--vv-top, 0px);
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--paper);
    color: var(--ink);
}

@supports (height: 100svh) {
    .shell,
    .auth-shell {
        height: 100svh;
        max-height: 100svh;
    }
}

@supports (height: 100dvh) {
    .shell,
    .auth-shell {
        height: 100dvh;
        max-height: 100dvh;
    }
}

.shell,
.auth-shell {
    height: min(100dvh, var(--vvh, 100dvh));
    max-height: min(100dvh, var(--vvh, 100dvh));
}

html[data-viewport="chrome-overflow"],
html[data-viewport="chrome-overflow"] body,
html[data-viewport="chrome-overflow"] #app,
html[data-viewport="chrome-overflow"] .shell,
html[data-viewport="chrome-overflow"] .auth-shell {
    height: auto;
    max-height: none;
    overflow: auto;
}

.topbar,
.auth-bar {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
    padding: var(--space-1) var(--space-2);
    background: var(--navy);
    color: var(--topbar-ink);
}

.auth-bar {
    min-height: var(--tap);
    font-weight: 700;
}

.topbar .brand,
.auth-bar .brand {
    color: var(--topbar-ink);
    font-weight: 700;
    text-decoration: none;
    min-width: var(--tap);
    min-height: var(--tap);
    height: var(--tap);
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 0.15rem;
}

.mark {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.45rem;
    background: var(--gold);
    color: var(--gold-ink);
    display: inline-grid;
    place-items: center;
    font-weight: 750;
}

.tenant-chip,
.status,
.user-name {
    min-height: var(--tap);
    display: inline-flex;
    align-items: center;
    max-width: 100%;
}

.tenant-chip {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    padding: 0 0.7rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status {
    font-size: var(--text-sm);
}

.status[data-online="true"]::before,
.status[data-online="false"]::before {
    content: "";
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    margin-right: 0.35rem;
    background: #8fd9b3;
}

.status[data-online="false"]::before {
    background: #f0b4a2;
}

.spacer {
    flex: 1 1 auto;
}

.nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--topbar-ink);
    border-color: rgba(255, 255, 255, 0.35);
    min-width: var(--tap);
    min-height: var(--tap);
    height: var(--tap);
    padding: 0 0.75rem;
}

.shell-body {
    display: flex;
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.sidenav {
    width: var(--sidebar);
    flex: 0 0 var(--sidebar);
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: var(--space-2);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    overflow: auto;
    scrollbar-width: thin;
}

.nav-link,
.bottomnav a,
.bottomnav button {
    display: flex;
    align-items: center;
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--ink);
}

.nav-link.active,
.bottomnav a.active,
.tabs button[aria-selected="true"] {
    background: var(--nav-active);
    color: var(--ink);
    font-weight: 700;
}

.content {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    padding: var(--space-2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.bottomnav {
    display: none;
}

.banner {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    background: var(--warn-bg);
    color: var(--warn);
}

.banner-offline {
    background: var(--danger-bg);
    color: var(--danger);
}

.card,
.auth-card,
.dialog {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: var(--space-3);
}

.module-note,
.auth-card {
    overflow: auto;
    scrollbar-width: thin;
    min-height: 0;
}

.module-note {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.auth-main {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--space-3);
    overflow: hidden;
}

.auth-card {
    width: min(28rem, 100%);
    max-height: 100%;
    align-self: center;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.auth-card .primary,
.auth-card .sign-in,
.auth-card button,
.auth-card input,
.tenant-list button,
.search-results button {
    width: 100%;
    min-width: var(--tap);
    min-height: var(--tap);
}

.tenant-list,
.search-results,
.cart-lines {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.tenant-list {
    overflow: auto;
    scrollbar-width: thin;
    min-height: 0;
}

.tenant-list button,
.search-results button,
.qty-controls button {
    text-align: left;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
}

.tenant-list button,
.search-results button {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.1rem;
}

.tenant-name {
    font-weight: 700;
}

.tenant-meta,
.hint,
.sync-status {
    color: var(--muted);
    font-size: var(--text-sm);
}

.alert {
    background: var(--danger-bg);
    color: var(--danger);
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-3);
}

.facts {
    display: grid;
    grid-template-columns: minmax(6.5rem, 9rem) minmax(0, 1fr);
    gap: 0.2rem 0.6rem;
    margin: 0;
}

.facts dt {
    color: var(--muted);
}

.facts dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 39, 68, 0.48);
    display: grid;
    place-items: center;
    padding: var(--space-3);
    z-index: 50;
}

.dialog {
    width: min(28rem, 100%);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-height: calc(100dvh - 2rem);
    overflow: auto;
    scrollbar-width: thin;
}

.dialog ol {
    margin: 0;
    padding-left: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.backdrop {
    display: none;
}

.pos-stage {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    overflow: hidden;
}

.pos-bar,
.pos-heading,
.pos-tools,
.pos-dock,
.qty-controls,
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
}

.pos-bar,
.pos-heading {
    flex: 0 0 auto;
    justify-content: space-between;
}

.pos-work,
.pos-grid {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(15rem, 20rem);
    gap: var(--space-2);
}

.pos-main,
.panel,
.totals {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.pos-main,
.panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.panel {
    flex: 1 1 auto;
    overflow: auto;
    min-height: 0;
}

.bill-setup,
.line-tax {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 0.8fr);
    gap: var(--space-2);
}

.bill-setup label,
.line-tax label {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.1rem;
    min-width: 0;
    font-size: var(--text-sm);
    color: var(--muted);
}

.bill-setup select,
.bill-setup input,
.line-tax input {
    width: 100%;
    min-height: var(--tap);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.2rem 0.45rem;
    background: var(--surface);
    color: var(--ink);
}

.line-tax label:first-child {
    flex-direction: row;
    align-items: center;
    min-height: var(--tap);
    color: var(--ink);
}

.line-tax input[type="checkbox"] {
    width: 1.5rem;
    height: 1.5rem;
    min-height: 0;
}

.gstin-field input {
    min-width: 0;
    width: 100%;
}

.discount-entry {
    display: flex;
    gap: var(--space-1);
    align-items: center;
    min-width: 0;
}

.discount-entry input {
    min-width: 0;
    flex: 1 1 auto;
}

.discount-entry select {
    flex: 0 0 3.25rem;
    min-width: var(--tap);
    min-height: var(--tap);
}

@media (max-width: 900px) {
    .bill-setup,
    .line-tax {
        grid-template-columns: 1fr 1fr;
    }

    .gstin-field {
        grid-column: 1 / -1;
    }
}

.search-box {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-1);
}

.search-box input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.65rem;
    background: var(--surface);
    color: var(--ink);
}

.tax-mode {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    margin: 0;
    padding: 0.15rem 0.45rem 0.35rem;
}

.tax-mode legend {
    padding: 0 0.25rem;
    font-size: var(--text-sm);
}

.tax-mode label {
    min-height: var(--tap);
    min-width: var(--tap);
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin-right: var(--space-2);
    padding-right: 0.35rem;
}

.tax-mode input {
    width: 2rem;
    height: 2rem;
    accent-color: var(--navy);
}

.search-results,
.cart-lines,
.totals-scroll,
.scroll-thin {
    overflow: auto;
    scrollbar-width: thin;
    min-height: 0;
}

.search-results {
    flex: 0 1 auto;
    max-height: 34%;
}

.cart-lines {
    flex: 1 1 auto;
}

.cart-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: var(--space-2);
    align-items: center;
    border-radius: var(--radius-sm);
}

.cart-line[aria-selected="true"] {
    background: var(--nav-active);
    padding: 0.2rem 0.35rem;
}

.qty-controls button {
    min-width: var(--tap);
    justify-content: center;
}

.line-amount,
.grand {
    font-weight: 750;
    font-variant-numeric: tabular-nums;
}

.grand {
    margin: 0;
    font-size: var(--text-xl);
    line-height: 1;
}

button.grand {
    background: transparent;
    border: 0;
    color: var(--ink);
    padding: 0 0.2rem;
}

.totals {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
}

.totals-scroll {
    flex: 1 1 auto;
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.pos-dock {
    flex: 0 0 auto;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    border-top: 1px solid var(--line);
    background: var(--surface);
}

.pos-dock .pay,
.totals .primary {
    min-width: 7.5rem;
}

.tabs button {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
}

.sidenav .install-button {
    flex: 0 0 auto;
    width: 100%;
}

@media (max-width: 767px) {
    .wide-only {
        display: none;
    }

    .brand-text {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    .sidenav {
        position: fixed;
        z-index: 25;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(18rem, 86vw);
        transform: translateX(-105%);
        visibility: hidden;
        box-shadow: none;
    }

    .shell.nav-shown .sidenav {
        transform: none;
        visibility: visible;
        box-shadow: var(--shadow);
    }

    .shell.nav-shown .backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 39, 68, 0.35);
        z-index: 20;
        min-height: 100%;
        border: 0;
        border-radius: 0;
    }

    .topbar .install-button {
        display: none;
    }

    .bottomnav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 15;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        background: var(--surface);
        border-top: 1px solid var(--line);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .bottomnav a,
    .bottomnav button {
        justify-content: center;
        border-radius: 0;
        width: 100%;
    }

    .shell {
        padding-bottom: calc(var(--bottom) + env(safe-area-inset-bottom));
    }

    .pos-work,
    .pos-grid,
    .facts {
        grid-template-columns: 1fr;
    }

    .qty-controls {
        flex-wrap: nowrap;
    }

    .cart-lines {
        flex: 0 0 auto;
        max-height: 8.5rem;
    }

    .cart-line strong,
    .cart-line .tenant-meta {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .pos-work,
    .pos-grid {
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .totals {
        position: relative;
    }

    .totals-scroll {
        display: none;
    }

    .totals.details-open .totals-scroll {
        display: flex;
        position: absolute;
        left: 0;
        right: 0;
        bottom: 100%;
        max-height: 46dvh;
        z-index: 12;
        box-shadow: var(--shadow);
    }
}

@media (min-width: 768px) and (max-width: 1279px) {
    .topbar .install-button {
        display: none;
    }
}

@media (min-width: 1280px) {
    .sidenav .install-button {
        display: none;
    }
}

    .shell.nav-shown .sidenav {
        width: var(--sidebar);
        flex-basis: var(--sidebar);
    }

    .shell:not(.nav-shown) .sidenav {
        width: 0;
        flex-basis: 0;
        padding: 0;
        border: 0;
        overflow: hidden;
        visibility: hidden;
    }
}

@media (min-width: 1280px) {
    .content {
        padding: var(--space-3) var(--space-4);
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        scroll-behavior: auto;
    }
}

@media (max-height: 200px) {
    .topbar,
    .pos-bar,
    .bill-setup,
    .bottomnav,
    .sidenav,
    .banner,
    .panel,
    .line-tax {
        display: none;
    }

    .shell {
        padding-bottom: 0;
    }

    .content {
        padding: 4px 8px;
    }

    .search-box {
        flex: 0 0 auto;
    }

    .pos-work {
        align-items: end;
    }
}
