:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #64717d;
  --line: #dbe1e7;
  --page: #f7f8fa;
  --panel: #ffffff;
  --brand: #7d1f2d;
  --brand-2: #0f766e;
  --blue: #2563eb;
  --amber: #b45309;
  --green: #15803d;
  --danger: #b91c1c;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body,
#app {
  height: 100%;
}

html {
  background: var(--page);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  font-size: 16px;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.shell {
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  background: #101820;
  color: white;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #7d1f2d, #d6a756);
  color: white;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.brand p {
  margin: 2px 0 0;
  color: rgba(255, 255, 255, 0.65);
  font-size: 12px;
}

.role-card {
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  display: grid;
  gap: 8px;
}

.role-card label {
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
}

.role-card select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: white;
  background: #172632;
  border-radius: 6px;
  padding: 9px;
}

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

.nav button {
  color: rgba(255, 255, 255, 0.76);
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  gap: 9px;
}

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

.nav-group-button {
  min-height: 42px;
  color: white !important;
  background: linear-gradient(135deg, #0ea5e9, #2563eb) !important;
  font-weight: 700;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.22);
  justify-content: space-between;
}

.nav-group-state {
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  font-weight: 500;
}

.nav-children {
  display: grid;
  gap: 4px;
  padding-left: 8px;
}

.nav-children button {
  min-height: 36px;
}

.nav button.active,
.nav button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-footer {
  margin-top: auto;
  color: rgba(255, 255, 255, 0.55);
  font-size: 12px;
  line-height: 1.5;
}

.main {
  min-width: 0;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(247, 248, 250, 0.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding: max(18px, env(safe-area-inset-top)) 28px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.mobile-menu {
  display: none;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
}

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

.button {
  min-height: 42px;
  border-radius: 7px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: #111827;
  color: white;
  white-space: nowrap;
}

.button.secondary {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
}

.button.green {
  background: var(--green);
}

.button.danger {
  background: var(--danger);
}

.content {
  padding: 24px 28px max(40px, calc(24px + env(safe-area-inset-bottom)));
  display: grid;
  gap: 18px;
}

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

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

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

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

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

.section {
  display: grid;
  gap: 12px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-head h3 {
  margin: 0;
  font-size: 16px;
}

.section-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.metric {
  padding: 16px;
  display: grid;
  gap: 8px;
  min-height: 114px;
}

.metric .label {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 27px;
  line-height: 1.05;
}

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

.metric.accent {
  border-top: 4px solid var(--brand);
}

.metric.blue {
  border-top: 4px solid var(--blue);
}

.metric.green {
  border-top: 4px solid var(--green);
}

.metric.amber {
  border-top: 4px solid var(--amber);
}

.panel {
  padding: 16px;
}

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

.amount-in {
  color: var(--green);
  font-weight: 700;
}

.amount-out {
  color: var(--danger);
  font-weight: 700;
}

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

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

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

th {
  color: var(--muted);
  font-weight: 650;
  background: #f9fafb;
}

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

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

.badge.green {
  color: #166534;
  background: #dcfce7;
}

.badge.amber {
  color: #92400e;
  background: #fef3c7;
}

.badge.red {
  color: #991b1b;
  background: #fee2e2;
}

.badge.blue {
  color: #1d4ed8;
  background: #dbeafe;
}

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

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

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

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

.field label {
  color: var(--muted);
  font-size: 12px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 44px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: white;
  padding: 8px 10px;
  color: var(--ink);
}

.field.invalid label {
  color: var(--danger);
}

.field.invalid input,
.field.invalid select,
.field.invalid textarea {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

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

.password-wrap {
  position: relative;
}

.password-wrap input {
  padding-right: 64px;
}

.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 48px;
  height: 28px;
  border-radius: 6px;
  color: var(--blue);
  background: #eff6ff;
  font-size: 12px;
}

.split {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
}

.bars {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.bar-track {
  height: 9px;
  border-radius: 999px;
  background: #edf2f7;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), #d6a756);
}

.timeline {
  display: grid;
  gap: 10px;
}

.timeline-item {
  border-left: 3px solid var(--line);
  padding-left: 12px;
}

.timeline-item strong {
  display: block;
  font-size: 14px;
}

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

.notice {
  padding: 12px 14px;
  border-radius: 8px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  background: #101820;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  max-width: min(420px, calc(100vw - 36px));
}

.hidden {
  display: none !important;
}

.product-img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 7px;
  background: #f1f5f9;
  border: 1px solid var(--line);
}

.product-img.placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.stock-panel {
  min-height: 38px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.stock-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 7px;
  padding: 0 10px;
  color: white;
  font-size: 13px;
  font-weight: 700;
}

.stock-chip.green {
  background: var(--green);
}

.stock-chip.amber {
  background: var(--amber);
}

.stock-chip.red {
  background: var(--danger);
}

.stock-chip.blue {
  background: var(--blue);
}

.price-list {
  display: grid;
  gap: 4px;
  min-width: 180px;
}

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

.usage-grid {
  display: grid;
  gap: 8px;
}

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

.usage-row span {
  display: grid;
  gap: 2px;
  color: var(--ink);
  font-size: 13px;
}

.usage-row small {
  color: var(--muted);
}

.customer-icon,
.inline-icon {
  display: inline-flex;
  width: 20px;
  height: 20px;
  vertical-align: middle;
  margin-left: 4px;
}

.customer-icon svg,
.inline-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.customer-icon.active {
  color: #f59e0b;
}

.customer-icon.vip {
  color: #7c3aed;
}

.inline-icon.warning {
  width: 16px;
  height: 16px;
  fill: none;
  color: var(--amber);
  margin: 0 3px 0 0;
}

.warning-line {
  color: var(--amber);
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-top: 3px;
}

.segmented.compact {
  width: min(360px, 100%);
  max-width: 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-self: start;
}

.segmented.compact button {
  min-width: 0;
  padding: 0 16px;
  white-space: nowrap;
}

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

.mini-button {
  min-height: 30px;
  border-radius: 6px;
  padding: 0 9px;
  background: #f1f5f9;
  color: var(--ink);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.mini-button.primary {
  color: white;
  background: #111827;
  border-color: #111827;
}

.mini-button.green {
  color: white;
  background: var(--green);
  border-color: var(--green);
}

.mini-button.danger {
  color: white;
  background: var(--danger);
  border-color: var(--danger);
}

.empty {
  min-height: 120px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
}

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

  .grid.cols-3,
  .split {
    grid-template-columns: 1fr;
  }

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

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

  .sidebar {
    position: fixed;
    z-index: 12;
    inset: 0 auto 0 0;
    width: min(304px, calc(100vw - 28px));
    transform: translateX(-100%);
    transition: transform 160ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: inline-grid;
    place-items: center;
  }

  .topbar {
    padding: max(14px, env(safe-area-inset-top)) 16px 14px;
    align-items: flex-start;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
  }

  .topbar h2 {
    font-size: 19px;
  }

  .content {
    padding: 16px 14px max(24px, calc(14px + env(safe-area-inset-bottom)));
  }

  .grid.cols-4,
  .grid.cols-3,
  .grid.cols-2,
  .quick-ledger,
  .form,
  .form.wide {
    grid-template-columns: 1fr;
  }

  .usage-row {
    grid-template-columns: 1fr;
  }

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

  .actions {
    width: 100%;
    justify-content: flex-start;
  }

  .button {
    min-width: 0;
    flex: 1;
  }

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

  .brand h1,
  .brand p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .metric strong {
    font-size: 24px;
  }
}

@media (max-width: 520px) {
  .login-page {
    min-height: 100dvh;
    place-items: stretch;
    padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  }

  .login-card {
    align-self: center;
    width: 100%;
    box-shadow: none;
  }

  .login-brand img {
    width: 48px;
    height: 48px;
  }

  .login-brand h1 {
    font-size: 20px;
  }

  .section-head .button,
  .section-head .mini-button,
  .actions .button {
    width: 100%;
  }

  .segmented.compact {
    width: 100%;
  }

  table {
    min-width: 680px;
  }

  th,
  td {
    padding: 10px;
  }

  .modal-backdrop {
    align-items: end;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .modal-card {
    width: 100%;
    max-height: min(86dvh, calc(100dvh - 24px));
    border-radius: 10px;
    padding: 16px;
  }
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  object-fit: cover;
  background: #0f172a;
  flex: 0 0 auto;
}

.identity-card {
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  display: grid;
  gap: 6px;
}

.identity-card span {
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
}

.identity-card strong {
  color: white;
  font-size: 14px;
  line-height: 1.4;
}

.logout-button {
  margin-top: auto;
  min-height: 38px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

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

.login-card {
  width: min(460px, 100%);
}

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

.login-brand img {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  object-fit: cover;
  background: #0f172a;
}

.login-brand h1 {
  margin: 0;
  font-size: 22px;
}

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

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.segmented button {
  min-height: 36px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}

.segmented button.active {
  color: white;
  background: #111827;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 2px 8px 2px 0;
  color: var(--ink);
  white-space: nowrap;
}

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

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.link-button {
  padding: 0;
  color: var(--blue);
  background: transparent;
  text-align: left;
}

.search-input {
  min-height: 44px;
  border-radius: 7px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  min-width: min(360px, 100%);
}

.pager {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.48);
}

.modal-card {
  width: min(620px, 100%);
  max-height: min(780px, calc(100vh - 40px));
  overflow: auto;
  padding: 18px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 {
  margin: 0;
  font-size: 18px;
}

.modal-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.modal-close {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: #f1f5f9;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

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

.modal-form .full,
.modal-form .notice,
.modal-actions {
  grid-column: 1 / -1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 6px;
}

@media (max-width: 780px) {
  .modal-form {
    grid-template-columns: 1fr;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }
}
