:root {
  color-scheme: light;
  --bg: #f7f3e8;
  --panel: #fffdf7;
  --ink: #27343a;
  --muted: #6f7d80;
  --line: #d8e2df;
  --accent: #77b7b2;
  --accent-strong: #4f8f89;
  --soft: #e4f3f1;
  --cream: #fff7df;
  --row: #f8fbfa;
  --warn: #a7604d;
  --shadow: 0 10px 30px rgba(39, 52, 58, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000;
  --panel: #090909;
  --ink: #f4f7f5;
  --muted: #b8c2c0;
  --line: #30363a;
  --accent: #8bc9c5;
  --accent-strong: #a8dad6;
  --soft: #101b1b;
  --cream: #151515;
  --row: #111;
  --warn: #dda08e;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.65);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, sans-serif;
}

.auth-locked body {
  overflow: hidden;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(247, 243, 232, 0.96);
}

:root[data-theme="dark"] .auth-gate {
  background: rgba(0, 0, 0, 0.96);
}

.auth-card {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.auth-card h2 {
  font-size: 24px;
}

.auth-message {
  min-height: 20px;
  margin: 0;
  color: var(--warn);
  font-size: 13px;
}

button,
input {
  font: inherit;
}

select,
textarea {
  font: inherit;
}

input:disabled,
textarea:disabled,
select:disabled,
button:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.app-topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: #e7f4f2;
}

:root[data-theme="dark"] .app-topbar {
  background: #000;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 18px;
}

.topbar-actions {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.header-title-block {
  display: grid;
  gap: 6px;
  justify-items: start;
}

.topbar-main-actions,
.topbar-menu-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill {
  min-width: 126px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7fbf8;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 500px;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 77px);
}

.sale-panel,
.cart-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.sale-panel {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  padding: 14px;
}

.cart-panel {
  display: flex;
  flex-direction: column;
  padding: 14px;
}

.customer-first {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.customer-box,
.search-box,
.field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.customer-box input,
.search-box input,
.field input,
.totals input,
.qty-input,
.price-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
}

.customer-box input {
  height: 54px;
  padding: 0 14px;
  font-size: 21px;
  font-weight: 700;
}

.customer-price-note {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}

.customer-price-note span,
.quick-stats span,
.change-box span,
.totals span,
.cart-meta,
.product-meta,
.price-source {
  color: var(--muted);
  font-size: 12px;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
}

.search-box input {
  height: 48px;
  padding: 0 14px;
  font-size: 18px;
}

.icon-button,
.ghost-button,
.primary-button,
.qty-control button,
.remove-line {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.icon-button {
  align-self: end;
  width: 44px;
  height: 48px;
  font-size: 24px;
}

.icon-button.small {
  width: 38px;
  height: 38px;
}

.ghost-button {
  min-height: 38px;
  padding: 0 12px;
}

.ghost-button.icon-only {
  min-width: 42px;
  padding: 0;
}

.ghost-link {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
}

.menu-trigger {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--cream);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
}

.work-menu {
  position: relative;
}

.work-menu-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  width: 190px;
  display: grid;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.work-menu-panel button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.work-menu-panel button:hover {
  background: var(--soft);
}

.ghost-button.danger {
  color: var(--warn);
}

.hidden {
  display: none !important;
}

.primary-button {
  width: 100%;
  min-height: 50px;
  border-color: var(--accent);
  background: var(--accent);
  color: #102421;
  font-weight: 700;
}

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

.quick-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.quick-stats div,
.change-box {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--cream);
}

.product-header,
.product-row {
  display: grid;
  grid-template-columns: 50px minmax(220px, 1fr) 40px 116px 104px;
  align-items: center;
  gap: 8px;
}

.product-header {
  min-height: 30px;
  padding: 0 10px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
}

.product-results {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 5px;
  padding-top: 6px;
  padding-right: 4px;
}

.product-row {
  width: 100%;
  min-height: 50px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--row);
  text-align: left;
}

.product-row:hover,
.product-row:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(31, 111, 91, 0.12);
}

.thumb {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.thumb.large {
  width: 72px;
  height: 72px;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-main {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.product-name,
.cart-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-name {
  font-size: 13px;
}

.product-meta {
  font-size: 11px;
}

.product-stock,
.product-last-price,
.product-price,
.cart-total {
  text-align: right;
}

.product-stock {
  color: var(--muted);
  font-size: 11px;
}

.empty-state {
  display: grid;
  gap: 4px;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: var(--row);
}

.empty-state span {
  color: var(--muted);
}

.cart-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.cart-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.field input,
.totals input,
.note-field textarea {
  height: 38px;
  padding: 0 10px;
}

.note-field textarea {
  min-height: 46px;
  padding: 8px 10px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

.cart-items {
  flex: 1;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 5px;
  margin: 8px 0;
  padding-right: 3px;
}

.cart-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px 78px 76px 28px;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--row);
  font-size: 12px;
}

.cart-row > div:first-child {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.qty-control {
  display: grid;
  grid-template-columns: 30px 1fr 30px;
}

.qty-control button {
  height: 32px;
}

.qty-input,
.price-input {
  height: 30px;
  text-align: center;
  font-size: 12px;
}

.qty-input {
  border-radius: 6px;
  min-width: 70px;
}

.remove-line {
  width: 28px;
  height: 30px;
  color: var(--warn);
}

.totals {
  display: grid;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.totals label,
.totals div {
  display: grid;
  grid-template-columns: 1fr 130px;
  align-items: center;
  gap: 8px;
}

.totals strong {
  text-align: right;
}

.net-row {
  padding-top: 6px;
  border-top: 1px solid var(--line);
  font-size: 22px;
}

.save-actions {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.history-panel {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.history-head h2 {
  font-size: 15px;
}

.compact-field {
  margin-bottom: 8px;
}

.compact-field input {
  height: 34px;
  padding: 0 9px;
}

.sale-history-list {
  max-height: 178px;
  overflow: auto;
  display: grid;
  gap: 5px;
  padding-right: 3px;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 62px 70px;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--row);
  font-size: 12px;
}

.history-row div {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.history-row strong,
.history-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-row button {
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.sync-badge {
  justify-self: start;
  padding: 4px 6px;
  border-radius: 999px;
  font-size: 11px;
  white-space: nowrap;
}

.sync-badge.pending {
  background: #fff1c7;
  color: #745512;
}

.sync-badge.synced {
  background: #dcefed;
  color: #285f5a;
}

.history-empty {
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.print-receipt {
  display: none;
}

.history-page {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.history-filter-panel,
.history-table-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 14px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.history-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.history-actions .primary-button,
.history-actions .ghost-button {
  width: auto;
  min-height: 38px;
  padding: 0 14px;
}

.history-summary {
  display: grid;
  grid-template-columns: 1fr repeat(3, auto);
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.history-summary span {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  white-space: nowrap;
}

.history-table-wrap {
  overflow: auto;
  max-height: calc(100vh - 205px);
  min-height: 390px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  font-size: 13px;
}

.history-table th,
.history-table td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.history-table th {
  position: sticky;
  top: 0;
  background: var(--soft);
  z-index: 1;
}

.history-table .amount-cell {
  text-align: right;
}

.bill-status {
  display: inline-flex;
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--cream);
  color: var(--ink);
}

.history-table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.history-table-actions button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.history-table-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.view-bill-dialog {
  width: min(860px, calc(100vw - 28px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.view-bill-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.view-bill-dialog form {
  max-height: calc(100dvh - 32px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.view-bill-head,
.view-bill-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.view-bill-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.view-bill-content {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 10px;
  padding: 12px 14px;
}

.view-bill-meta,
.view-bill-total {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.view-bill-meta div,
.view-bill-total div,
.view-bill-note {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}

.view-bill-meta span,
.view-bill-total span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.view-bill-meta strong,
.view-bill-total strong {
  overflow-wrap: anywhere;
}

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

.view-bill-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.view-bill-table th,
.view-bill-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.view-bill-table th {
  position: sticky;
  top: 0;
  background: var(--soft);
  z-index: 1;
}

.view-bill-table td:nth-child(3) {
  min-width: 260px;
  white-space: normal;
}

.canceled-sale {
  color: var(--muted);
  text-decoration: line-through;
}

.empty-history-cell {
  color: var(--muted);
  text-align: center !important;
}

.quantity-dialog {
  width: min(620px, calc(100vw - 24px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(21, 34, 29, 0.24);
}

.product-manager-dialog {
  width: min(1080px, calc(100vw - 40px));
  height: min(720px, calc(100dvh - 40px));
  max-height: calc(100dvh - 40px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #c6ffc4;
  color: #164845;
  box-shadow: 0 24px 60px rgba(21, 34, 29, 0.24);
}

:root[data-theme="dark"] .product-manager-dialog {
  background: #071107;
  color: var(--ink);
}

:root[data-theme="dark"] .product-manager-title {
  background: linear-gradient(#0f5d25, #123f1d);
  color: #f4fff5;
}

:root[data-theme="dark"] .product-editor-panel fieldset {
  border-color: #4f7653;
}

:root[data-theme="dark"] .product-editor-panel legend,
:root[data-theme="dark"] .product-editor-grid .field,
:root[data-theme="dark"] .product-image-panel,
:root[data-theme="dark"] .list-tool strong {
  color: #d7f4df;
}

:root[data-theme="dark"] .product-editor-grid .field input,
:root[data-theme="dark"] .list-tool select,
:root[data-theme="dark"] .list-tool input,
:root[data-theme="dark"] .product-browser-search select,
:root[data-theme="dark"] .product-browser-search input {
  background: #111;
  color: #f7faf8;
  border-color: #5a6a61;
}

:root[data-theme="dark"] .product-editor-grid .field input::placeholder,
:root[data-theme="dark"] .list-tool input::placeholder,
:root[data-theme="dark"] .product-browser-search input::placeholder {
  color: #8f9a94;
}

:root[data-theme="dark"] .list-tool {
  border-color: #4f7653;
  background: rgba(255, 255, 255, 0.06);
}

:root[data-theme="dark"] .product-image-preview {
  background: #f8f8f8;
  color: #5f6b66;
}

:root[data-theme="dark"] .product-browser-panel {
  border-color: #384a40;
  background: #080808;
}

:root[data-theme="dark"] .product-browser-search {
  background: #22206f;
  color: #fff;
}

:root[data-theme="dark"] .product-manager-table {
  color: #f6f8f7;
}

:root[data-theme="dark"] .product-manager-table th {
  background: #9a6500;
  color: #fff7dc;
}

:root[data-theme="dark"] .product-manager-table td {
  border-color: #445047;
}

:root[data-theme="dark"] .product-manager-table tbody tr:nth-child(even) {
  background: #121812;
}

:root[data-theme="dark"] .product-manager-table tbody tr:nth-child(odd) {
  background: #1b1510;
}

.product-manager-dialog::backdrop {
  background: rgba(21, 34, 29, 0.36);
}

.report-dialog,
.confirm-dialog {
  width: min(1120px, calc(100vw - 28px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.confirm-dialog {
  width: min(460px, calc(100vw - 28px));
}

.report-dialog::backdrop,
.confirm-dialog::backdrop {
  background: rgba(0, 0, 0, 0.48);
}

.report-dialog form,
.confirm-dialog form {
  max-height: calc(100dvh - 32px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: auto;
}

.confirm-dialog form {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.report-dialog-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
}

.report-filter-panel {
  display: grid;
  grid-template-columns: minmax(180px, 1.3fr) minmax(150px, 1fr) minmax(150px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.filter-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.filter-actions .primary-button,
.filter-actions .ghost-button {
  width: auto;
  min-height: 38px;
  padding: 0 14px;
  white-space: nowrap;
}

.report-list-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  padding: 14px 16px 16px;
}

.report-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.report-summary-row .primary-button {
  width: auto;
  min-height: 38px;
  padding: 0 16px;
}

.billing-table-wrap {
  min-height: 360px;
  max-height: min(58dvh, 560px);
  overflow: auto;
  border: 1px solid var(--line);
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
}

.report-table th,
.report-table td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.report-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--soft);
}

.report-table .num,
.num {
  text-align: right;
}

.report-table .center,
.center {
  text-align: center;
}

.empty-row {
  padding: 18px !important;
  color: var(--muted);
  text-align: center !important;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.row-actions button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.row-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.confirm-body,
.payment-fields,
.readonly-bill {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.confirm-body strong {
  font-size: 24px;
}

.readonly-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.readonly-summary div {
  display: grid;
  gap: 2px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}

.readonly-summary span {
  color: var(--muted);
  font-size: 12px;
}

.customer-manager-dialog form {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.customer-editor-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.customer-form-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(180px, 0.8fr);
  gap: 10px;
}

.customer-address-field {
  grid-column: 1 / -1;
}

.customer-editor-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.customer-editor-actions .primary-button,
.customer-editor-actions .ghost-button {
  width: auto;
  min-height: 38px;
  padding: 0 14px;
  white-space: nowrap;
}

.customer-browser-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  padding: 14px 16px 16px;
}

.customer-browser-search {
  max-width: 560px;
}

.customer-table-wrap {
  min-height: 360px;
  max-height: min(58dvh, 560px);
  overflow: auto;
  border: 1px solid var(--line);
}

.customer-table-wrap tr[data-id] {
  cursor: pointer;
}

.sync-settings-dialog {
  width: min(620px, calc(100vw - 28px));
}

.sync-settings-dialog form {
  grid-template-rows: auto auto auto;
}

.sync-settings-body {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.sync-settings-status {
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--ink);
}

.sync-settings-body input {
  width: 100%;
}

.system-status-dialog {
  width: min(760px, calc(100vw - 28px));
}

.system-status-dialog form {
  grid-template-rows: auto auto;
}

.system-status-body {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.system-status-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.system-status-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}

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

.system-status-card strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 18px;
}

.annual-export-panel {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.annual-export-panel .primary-button {
  width: auto;
  min-height: 42px;
  padding: 0 16px;
  white-space: nowrap;
}

button:disabled,
.ghost-button:disabled,
.primary-button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.selected-row td {
  background: var(--soft);
  font-weight: 700;
}

.product-manager-dialog form {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(330px, 1fr);
  overflow: auto;
}

.product-manager-title {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 6px 50px;
  background: linear-gradient(#159940, #2aaa37);
  color: #ecfff0;
}

.product-manager-title h2 {
  font-size: 21px;
}

.product-manager-title .icon-button {
  position: absolute;
  right: 10px;
  top: 5px;
}

.product-editor-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 176px;
  gap: 10px;
  padding: 10px 14px 8px;
}

.product-editor-panel fieldset {
  min-width: 0;
  margin: 0;
  border: 1px solid #9fe6a1;
  border-radius: 6px;
}

.product-editor-panel legend {
  padding: 0 8px;
  font-weight: 700;
}

.product-editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
  padding: 4px 10px 8px;
}

.product-editor-grid .field {
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  color: #157b78;
  font-weight: 700;
  font-size: 12px;
}

.product-editor-grid .field input {
  height: 30px;
  background: #f7f7f7;
}

.product-editor-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 6px 10px 10px;
}

.product-editor-actions .primary-button,
.product-editor-actions .ghost-button {
  width: 74px;
  min-height: 38px;
  padding: 0 8px;
}

.product-list-tools {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 0 10px 6px;
}

.list-tool {
  min-width: 0;
  display: grid;
  grid-template-columns: 88px 126px minmax(150px, 1fr) 94px 74px;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid #9fe6a1;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.38);
}

.list-tool strong {
  font-size: 12px;
  line-height: 1.15;
  white-space: nowrap;
}

.list-tool select,
.list-tool input {
  min-width: 0;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #f7f7f7;
  color: #164845;
}

.list-tool .ghost-button {
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
  white-space: nowrap;
}

.product-image-panel {
  display: grid;
  align-content: start;
  gap: 8px;
  color: #157b78;
  font-weight: 700;
}

.product-image-preview {
  width: 154px;
  height: 112px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid #8aa594;
  background: #fff;
  color: var(--muted);
}

.product-image-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.product-image-panel input {
  width: 154px;
  font-size: 11px;
}

.product-browser-panel {
  min-height: 330px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  margin: 0 14px 14px;
  border: 1px solid #53736a;
  background: #fff9db;
}

.product-browser-search {
  min-height: 46px;
  display: grid;
  grid-template-columns: 1fr 180px 260px 46px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: #7d7cff;
  color: #fff;
  font-weight: 700;
  text-align: right;
}

.product-browser-search input {
  height: 30px;
  border: 1px solid #dce2ee;
  border-radius: 4px;
}

.product-browser-search select {
  min-width: 0;
  height: 30px;
  border: 1px solid #dce2ee;
  border-radius: 4px;
  background: #fff;
  color: #164845;
}

.product-browser-search .icon-button {
  width: 42px;
  height: 34px;
  align-self: center;
  background: #fff;
  color: #197989;
}

.product-manager-table-wrap {
  min-height: 0;
  overflow: auto;
}

.product-manager-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.product-manager-table th,
.product-manager-table td {
  padding: 4px 7px;
  border: 1px solid #a4ada8;
  white-space: nowrap;
}

.product-manager-table th {
  position: sticky;
  top: 0;
  background: #ffa600;
  color: #1d3134;
  z-index: 1;
  text-align: left;
}

.product-manager-table tbody tr:nth-child(even) {
  background: #f3f4d8;
}

.product-manager-table tbody tr:nth-child(odd) {
  background: #ffe0ba;
}

.product-manager-table tbody tr:hover,
.product-manager-table .selected-product-row {
  background: #0d83d4 !important;
  color: #fff;
}

.sales-item-history-page .filter-grid {
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.sales-item-history-page .filter-grid .field {
  min-width: 0;
  grid-column: span 2;
}

.sales-item-history-page .filter-grid .field:nth-of-type(5),
.sales-item-history-page .filter-grid .field:nth-of-type(6) {
  grid-column: span 2;
}

.sales-item-history-page .field input {
  min-width: 0;
}

.sales-item-table-wrap {
  min-height: 430px;
  max-height: calc(100vh - 205px);
}

.sales-item-table {
  min-width: 1180px;
}

.sales-item-table th:nth-child(4),
.sales-item-table td:nth-child(4) {
  min-width: 260px;
}

.quantity-dialog::backdrop {
  background: rgba(21, 34, 29, 0.35);
}

.quantity-dialog form {
  display: grid;
  gap: 0;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
}

.dialog-head {
  border-bottom: 1px solid var(--line);
}

.dialog-actions {
  border-top: 1px solid var(--line);
}

.dialog-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.dialog-product-line {
  display: grid;
  grid-template-columns: minmax(150px, 190px) minmax(0, 1fr);
  align-items: stretch;
  gap: 16px;
}

.dialog-product-line .thumb.large {
  width: 100%;
  height: auto;
  min-height: 150px;
  aspect-ratio: 1 / 1;
  align-self: stretch;
  background: #fff;
}

.dialog-product-line .thumb.large img {
  object-fit: contain;
}

.dialog-product-line div:last-child {
  display: grid;
  align-content: center;
  gap: 5px;
}

.dialog-product-line span {
  color: var(--muted);
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .cart-panel {
    min-height: 620px;
  }

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

  .report-filter-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .filter-actions {
    grid-column: 1 / -1;
  }

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

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

  .sales-item-history-page .filter-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .sales-item-history-page .filter-grid .field {
    grid-column: span 2;
  }

  .sales-item-history-page .filter-grid .field:nth-of-type(5),
  .sales-item-history-page .filter-grid .field:nth-of-type(6) {
    grid-column: span 3;
  }
}

@media (max-width: 720px) {
  .app-topbar,
  .customer-first {
    align-items: flex-start;
    grid-template-columns: 1fr;
  }

  .app-topbar {
    flex-direction: column;
  }

  .topbar-actions,
  .topbar-main-actions,
  .topbar-menu-actions {
    width: 100%;
    justify-items: stretch;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .workspace {
    padding: 10px;
  }

  .quick-stats,
  .product-header {
    grid-template-columns: 1fr;
  }

  .product-header {
    display: none;
  }

  .product-row,
  .cart-row,
  .checkout-row {
    grid-template-columns: 1fr;
  }

  .product-stock,
  .product-last-price,
  .product-price,
  .cart-total {
    text-align: left;
  }

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

  .report-filter-panel,
  .readonly-summary,
  .customer-editor-panel,
  .system-status-cards,
  .annual-export-panel,
  .customer-form-grid {
    grid-template-columns: 1fr;
  }

  .filter-actions,
  .report-summary-row,
  .customer-editor-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-actions .primary-button,
  .filter-actions .ghost-button,
  .report-summary-row .primary-button,
  .customer-editor-actions .primary-button,
  .customer-editor-actions .ghost-button {
    width: 100%;
  }

  .history-actions {
    flex-direction: column;
  }

  .view-bill-meta,
  .view-bill-total {
    grid-template-columns: 1fr;
  }

  .view-bill-head,
  .view-bill-actions,
  .view-bill-content {
    padding: 10px;
  }

  .product-manager-dialog {
    height: calc(100dvh - 16px);
    width: calc(100vw - 16px);
  }

  .product-editor-grid,
  .product-editor-grid .field,
  .product-browser-search {
    grid-template-columns: 1fr;
    text-align: left;
  }

  .list-tool {
    grid-template-columns: 1fr;
  }

  .quantity-dialog {
    width: calc(100vw - 16px);
  }

  .dialog-head,
  .dialog-actions,
  .dialog-body {
    padding: 10px;
  }

  .dialog-product-line {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .dialog-product-line .thumb.large {
    width: min(70vw, 220px);
    min-height: auto;
    justify-self: center;
  }

  .product-image-preview,
  .product-image-panel input {
    width: 100%;
  }

  .sales-item-history-page .filter-grid {
    grid-template-columns: 1fr;
  }

  .sales-item-history-page .filter-grid .field,
  .sales-item-history-page .filter-grid .field:nth-of-type(5),
  .sales-item-history-page .filter-grid .field:nth-of-type(6) {
    grid-column: 1;
  }
}

@page {
  size: A5 portrait;
  margin: 0;
}

@media print {
  body > :not(.print-receipt) {
    display: none !important;
  }

  html,
  body {
    background: #fff;
    color: #000;
    width: 148mm;
    min-height: 210mm;
    margin: 0;
  }

  .print-receipt {
    display: block;
    width: 148mm;
    margin: 0 auto;
    padding: 0;
    color: #000;
    font-family: "Segoe UI", Tahoma, sans-serif;
    font-size: 11.5pt;
    line-height: 1.22;
  }

  .receipt-page {
    position: relative;
    width: 148mm;
    min-height: 210mm;
    padding: 7mm 8mm 8mm;
    page-break-after: always;
    break-after: page;
  }

  .receipt-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .billing-print-page {
    position: relative;
    width: 148mm;
    min-height: 210mm;
    padding: 8mm;
    page-break-after: always;
    break-after: page;
  }

  .billing-print-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .receipt-page-count {
    position: absolute;
    top: 6mm;
    right: 9mm;
    color: #555;
    font-size: 8pt;
  }

  .receipt-page h1 {
    margin: 1mm 0 5mm;
    font-size: 17pt;
    font-weight: 700;
    text-align: center;
  }

  .billing-print-page h1 {
    margin: 1mm 0 5mm;
    font-size: 17pt;
    font-weight: 700;
    text-align: center;
  }

  .print-receipt p {
    margin: 3px 0;
  }

  .receipt-meta {
    display: grid;
    grid-template-columns: 1fr 58mm;
    gap: 7mm;
    min-height: 23mm;
    margin-bottom: 3mm;
  }

  .shop-name {
    padding-top: 1mm;
    font-size: 11.5pt;
    font-weight: 700;
  }

  .bill-info {
    display: grid;
    gap: 0.8mm;
    font-size: 8.8pt;
  }

  .bill-info div {
    display: grid;
    grid-template-columns: 18mm 1fr;
    gap: 3mm;
  }

  .bill-info span {
    font-weight: 400;
  }

  .bill-info strong {
    font-weight: 400;
  }

  .bill-info .customer-line strong {
    font-weight: 700;
    font-size: 9.8pt;
  }

  .receipt-note {
    min-height: 6mm;
    margin: 0 0 2mm;
    font-size: 9pt;
  }

  .delivery-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 7.8pt;
  }

  .billing-print-meta {
    display: grid;
    grid-template-columns: 1fr 62mm;
    gap: 6mm;
    min-height: 22mm;
    margin-bottom: 3mm;
    font-size: 9pt;
  }

  .billing-print-meta > div:last-child {
    display: grid;
    gap: 1mm;
  }

  .billing-print-meta > div:last-child div {
    display: grid;
    grid-template-columns: 18mm 1fr;
    gap: 3mm;
  }

  .billing-print-customer strong {
    font-size: 10.5pt;
    font-weight: 700;
  }

  .billing-print-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 8pt;
  }

  .billing-print-table th,
  .billing-print-table td {
    border-left: 0.35mm solid #000;
    border-right: 0.35mm solid #000;
    padding: 0.8mm 1mm;
    vertical-align: middle;
  }

  .billing-print-table th {
    height: 7mm;
    border-top: 0.35mm solid #000;
    border-bottom: 0.35mm solid #000;
    text-align: center;
  }

  .billing-print-table tbody tr:last-child td,
  .billing-print-table .summary-row td,
  .billing-print-table .baht-row td {
    border-bottom: 0.35mm solid #000;
  }

  .billing-print-table th:nth-child(1),
  .billing-print-table td:nth-child(1) {
    width: 10mm;
  }

  .billing-print-table th:nth-child(2),
  .billing-print-table td:nth-child(2) {
    width: 24mm;
  }

  .billing-print-table th:nth-child(3),
  .billing-print-table td:nth-child(3) {
    width: 34mm;
  }

  .billing-print-table th:nth-child(5),
  .billing-print-table td:nth-child(5) {
    width: 30mm;
  }

  .delivery-table th,
  .delivery-table td {
    border-left: 0.35mm solid #000;
    border-right: 0.35mm solid #000;
    padding: 0.65mm 1mm;
    vertical-align: middle;
    overflow-wrap: anywhere;
  }

  .delivery-table th {
    height: 6.2mm;
    border-top: 0.35mm solid #000;
    border-bottom: 0.35mm solid #000;
    font-weight: 600;
    text-align: center;
  }

  .delivery-table th:nth-child(1),
  .delivery-table td:nth-child(1) {
    width: 8mm;
    text-align: center;
  }

  .delivery-table th:nth-child(2),
  .delivery-table td:nth-child(2) {
    width: 8mm;
  }

  .delivery-table th:nth-child(3),
  .delivery-table td:nth-child(3) {
    width: auto;
  }

  .delivery-table td:nth-child(3) {
    font-size: 7.8pt;
    line-height: 1.08;
  }

  .delivery-table th:nth-child(4),
  .delivery-table td:nth-child(4) {
    width: 7.5mm;
  }

  .delivery-table th:nth-child(5),
  .delivery-table td:nth-child(5) {
    width: 18mm;
  }

  .delivery-table th:nth-child(6),
  .delivery-table td:nth-child(6) {
    width: 28.5mm;
  }

  .delivery-table tbody tr.item-row {
    height: 4.45mm;
  }

  .delivery-table td:nth-child(4) {
    font-size: 5.2pt;
    line-height: 0.95;
    letter-spacing: 0;
    transform: scaleX(0.82);
    transform-origin: center;
  }

  .delivery-table tbody tr.item-row:last-of-type td {
    border-bottom: 0.35mm solid #000;
  }

  .print-receipt .num {
    text-align: right;
    font-size: 7.6pt;
  }

  .delivery-table td:nth-child(2) {
    text-align: center;
  }

  .summary-row td:nth-child(5) {
    text-align: center;
  }

  .net-summary-label {
    text-align: center;
  }

  .net-summary-amount {
    text-align: right;
    padding-right: 2mm !important;
  }

  .print-receipt .center {
    text-align: center;
  }

  .summary-row td {
    height: 6.2mm;
    border-top: 0.35mm solid #000;
    border-bottom: 0;
    font-size: 7.8pt;
  }

  .summary-row + .summary-row td {
    border-top: 0;
  }

  .summary-space {
    border-bottom: 0.35mm solid #000 !important;
  }

  .continue-row td {
    color: #555;
    font-size: 10pt;
    text-align: center;
  }

  .baht-row td {
    height: 6.4mm;
    border-top: 0.35mm solid #000;
    border-bottom: 0.35mm solid #000;
    font-size: 9.2pt;
    font-weight: 700;
  }

  .baht-row td:first-child {
    text-align: center;
    font-size: 8.6pt;
    line-height: 1.05;
  }

  .receipt-signatures {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22mm;
    margin-top: 7mm;
    padding: 0 4mm;
    font-size: 10pt;
  }

  .receipt-signatures p {
    margin: 3mm 0;
  }
}
