:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-2: #eef3f2;
  --ink: #18201f;
  --muted: #61706d;
  --line: #d7dfdc;
  --primary: #126b5f;
  --primary-strong: #0b5349;
  --accent: #2456a6;
  --warn: #986a12;
  --danger: #b9332b;
  --good: #1f7a43;
  --shadow: 0 12px 30px rgba(15, 30, 35, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.login-brand {
  color: var(--ink);
  padding: 0;
}

.login-panel h1 {
  font-size: 22px;
}

.login-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.label-caption {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.required-star {
  color: var(--danger);
  font-weight: 800;
}

.password-input {
  position: relative;
  display: block;
}

.password-input input {
  padding-right: 72px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  min-width: 56px;
  min-height: 30px;
  transform: translateY(-50%);
  border: 1px solid transparent;
  border-radius: 6px;
  background: #eef3f2;
  color: var(--primary);
  font-size: 12px;
}

.password-toggle:hover {
  border-color: var(--line);
  background: #ffffff;
}

.login-error {
  color: var(--danger);
}

.app-shell[hidden],
.login-view[hidden] {
  display: none !important;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  background: #162321;
  color: #edf5f2;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: #e5b642;
  color: #162321;
  border-radius: 8px;
  font-weight: 800;
}

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

.brand span {
  color: #afbfbb;
  font-size: 12px;
  margin-top: 2px;
}

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

.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  text-align: left;
  color: #d8e5e1;
  background: transparent;
}

.nav-item:hover,
.nav-item.active {
  background: #24413b;
  border-color: #375e56;
  color: #ffffff;
}

.store-box {
  margin-top: auto;
  padding: 12px;
  border: 1px solid #37514b;
  border-radius: 8px;
  background: #1d302c;
}

.store-box span,
.store-box strong {
  display: block;
}

.store-box small {
  display: block;
  margin-top: 6px;
  color: #d5e0dd;
  font-size: 12px;
  line-height: 1.35;
}

.store-box small.danger {
  color: #ffd0cc;
}

.store-box span {
  color: #afbfbb;
  font-size: 12px;
}

.store-box select {
  margin-top: 10px;
  border-color: #37514b;
  background: #162321;
  color: #edf5f2;
}

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

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

.topbar p {
  margin-top: 5px;
  color: var(--muted);
}

.top-actions,
.inline-actions,
.filter-bar,
.field-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.lang-switch {
  min-height: 38px;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f2;
}

.lang-btn {
  min-width: 54px;
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 9px;
}

.lang-btn.active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(15, 30, 35, 0.08);
}

.user-pill {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
}

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

.btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #ffffff;
  color: var(--ink);
}

.btn:hover {
  border-color: #9cafaa;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn.primary:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

.status-bar {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid #bdd3ce;
  border-radius: 8px;
  background: #edf8f5;
  color: #174f45;
}

.status-bar.error {
  border-color: #efbbb7;
  background: #fff0ef;
  color: #8e251e;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric-grid.compact {
  grid-template-columns: repeat(6, minmax(140px, 1fr));
}

.metric-tile {
  min-height: 92px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.metric-tile span {
  color: var(--muted);
}

.metric-tile strong {
  margin-top: 10px;
  font-size: 24px;
  line-height: 1.15;
}

.metric-tile.warn strong {
  color: var(--warn);
}

.metric-tile.danger strong {
  color: var(--danger);
}

.split-layout,
.sale-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.9fr);
  gap: 14px;
}

.sale-grid {
  grid-template-columns: minmax(320px, 0.75fr) minmax(460px, 1.25fr);
}

.work-panel {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-heading {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.quiet {
  color: var(--muted);
  margin-bottom: 12px;
  overflow-wrap: anywhere;
}

.import-result {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.6;
}

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

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

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

th {
  color: var(--muted);
  background: #f2f5f4;
  font-weight: 600;
}

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

.product-table td:nth-child(2),
.cart-table td:nth-child(1) {
  white-space: normal;
  min-width: 220px;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 8px;
  background: #edf2f7;
  color: #355066;
  font-size: 12px;
}

.badge.danger {
  background: #fff0ef;
  color: var(--danger);
}

.badge.warn {
  background: #fff5df;
  color: var(--warn);
}

.badge.good {
  background: #eaf7ef;
  color: var(--good);
}

.permission-summary {
  max-width: 220px;
  color: var(--muted);
  font-size: 13px;
}

.permission-list {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
}

.permission-list strong,
.permission-list small {
  display: block;
}

.permission-list small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.field-row label,
.field-grid label,
.totals label,
.modal label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.field-row label {
  flex: 1 1 260px;
}

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

.installment-panel {
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
}

.installment-panel .field-grid {
  margin: 10px 0 0;
}

.installment-schedule {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  padding-top: 4px;
  order: 2;
}

.installment-fields > label:nth-child(3),
.installment-fields > label:nth-child(4) {
  order: 3;
}

.installment-schedule h3 {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
}

.installment-date-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
}

.installment-date-grid label {
  margin: 0;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
}

.check-row input {
  width: 18px;
  min-height: 18px;
  margin: 0;
}

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

.plain-number {
  appearance: textfield;
  -moz-appearance: textfield;
}

.plain-number::-webkit-outer-spin-button,
.plain-number::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

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

.filter-bar {
  margin-bottom: 12px;
}

.filter-bar input {
  flex: 1 1 260px;
}

.filter-bar select {
  max-width: 220px;
}

.search-list {
  display: grid;
  gap: 8px;
  max-height: 62vh;
  overflow: auto;
}

.result-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.result-main strong,
.result-main span {
  display: block;
}

.result-main span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.cart-table input {
  width: 92px;
}

.totals {
  display: grid;
  grid-template-columns: minmax(120px, 180px) auto auto auto;
  align-items: end;
  gap: 14px;
  margin: 12px 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.cart-warning {
  margin: -2px 0 12px;
  color: var(--warn);
  font-size: 13px;
}

.totals div span,
.totals div strong {
  display: block;
  text-align: right;
}

.totals div span {
  color: var(--muted);
}

.totals div strong {
  margin-top: 4px;
  font-size: 22px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 12px;
}

.bar-layout {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(280px, 1fr) minmax(360px, 1.2fr);
  gap: 20px;
  align-items: start;
}

.bar-table-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.bar-table-card {
  min-height: 108px;
  display: grid;
  align-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  color: var(--text);
  text-align: left;
  padding: 14px;
  cursor: pointer;
}

.bar-table-card strong,
.bar-table-card span,
.bar-table-card small {
  display: block;
}

.bar-table-card span,
.bar-table-card small {
  color: var(--muted);
}

.bar-table-card.occupied {
  border-color: rgba(18, 120, 103, 0.4);
  background: #eef8f5;
}

.bar-table-card.selected {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.inline-actions.right {
  justify-content: flex-end;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 20, 22, 0.5);
  z-index: 20;
}

.modal {
  width: min(760px, 100%);
  max-height: min(820px, 92vh);
  overflow: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
}

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

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

.modal-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.print-area {
  display: none;
}

.print-doc {
  color: #000000;
  background: #ffffff;
  font-family: Arial, sans-serif;
}

.print-doc h1 {
  font-size: 24px;
  margin-bottom: 4px;
}

.print-doc .print-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 2px solid #000000;
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.print-doc .print-meta {
  text-align: right;
  line-height: 1.5;
}

.print-doc table {
  border-collapse: collapse;
  width: 100%;
}

.print-doc th,
.print-doc td {
  border-bottom: 1px solid #333333;
  color: #000000;
  padding: 7px 6px;
}

.print-doc .print-total {
  margin-top: 12px;
  margin-left: auto;
  width: 280px;
  display: grid;
  gap: 6px;
}

.print-doc .print-total div {
  display: flex;
  justify-content: space-between;
}

.print-doc .installment-print-schedule {
  margin-top: 12px;
}

.print-doc .installment-print-schedule h2 {
  margin: 0 0 6px;
  font-size: 15px;
}

.print-doc .installment-print-schedule table {
  font-size: 12px;
}

.print-doc.receipt {
  width: 76mm;
  font-size: 12px;
}

.print-doc.receipt h1 {
  font-size: 18px;
}

.print-doc.receipt .print-head {
  display: block;
  text-align: center;
}

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

.print-doc.receipt th,
.print-doc.receipt td {
  padding: 5px 2px;
  white-space: normal;
}

.print-doc.receipt .print-total {
  width: 100%;
}

@media (max-width: 1120px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .split-layout,
  .sale-grid,
  .bar-layout {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    position: static;
  }

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

  .main-panel {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .metric-grid.compact,
  .field-grid,
  .modal-body,
  .totals {
    grid-template-columns: 1fr;
  }

  .totals div span,
  .totals div strong {
    text-align: left;
  }
}

@media print {
  @page {
    margin: 12mm;
  }

  body {
    background: #ffffff;
  }

  .app-shell,
  .modal-overlay {
    display: none !important;
  }

  .print-area {
    display: block;
  }

  .print-area .print-doc {
    display: block;
  }
}
