:root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --ink: #1f2937;
    --muted: #64748b;
    --line: #d9dee7;
    --primary: #136f63;
    --primary-strong: #0f5c53;
    --accent: #b65d16;
    --danger: #b42318;
    --success-bg: #e9f7ef;
    --error-bg: #fff0f0;
    --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Tahoma, "Noto Sans Thai", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

a {
    color: inherit;
    text-decoration: none;
}

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.05);
}

.topbar-inner {
    display: flex;
    gap: 18px;
    align-items: center;
    justify-content: space-between;
    max-width: 1440px;
    margin: 0 auto;
    padding: 12px 20px;
}

.brand {
    min-width: 210px;
}

.brand-title {
    font-weight: 800;
    font-size: 18px;
}

.brand-sub {
    color: var(--muted);
    font-size: 12px;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.nav a {
    border: 1px solid var(--line);
    border-radius: 8px;
    color: #334155;
    padding: 8px 12px;
    background: #fff;
    white-space: nowrap;
}

.nav a.active,
.nav a:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.shell {
    max-width: 1440px;
    margin: 0 auto;
    padding: 20px;
}

.page-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.page-head h1 {
    margin: 0;
    font-size: 26px;
    line-height: 1.2;
}

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

.eyebrow {
    color: var(--primary);
    font-weight: 800;
    letter-spacing: 0;
    margin: 0 0 6px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.stat {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.stat span {
    color: var(--muted);
    display: block;
    font-size: 12px;
}

.stat strong {
    display: block;
    font-size: 22px;
    margin-top: 4px;
}

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

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

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

.grid.pos {
    grid-template-columns: minmax(560px, 1.45fr) minmax(360px, 0.75fr);
}

.customer-inline-form {
    display: none;
}

.customer-inline-form + .panel {
    grid-column: 1 / -1;
}

.narrow-panel {
    max-width: 920px;
}

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

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

.pos-customer-row {
    align-items: end;
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(0, 1fr) auto;
    margin: -2px 0 14px;
    padding-bottom: 14px;
}

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

.form-grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field {
    display: grid;
    gap: 6px;
}

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

label {
    color: #334155;
    font-weight: 700;
    font-size: 13px;
}

.input,
.select,
.textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    padding: 10px 11px;
    min-height: 42px;
}

.textarea {
    min-height: 84px;
    resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(19, 111, 99, 0.12);
}

.button {
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    cursor: pointer;
    display: inline-flex;
    font-weight: 800;
    justify-content: center;
    min-height: 40px;
    padding: 9px 13px;
    white-space: nowrap;
}

.button.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.button.primary:hover {
    background: var(--primary-strong);
}

.button.accent {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.button.danger {
    background: #fff;
    border-color: #f2c2bd;
    color: var(--danger);
}

.button.danger.solid {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.button.small {
    min-height: 32px;
    padding: 6px 9px;
    font-size: 13px;
}

.button-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.customer-page-actions {
    justify-content: flex-end;
    margin: -8px 0 16px;
}

.flash {
    border-radius: 8px;
    margin-bottom: 14px;
    padding: 12px 14px;
    font-weight: 700;
}

.flash.success {
    background: var(--success-bg);
    border: 1px solid #b7e2c8;
    color: #116333;
}

.flash.error {
    background: var(--error-bg);
    border: 1px solid #ffc9c9;
    color: var(--danger);
}

.searchbar {
    align-items: end;
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto auto;
    gap: 10px;
    margin-bottom: 14px;
}

.order-searchbar {
    grid-template-columns: minmax(220px, 1fr) auto;
}

.searchbar .button {
    justify-self: start;
}

.search-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.order-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.table-wrap.no-scroll {
    overflow: visible;
}

table {
    border-collapse: collapse;
    min-width: 820px;
    width: 100%;
}

.auto-table {
    min-width: 0;
}

.receipt-list-table th,
.receipt-list-table td {
    white-space: normal;
    word-break: break-word;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 10px;
    text-align: left;
    vertical-align: top;
}

th {
    background: #eef2f6;
    color: #334155;
    font-size: 13px;
    white-space: nowrap;
}

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

.num {
    text-align: right;
    white-space: nowrap;
}

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

.dashboard-actions {
    justify-content: flex-start;
}

.product-search {
    margin-bottom: 10px;
}

.product-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
    max-height: 620px;
    overflow: auto;
    padding-right: 2px;
}

.product-tile {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    min-height: 138px;
    padding: 10px;
    position: relative;
    text-align: left;
}

.product-tile.featured {
    border-color: #e0a43a;
}

.product-tile:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(19, 111, 99, 0.10);
}

.product-tile strong,
.product-tile span {
    display: block;
}

.product-tile span {
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
}

.product-badge,
.product-featured-pill {
    background: #fff6dd;
    border: 1px solid #efd08a;
    color: #8a4b0f;
}

.product-tile .product-badge {
    border-radius: 999px;
    display: inline-flex;
    font-size: 12px;
    font-weight: 800;
    margin: 0 0 5px;
    padding: 2px 8px;
}

.product-thumb {
    background: #eef2f6;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: block;
    height: 76px;
    margin-bottom: 8px;
    object-fit: cover;
    width: 100%;
}

.product-thumb.empty {
    align-items: center;
    color: var(--muted);
    display: flex;
    font-size: 12px;
    justify-content: center;
}

.product-preview,
.table-thumb {
    background: #eef2f6;
    border: 1px solid var(--line);
    border-radius: 8px;
    height: 58px;
    object-fit: cover;
    width: 58px;
}

.table-thumb.empty {
    align-items: center;
    color: var(--muted);
    display: inline-flex;
    font-size: 13px;
    justify-content: center;
}

.image-preview-row {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.inline-check {
    align-items: center;
    display: inline-flex;
    gap: 6px;
    font-weight: 700;
}

.drag-cell {
    text-align: center;
    vertical-align: middle;
    width: 38px;
}

.drag-handle {
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    cursor: grab;
    display: inline-flex;
    font-weight: 900;
    height: 30px;
    justify-content: center;
    width: 30px;
}

.sortable-row.dragging {
    opacity: 0.55;
}

.sortable-row.dragging td {
    background: #eef8f5;
}

.modal-backdrop {
    align-items: center;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 18px;
    position: fixed;
    z-index: 80;
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
    max-width: 560px;
    padding: 18px;
    width: 100%;
}

.confirm-card {
    max-width: 460px;
}

.confirm-actions {
    justify-content: flex-end;
}

.modal-head {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-bottom: 14px;
}

.modal-head h2 {
    margin: 0;
}

.icon-button {
    align-items: center;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    font-weight: 900;
    height: 34px;
    justify-content: center;
    width: 34px;
}

.receipt-table input,
.receipt-table select {
    min-width: 78px;
}

.receipt-table .item-name {
    min-width: 150px;
}

.pos-receipt-table {
    min-width: 0;
    table-layout: fixed;
}

.pos-receipt-table th,
.pos-receipt-table td {
    padding: 8px 6px;
}

.pos-receipt-table th:nth-child(1),
.pos-receipt-table td:nth-child(1) {
    width: 46%;
}

.pos-receipt-table th:nth-child(2),
.pos-receipt-table td:nth-child(2) {
    width: 19%;
}

.pos-receipt-table th:nth-child(3),
.pos-receipt-table td:nth-child(3) {
    width: 25%;
}

.pos-receipt-table th:nth-child(4),
.pos-receipt-table td:nth-child(4) {
    width: 10%;
}

.pos-receipt-table .input {
    min-width: 0;
    padding: 8px 7px;
}

.pos-receipt-table .item-name {
    min-width: 0;
}

.pos-receipt-table .button.small {
    min-width: 0;
    padding: 6px 7px;
}

.summary {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.summary-line {
    align-items: center;
    display: flex;
    justify-content: space-between;
    gap: 14px;
}

.summary-line.total {
    border-top: 1px solid var(--line);
    font-size: 22px;
    font-weight: 900;
    margin-top: 6px;
    padding-top: 12px;
}

.status-pill {
    border-radius: 999px;
    display: inline-block;
    font-size: 12px;
    font-weight: 800;
    padding: 4px 9px;
}

.status-paid {
    background: #e9f7ef;
    color: #116333;
}

.status-partial {
    background: #fff6dd;
    color: #8a4b0f;
}

.status-unpaid {
    background: #fff0f0;
    color: var(--danger);
}

.status-voided {
    background: #e5e7eb;
    color: #475569;
}

.receipt-paper {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin: 0 auto;
    max-width: 820px;
    padding: 28px;
}

.receipt-paper.thermal-75 {
    border-radius: 4px;
    font-family: Tahoma, Arial, sans-serif;
    font-size: 11px;
    line-height: 1.28;
    max-width: 75mm;
    padding: 4mm;
}

.thermal-75 .receipt-head {
    border-bottom: 1px dashed #111827;
    display: block;
    padding-bottom: 8px;
    text-align: center;
}

.thermal-75 .receipt-head h1 {
    font-size: 16px;
    margin: 0 0 4px;
}

.thermal-75 .receipt-head h2 {
    font-size: 14px;
    margin: 8px 0 4px;
}

.thermal-75 .receipt-meta {
    text-align: center;
}

.thermal-75 .receipt-info {
    display: block;
    margin: 10px 0;
}

.thermal-75 .receipt-info > div {
    border-bottom: 1px dashed #d1d5db;
    padding: 6px 0;
}

.thermal-75 .table-wrap {
    border: 0;
    border-radius: 0;
    overflow: visible;
}

.thermal-75 table {
    font-size: 10.5px;
    min-width: 0;
    table-layout: fixed;
}

.thermal-75 th,
.thermal-75 td {
    border-bottom: 1px dashed #d1d5db;
    padding: 4px 2px;
    word-break: break-word;
}

.thermal-75 th:first-child,
.thermal-75 td:first-child {
    width: 7mm;
}

.thermal-75 th:nth-child(2),
.thermal-75 td:nth-child(2) {
    width: auto;
}

.thermal-75 .summary-line {
    font-size: 11px;
}

.thermal-75 .summary-line.total {
    font-size: 15px;
}

.thermal-75 .receipt-status-bottom {
    margin: 12px 0 4px;
    text-align: center;
}

.receipt-head {
    display: flex;
    gap: 18px;
    justify-content: space-between;
    border-bottom: 2px solid #111827;
    padding-bottom: 14px;
}

.receipt-head h1 {
    margin: 0 0 6px;
}

.receipt-meta {
    text-align: right;
}

.receipt-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin: 16px 0;
}

.install-page {
    background: #eef2f6;
}

.install-wrap {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 20px;
}

.install-panel {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-width: 560px;
    padding: 28px;
    width: 100%;
}

.install-panel h1 {
    margin: 0 0 10px;
}

.status-ok {
    background: var(--success-bg);
    border: 1px solid #b7e2c8;
    border-radius: 8px;
    color: #116333;
    font-weight: 800;
    margin: 16px 0;
    padding: 12px;
}

.install-note {
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 13px;
    margin-top: 20px;
    padding-top: 14px;
}

code {
    background: #eef2f6;
    border-radius: 6px;
    padding: 2px 5px;
}

.print-only {
    display: none;
}

@media (max-width: 1040px) {
    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

@media (max-width: 700px) {
    .topbar-inner,
    .page-head,
    .receipt-head,
    .receipt-info {
        display: grid;
    }

    .nav {
        justify-content: flex-start;
    }

    .shell {
        padding: 14px;
    }

    .form-grid,
    .form-grid.three,
    .pos-customer-row,
    .searchbar {
        grid-template-columns: 1fr;
    }

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

    .receipt-meta {
        text-align: left;
    }
}

@media print {
    @page {
        size: 75mm auto;
        margin: 0;
    }

    body {
        background: #fff;
        font-size: 12px;
    }

    .topbar,
    .page-head,
    .flash,
    .no-print,
.button-row {
        display: none !important;
    }

    .shell {
        max-width: none;
        padding: 0;
    }

    .receipt-paper {
        border: 0;
        box-shadow: none;
        max-width: none;
        padding: 0;
    }

    .receipt-paper.thermal-75 {
        margin: 0;
        max-width: 75mm;
        padding: 3mm;
        width: 75mm;
    }

    .print-only {
        display: block;
    }

    table {
        min-width: 0;
    }
}

.button-row.compact {
    margin-top: 8px;
}
