/* ========================================
   Base
   ======================================== */
:root {
  color-scheme: light;
  --bg: #f5f6fa;
  --bg-2: #ffffff;
  --card: #f7f8fb;
  --surface: #eceef4;
  --raised: #ffffff;
  --input-bg: #ffffff;
  --border: #e2e4ec;
  --border-2: #cdd1dd;
  --text: #171822;
  --muted: #5f6377;
  --subtle: #8a8ea2;
  --primary: #6366f1;
  --primary-2: #4f46e5;
  --accent: #0891b2;
  --success: #059669;
  --warn: #b45309;
  --danger: #dc2626;
  --glow: #e9eafd;
  --topbar-bg: rgba(255, 255, 255, 0.85);
  --hover: rgba(15, 23, 42, 0.03);
  --stage-a: #e8eaf0;
  --stage-b: #f1f2f6;
  --code-text: #3b3f52;
  --backdrop: rgba(20, 22, 35, 0.45);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.12);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.18);
  --grad: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 16px;
  --font: 'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --topbar-h: 60px;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0a0a0f;
  --bg-2: #12121a;
  --card: #1a1a24;
  --surface: #22222e;
  --raised: #22222e;
  --input-bg: #1a1a24;
  --border: #2a2a3a;
  --border-2: #3a3a4a;
  --text: #f0f0f5;
  --muted: #8888a0;
  --subtle: #5a5a70;
  --primary-2: #818cf8;
  --accent: #22d3ee;
  --success: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --glow: #1a1a2e;
  --topbar-bg: rgba(10, 10, 15, 0.85);
  --hover: rgba(255, 255, 255, 0.02);
  --stage-a: #15151e;
  --stage-b: #111118;
  --code-text: #c7c7d9;
  --backdrop: rgba(5, 5, 10, 0.7);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
}

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

html,
body {
  margin: 0;
}

body {
  font-family: var(--font);
  background: radial-gradient(ellipse at top, var(--glow) 0%, var(--bg) 60%)
    fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

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

a {
  color: var(--primary-2);
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}
h1 {
  font-size: 1.6rem;
}
h2 {
  font-size: 1.05rem;
}
h3 {
  font-size: 0.9rem;
}

.muted {
  color: var(--muted);
}
.mono {
  font-family: var(--mono);
  font-size: 0.85em;
}
.nowrap {
  white-space: nowrap;
}
.center {
  text-align: center;
}
.upper {
  text-transform: uppercase;
}
.text-warn {
  color: var(--warn);
}
.text-danger {
  color: var(--danger);
}

kbd {
  font-family: var(--mono);
  font-size: 0.75em;
  padding: 1px 5px;
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--card);
}

::selection {
  background: rgba(99, 102, 241, 0.35);
}

/* ========================================
   Top bar
   ======================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: var(--topbar-bg);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  white-space: nowrap;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  object-fit: contain;
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}
.tabs::-webkit-scrollbar {
  display: none;
}

.tabs a {
  padding: 8px 14px;
  border-radius: var(--r-sm);
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}
.tabs a:hover {
  color: var(--text);
  background: var(--card);
}
.tabs a[aria-current='page'] {
  color: var(--text);
  background: var(--surface);
  box-shadow: inset 0 -2px 0 var(--primary);
}

.sync-status {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.8rem;
  white-space: nowrap;
  cursor: pointer;
}
.sync-status::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 7px;
  background: var(--muted);
  vertical-align: 1px;
}
.sync-status.ok::before {
  background: var(--success);
}
.sync-status.warn::before {
  background: var(--warn);
}

.theme-toggle {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover {
  color: var(--text);
  border-color: var(--border-2);
}
.theme-toggle svg {
  width: 18px;
  height: 18px;
}
.theme-toggle .icon-sun,
:root[data-theme='dark'] .theme-toggle .icon-moon {
  display: none;
}
:root[data-theme='dark'] .theme-toggle .icon-sun {
  display: block;
}

/* ========================================
   Layout primitives
   ======================================== */
main {
  padding: 20px;
  max-width: 1480px;
  margin: 0 auto;
}

.view-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.view-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.view-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.view-actions select {
  width: auto;
}

.panel {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  min-width: 0;
}
.panel > h2 {
  margin-bottom: 4px;
}

.split {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

/* ========================================
   Forms
   ======================================== */
:where(
    input:not([type='checkbox'], [type='radio'], [type='range'], [type='file']),
    select,
    textarea
  ) {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
:where(input, select, textarea):focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}
:where(input, select, textarea):disabled {
  opacity: 0.5;
}
textarea {
  resize: vertical;
  min-height: 60px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}
label output {
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8rem;
}
label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 400;
  cursor: pointer;
}
label.inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
label.inline input {
  width: auto;
}

input[type='checkbox'] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  margin: 0;
}
input[type='range'] {
  accent-color: var(--primary);
  width: 100%;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
legend {
  padding: 0 6px;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary-2);
}

.hint {
  font-size: 0.8rem;
  color: var(--subtle);
  margin: 0;
  font-weight: 400;
}
.hint code,
.steps code {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 0.9em;
}

.form-actions {
  display: flex;
  gap: 8px;
}
.form-actions.wrap {
  flex-wrap: wrap;
}

.input-group {
  display: flex;
  gap: 6px;
  align-items: center;
}
.input-group select {
  width: auto;
  flex: 0 0 auto;
}
.suffix {
  color: var(--muted);
}

/* ========================================
   Buttons
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: transform 0.15s, background 0.15s, border-color 0.15s,
    filter 0.15s, opacity 0.15s;
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.25);
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
}
.btn-secondary {
  background: var(--surface);
  border-color: var(--border-2);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-2);
}
.btn-danger {
  background: #dc2626;
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}
.btn-block {
  width: 100%;
}
.btn-lg {
  padding: 14px 18px;
  font-size: 1rem;
}

.btn-link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary-2);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.88rem;
}
.btn-link:hover {
  text-decoration: underline;
}
.btn-link.danger {
  color: var(--danger);
}

.icon-btn {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--r-sm);
}
.icon-btn:hover {
  color: var(--text);
  background: var(--surface);
}

/* ========================================
   Register
   ======================================== */
.view-pos {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 20px;
  align-items: start;
}

.pos-catalog {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: calc(100vh - var(--topbar-h) - 40px);
}

.pos-cart {
  position: sticky;
  top: calc(var(--topbar-h) + 20px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: calc(100vh - var(--topbar-h) - 40px);
  overflow-y: auto;
}
.pos-cart > * {
  flex-shrink: 0;
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chips:empty {
  display: none;
}
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
}
.chip:hover {
  color: var(--text);
}
.chip[aria-pressed='true'] {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary);
  color: var(--text);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  align-content: start;
  flex: 1;
  padding-top: 8px;
}

.product-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  min-height: 96px;
  padding: 14px;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.product-tile:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}
.product-tile:active {
  transform: scale(0.98);
}
.tile-name {
  font-weight: 600;
  line-height: 1.3;
}
.tile-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.tile-price {
  color: var(--accent);
  font-weight: 600;
  font-family: var(--mono);
  font-size: 0.85rem;
}
.stock {
  font-size: 0.72rem;
  color: var(--muted);
}
.stock.low {
  color: var(--warn);
}
.stock.out {
  color: var(--danger);
}
.tile-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
  border: 1px dashed var(--border-2);
  border-radius: var(--r);
  line-height: 1.8;
}

.custom-item {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.custom-item-fields {
  display: grid;
  grid-template-columns: 2fr 1fr 80px auto;
  gap: 8px;
}

.cart-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cart-lines {
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 60px;
}
.cart-empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
  font-size: 0.9rem;
}
.cart-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.line-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.line-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.line-unit {
  font-size: 0.78rem;
  color: var(--muted);
}

.stepper {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.stepper button {
  width: 28px;
  height: 30px;
  border: 0;
  background: var(--card);
  cursor: pointer;
  color: var(--muted);
}
.stepper button:hover {
  color: var(--text);
  background: var(--surface);
}
.stepper .line-qty {
  width: 46px;
  border: 0;
  border-radius: 0;
  padding: 4px;
  text-align: center;
  background: var(--bg-2);
  -moz-appearance: textfield;
  appearance: textfield;
}
.stepper .line-qty::-webkit-inner-spin-button,
.stepper .line-qty::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.line-total {
  font-family: var(--mono);
  font-size: 0.85rem;
  min-width: 80px;
  text-align: right;
}
.line-remove {
  border: 0;
  background: none;
  color: var(--subtle);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}
.line-remove:hover {
  color: var(--danger);
}

.cart-adjust {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.field-row {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.totals {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.totals div {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--muted);
}
.totals dd {
  margin: 0;
  font-family: var(--mono);
  color: var(--text);
}
.totals .grand {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  padding-top: 6px;
}
.totals .grand dd {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.payment {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.segmented button {
  border: 0;
  background: none;
  padding: 8px 4px;
  border-radius: var(--r-sm);
  color: var(--muted);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.85rem;
}
.segmented button[aria-pressed='true'] {
  background: var(--raised);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.cash-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.quick-cash {
  display: flex;
  gap: 6px;
}
.quick-cash:empty {
  display: none;
}
.quick-cash button {
  flex: 1;
  padding: 6px 4px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.78rem;
}
.quick-cash button:hover {
  border-color: var(--primary);
}
.change {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  color: var(--muted);
}
.change strong {
  font-family: var(--mono);
  font-size: 1.1rem;
  color: var(--success);
}
.change strong.short {
  color: var(--danger);
}

/* ========================================
   Tables
   ======================================== */
.table-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.table-toolbar input[type='search'] {
  max-width: 280px;
}
.table-toolbar select {
  width: auto;
}
.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th {
  text-align: left;
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:hover {
  background: var(--hover);
}
.table .num {
  text-align: right;
  font-family: var(--mono);
  font-size: 0.85rem;
  white-space: nowrap;
}
.table .actions {
  text-align: right;
  white-space: nowrap;
}
.table .actions .btn-link + .btn-link {
  margin-left: 12px;
}
.table .truncate {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.empty-cell {
  text-align: center;
  color: var(--muted);
  padding: 32px 12px !important;
}
.share-col {
  width: 28%;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--muted);
  vertical-align: middle;
}
.badge:empty {
  display: none;
}
.badge.ok {
  background: rgba(52, 211, 153, 0.12);
  color: var(--success);
}
.badge.pending {
  background: rgba(251, 191, 36, 0.12);
  color: var(--warn);
}

/* ========================================
   Receipt designer
   ======================================== */
.designer {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.designer-controls {
  max-height: calc(100vh - var(--topbar-h) - 130px);
  overflow-y: auto;
}
.designer-preview {
  position: sticky;
  top: calc(var(--topbar-h) + 20px);
  min-width: 0;
}
.preview-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.preview-toolbar strong {
  color: var(--text);
}

.paper-stage {
  background: repeating-conic-gradient(
      var(--stage-a) 0% 25%,
      var(--stage-b) 0% 50%
    )
    0 0 / 20px 20px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 32px 20px;
  display: flex;
  justify-content: safe center;
  align-items: flex-start;
  overflow: auto;
  max-height: calc(100vh - var(--topbar-h) - 130px);
}
.paper-stage .rcpt,
.receipt-dialog .rcpt {
  box-shadow: var(--shadow-lg);
}

.template-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.template-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  cursor: pointer;
  font-size: 0.88rem;
}
.template-card:hover {
  border-color: var(--border-2);
}
.template-card[aria-pressed='true'] {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}
.template-card small {
  color: var(--muted);
  font-size: 0.75rem;
}

.template-thumb {
  height: 56px;
  background: #fff;
  border-radius: 4px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  margin-bottom: 6px;
}
.template-thumb i {
  display: block;
  height: 4px;
  width: 70%;
  background: #bbb;
  border-radius: 2px;
}
.template-thumb i:first-child {
  width: 40%;
  height: 6px;
  background: #333;
}
.template-thumb--classic i:nth-child(2) {
  width: 100%;
  height: 2px;
  background: repeating-linear-gradient(90deg, #888 0 4px, transparent 4px 7px);
}
.template-thumb--modern {
  align-items: flex-start;
}
.template-thumb--modern i:first-child {
  width: 55%;
  height: 8px;
  background: #111;
}
.template-thumb--modern i:last-child {
  width: 100%;
  height: 8px;
  background: #111;
}
.template-thumb--minimal {
  gap: 7px;
}
.template-thumb--minimal i {
  background: #e2e2e2;
}
.template-thumb--minimal i:first-child {
  background: #777;
  height: 4px;
}
.template-thumb--invoice {
  flex-direction: row;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: space-between;
}
.template-thumb--invoice i {
  width: 40%;
}
.template-thumb--invoice i:nth-child(n + 3) {
  width: 100%;
  height: 3px;
}

.logo-uploader {
  display: flex;
  gap: 14px;
  align-items: center;
}
.logo-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.logo-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--r);
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
  color: #999;
  font-size: 0.72rem;
  border: 1px solid var(--border);
}
.logo-thumb img {
  max-width: 100%;
  max-height: 100%;
}

/* ========================================
   Reports
   ======================================== */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
}
.kpi span {
  font-size: 0.74rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.kpi strong {
  display: block;
  font-size: 1.35rem;
  margin-top: 4px;
  font-family: var(--mono);
  font-weight: 600;
}
.kpi small {
  color: var(--subtle);
  font-size: 0.78rem;
}
.kpi.highlight {
  background: linear-gradient(
    135deg,
    rgba(99, 102, 241, 0.18),
    rgba(34, 211, 238, 0.08)
  );
  border-color: rgba(99, 102, 241, 0.35);
}

.report-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 20px;
}
.span-2 {
  grid-column: 1 / -1;
}

.chart {
  height: 240px;
  margin-top: 16px;
}
.bars {
  display: flex;
  gap: 4px;
  height: 100%;
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.bar-track {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.bar {
  width: 100%;
  max-width: 36px;
  min-height: 2px;
  background: var(--grad);
  border-radius: 4px 4px 0 0;
  transition: height 0.3s ease;
}
.bar-col:hover .bar {
  filter: brightness(1.25);
}
.bar-label {
  font-size: 0.68rem;
  color: var(--subtle);
  height: 14px;
  white-space: nowrap;
}

.share {
  height: 6px;
  background: var(--surface);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}
.share i {
  display: block;
  height: 100%;
  background: var(--grad);
}

.breakdown {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 16px;
}
.breakdown-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}
.breakdown-head strong {
  font-family: var(--mono);
  font-weight: 500;
}

/* ========================================
   Settings
   ======================================== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 20px;
  align-items: start;
}
.setup summary {
  cursor: pointer;
  color: var(--primary-2);
  font-weight: 500;
  font-size: 0.9rem;
}
.setup[open] {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.steps {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 0.88rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.steps strong,
.steps em {
  color: var(--text);
}
.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
}
pre.code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px;
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.55;
  overflow: auto;
  max-height: 300px;
  color: var(--code-text);
  margin: 0;
}

/* ========================================
   Dialogs & toasts
   ======================================== */
dialog {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 0;
  width: min(92vw, 460px);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(4px);
}
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.dialog-body {
  padding: 20px;
}
.dialog-body p {
  margin: 0;
}
.dialog-foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.dialog-foot .hint {
  margin-right: auto;
}

.receipt-dialog {
  width: auto;
  max-width: min(96vw, 900px);
  max-height: 92vh;
}
.receipt-dialog[open] {
  display: flex;
  flex-direction: column;
}
.receipt-dialog .dialog-body {
  flex: 1;
  min-height: 0;
  background: var(--stage-b);
  overflow: auto;
  display: flex;
  justify-content: safe center;
  align-items: flex-start;
  padding: 28px;
}

.receipt-image {
  display: block;
  max-width: 100%;
  height: auto;
  box-shadow: var(--shadow-lg);
}

.toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--r);
  background: var(--raised);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--success);
  box-shadow: var(--shadow-md);
  font-size: 0.9rem;
  max-width: 360px;
  animation: toast-in 0.2s ease;
  transition: opacity 0.3s, transform 0.3s;
}
.toast--warn {
  border-left-color: var(--warn);
}
.toast--error {
  border-left-color: var(--danger);
}
.toast.out {
  opacity: 0;
  transform: translateY(8px);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ========================================
   Receipt fonts
   ======================================== */
@font-face {
  font-family: 'BitMatrix A5';
  src: url('../fonts/bitMatrix-A5.ttf') format('truetype');
  font-weight: 400;
  font-display: block;
}
@font-face {
  font-family: 'BitMatrix A5';
  src: url('../fonts/bitMatrix-A5-bold.ttf') format('truetype');
  font-weight: 600 900;
  font-display: block;
}
@font-face {
  font-family: 'BitMatrix A5 Wide';
  src: url('../fonts/bitMatrix-A5-wide.ttf') format('truetype');
  font-display: block;
}
@font-face {
  font-family: 'TypeR 05';
  src: url('../fonts/typeR-05.ttf') format('truetype');
  font-display: block;
}

/* ========================================
   Receipt (shared by preview, dialog & print)
   ======================================== */
.rcpt {
  --rcpt-fs: 12px;
  --rcpt-align: center;
  --rcpt-divider: 1px dashed #000;
  flex-shrink: 0;
  background: #fff;
  color: #000;
  font-size: var(--rcpt-fs);
  line-height: 1.35;
  --rcpt-pad-x: 4mm;
  --rcpt-pad-y: 5mm;
  padding: var(--rcpt-pad-y) var(--rcpt-pad-x);
  margin: 0 auto;
  overflow-wrap: anywhere;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.rcpt--paper-58 {
  width: 58mm;
  --rcpt-pad-x: 3mm;
  --rcpt-pad-y: 4mm;
}
.rcpt--paper-80 {
  width: 80mm;
}
.rcpt--paper-a4 {
  width: 210mm;
  --rcpt-pad-x: 15mm;
  --rcpt-pad-y: 16mm;
}
.rcpt--font-mono {
  font-family: 'Courier New', Courier, ui-monospace, monospace;
}
.rcpt--font-sans {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.rcpt--font-serif {
  font-family: Georgia, 'Times New Roman', serif;
}
.rcpt--font-bitmatrix {
  font-family: 'BitMatrix A5', 'Courier New', monospace;
}
.rcpt--font-bitmatrix-wide {
  font-family: 'BitMatrix A5 Wide', 'Courier New', monospace;
}
.rcpt--font-typer {
  font-family: 'TypeR 05', 'Courier New', monospace;
}
/* !important so template rules that lighten parts (e.g. minimal item names) can't undo it. */
.rcpt--bold,
.rcpt--bold * {
  font-weight: 700 !important;
}
.rcpt--bold .rcpt-biz,
.rcpt--bold .rcpt-inv-title,
.rcpt--bold .rcpt-grand td {
  font-weight: 800 !important;
}

.rcpt table {
  width: 100%;
  border-collapse: collapse;
  font-size: inherit;
}
.rcpt td,
.rcpt th {
  padding: 1px 0;
  vertical-align: top;
}
.rcpt .r {
  text-align: right;
  white-space: nowrap;
  padding-left: 8px;
}
.rcpt hr {
  border: 0;
  border-top: var(--rcpt-divider);
  margin: 0.7em 0;
}
.rcpt--divider-none hr {
  margin: 0.45em 0;
}

.rcpt-header {
  text-align: var(--rcpt-align);
}
.rcpt-logo {
  max-width: 100%;
  height: auto;
  margin-bottom: 0.5em;
  vertical-align: top;
}
.rcpt-logo.gray {
  filter: grayscale(1) contrast(1.15);
}
.rcpt-biz {
  font-size: 1.3em;
  font-weight: 700;
  margin-bottom: 0.15em;
}
.rcpt-note {
  margin-top: 0.5em;
  font-style: italic;
}
.rcpt-item-name td {
  padding-top: 0.35em;
  font-weight: 600;
}
.rcpt-item-calc td:first-child {
  padding-left: 1em;
}
.rcpt-kv-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1em;
  padding: 1px 0;
}
.rcpt-kv-key {
  flex-shrink: 0;
  white-space: nowrap;
}
.rcpt-kv-val {
  min-width: 0;
  text-align: right;
}
.rcpt-grand td {
  font-size: 1.25em;
  font-weight: 700;
  padding: 0.25em 0;
}
.rcpt-taxinfo {
  margin-top: 0.6em;
  font-size: 0.9em;
}
.rcpt-count {
  text-align: center;
  font-size: 0.9em;
  margin-top: 0.6em;
}
.rcpt-footer {
  text-align: center;
}
.rcpt-sku {
  font-size: 0.8em;
  color: #666;
}

.rcpt--modern .rcpt-biz {
  font-size: 1.6em;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.rcpt--modern .rcpt-kv-key {
  text-transform: uppercase;
  font-size: 0.8em;
  letter-spacing: 0.06em;
}
.rcpt--modern .rcpt-grand td {
  background: #000;
  color: #fff;
  padding: 0.45em 0.5em;
}

.rcpt--minimal {
  line-height: 1.55;
}
.rcpt--minimal .rcpt-biz {
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 1.1em;
}
.rcpt--minimal .rcpt-item-name td {
  font-weight: 400;
}
.rcpt--minimal .rcpt-grand td {
  font-weight: 600;
  font-size: 1.15em;
}
.rcpt--minimal .rcpt-kv {
  font-size: 0.88em;
  color: #444;
}

.rcpt-inv-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}
.rcpt-inv-head .rcpt-header {
  flex: 1;
}
.rcpt-inv-meta {
  min-width: 40%;
}
.rcpt-inv-title {
  font-size: 1.8em;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: right;
  margin-bottom: 0.3em;
}
.rcpt-inv-items {
  margin-top: 1.8em;
}
.rcpt-inv-items th {
  text-align: left;
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid #000;
  padding: 0.5em 0;
}
.rcpt-inv-items td {
  padding: 0.55em 0;
  border-bottom: 1px solid #ddd;
}
.rcpt-inv-totals {
  margin-left: auto;
  width: 45%;
  margin-top: 1em;
}
.rcpt--invoice .rcpt-grand td {
  border-top: 2px solid #000;
  padding-top: 0.4em;
}
.rcpt--invoice .rcpt-footer {
  margin-top: 2em;
}

.rcpt [data-field] {
  outline: 1px dashed transparent;
  outline-offset: 2px;
  border-radius: 2px;
  cursor: text;
  transition: outline-color 0.15s;
}
.rcpt [data-field]:hover {
  outline-color: #6366f1;
}
.rcpt [data-field]:focus {
  outline: 2px solid #6366f1;
  background: rgba(99, 102, 241, 0.07);
}

/* ========================================
   Print
   ======================================== */
#print-area {
  position: absolute;
  left: -10000px;
  top: 0;
}

@media print {
  html,
  body {
    background: #fff !important;
    min-height: 0;
  }
  body > *:not(#print-area) {
    display: none !important;
  }
  #print-area {
    position: static;
  }
  #print-area .rcpt {
    margin: 0;
    box-shadow: none;
  }
  /* The A4 @page already has a 12mm margin; only print the padding beyond it. */
  #print-area .rcpt--paper-a4 {
    width: auto;
    padding: max(0mm, calc(var(--rcpt-pad-y) - 12mm)) max(0mm, calc(var(--rcpt-pad-x) - 12mm));
  }
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 1180px) {
  .view-pos {
    grid-template-columns: minmax(0, 1fr) 360px;
  }
  .designer {
    grid-template-columns: 1fr;
  }
  .designer-preview {
    position: static;
    order: -1;
  }
  .designer-controls,
  .paper-stage {
    max-height: none;
  }
  .report-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .view-pos,
  .split {
    grid-template-columns: 1fr;
  }
  .pos-cart {
    position: static;
    max-height: none;
  }
  .pos-catalog {
    min-height: 0;
  }
  .topbar {
    gap: 12px;
    padding: 0 12px;
  }
  .brand-name {
    display: none;
  }
  main {
    padding: 12px;
  }
  .custom-item-fields {
    grid-template-columns: 1fr 1fr;
  }
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .grid-2,
  .checks,
  .template-picker {
    grid-template-columns: 1fr;
  }
  .sync-status {
    display: none;
  }
}
