:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #15202b;
  --muted: #667085;
  --line: #d8dee8;
  --primary: #176b87;
  --primary-dark: #0f5268;
  --accent: #2e7d32;
  --danger: #b42318;
  --warn-bg: #fff8e6;
  --shadow: 0 14px 32px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Tahoma, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

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

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

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 18px;
  background: #111827;
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #e2f3f5;
  color: #0f5268;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #aeb8c8;
  font-size: 12px;
}

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

.nav a {
  border-radius: 8px;
  color: #d0d5dd;
  padding: 10px 12px;
}

.nav a.active,
.nav a:hover {
  background: #233044;
  color: #fff;
}

.logout-form {
  margin-top: auto;
}

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

.page-header,
.section-header,
.toolbar-band,
.row-actions,
.form-actions,
.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-header {
  justify-content: space-between;
  margin-bottom: 20px;
}

.page-header h1,
.content-section h2,
.layout-card h2 {
  margin: 0;
}

.page-header h1 {
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button,
.text-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.primary-button {
  background: var(--primary);
  color: #fff;
  padding: 0 16px;
}

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

.secondary-button,
.icon-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
}

.ghost-button {
  width: 100%;
  border: 1px solid #344054;
  background: transparent;
  color: #fff;
  padding: 0 14px;
}

.danger-button {
  background: #fff1f0;
  color: var(--danger);
  padding: 0 12px;
}

.text-link {
  color: var(--primary);
  min-height: auto;
}

.wide {
  width: 100%;
}

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

.flash.success {
  background: #eaf7ed;
  color: #1b5e20;
}

.flash.error {
  background: #fff1f0;
  color: var(--danger);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card,
.content-section,
.layout-card,
.login-panel,
.settings-panel,
.preview-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 18px;
}

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

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.content-section {
  padding: 18px;
}

.content-section.narrow {
  max-width: 920px;
}

.section-header {
  justify-content: space-between;
  margin-bottom: 14px;
}

.toolbar-band {
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.search-form {
  display: flex;
  gap: 10px;
  width: min(100%, 560px);
}

.search-form input {
  flex: 1;
}

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

textarea {
  resize: vertical;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.form-stack {
  display: grid;
  gap: 14px;
}

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

.form-grid.compact {
  gap: 12px;
}

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

.form-actions {
  margin-top: 4px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td small {
  color: var(--muted);
}

.right {
  text-align: right;
}

.row-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 10px;
  background: #eef2f6;
  color: #475467;
  font-size: 12px;
  font-weight: 700;
}

.status.active {
  background: #eaf7ed;
  color: #1b5e20;
}

.status.inactive {
  background: #f2f4f7;
  color: #667085;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.import-form {
  display: flex;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
}

.import-form label {
  flex: 1;
}

.layout-list {
  display: grid;
  gap: 12px;
}

.layout-card {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 16px;
  padding: 16px;
}

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

.default-pill {
  border-radius: 999px;
  background: #e2f3f5;
  color: var(--primary-dark);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
}

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

.settings-panel,
.preview-panel {
  padding: 18px;
}

.switch-row {
  flex-wrap: wrap;
  margin: 16px 0;
}

.switch-row label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.switch-row input {
  width: auto;
}

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

.field-row {
  display: grid;
  grid-template-columns: 70px 1fr 90px;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.field-row:last-child {
  border-bottom: 0;
}

.field-row.head {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field-row input[type='checkbox'] {
  width: 18px;
  height: 18px;
}

.field-row input[type='number'] {
  padding: 6px 8px;
}

.receipt-preview {
  display: grid;
  justify-content: center;
  padding: 18px 0;
  background: repeating-linear-gradient(45deg, #f7f8fa, #f7f8fa 8px, #eef2f6 8px, #eef2f6 16px);
}

.receipt-paper {
  display: flex;
  width: var(--paper-width, 80mm);
  min-height: 130mm;
  flex-direction: column;
  gap: 4px;
  padding: var(--margin-top, 4mm) var(--margin-side, 3mm) 8mm;
  background: #fff;
  color: #000;
  font-family: Tahoma, Arial, sans-serif;
  text-align: center;
}

.receipt-paper.with-border,
.print-ready.with-border {
  border: 1px dashed #111;
}

.receipt-paper h1,
.receipt-paper h2 {
  margin: 0 0 4px;
  font-weight: 800;
  line-height: 1.15;
}

.preview-lines {
  display: flex;
  flex-direction: column;
  gap: inherit;
}

.preview-line,
.print-line {
  display: grid;
  gap: 2px;
  line-height: 1.25;
}

.preview-line span,
.print-line span {
  color: #444;
  font-size: 0.82em;
}

.preview-line strong,
.print-line strong {
  overflow-wrap: anywhere;
}

.preview-barcode,
.print-barcode {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 2px auto;
}

.setting-note {
  border: 1px solid #f5d78e;
  border-radius: 8px;
  background: var(--warn-bg);
  color: #6b4e00;
  padding: 12px;
  font-weight: 700;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: #eef2f6;
}

.login-panel {
  width: min(100%, 420px);
  padding: 26px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.login-brand h1,
.login-brand p {
  margin: 0;
}

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

.not-found {
  display: grid;
  min-height: 50vh;
  place-items: center;
  text-align: center;
}

.not-found h1 {
  margin: 0;
  font-size: 64px;
}

.print-body {
  background: #eef2f6;
}

.print-toolbar {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 18px;
}

.print-sheet {
  display: grid;
  justify-content: center;
  gap: 12px;
  padding: 0 0 28px;
}

.print-ready {
  width: var(--paper-width);
  min-height: auto;
  padding: var(--margin-top) var(--margin-side) 8mm;
  box-shadow: var(--shadow);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

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

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

  .layout-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 18px;
  }

  .page-header,
  .toolbar-band,
  .import-form,
  .search-form {
    align-items: stretch;
    flex-direction: column;
  }

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

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

@media print {
  @page {
    size: var(--paper-width) auto;
    margin: 0;
  }

  body {
    background: #fff;
  }

  .print-toolbar {
    display: none;
  }

  .print-sheet {
    display: block;
    padding: 0;
  }

  .print-ready {
    box-shadow: none;
    page-break-after: always;
  }
}
