:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #d8dee8;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #b45309;
  --danger: #b91c1c;
  --good: #047857;
  --soft: #eef6f5;
  --warn: #fff7ed;
  --radius: 8px;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  min-width: 320px;
}

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

button {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  color: #fff;
  background: var(--brand);
}

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

button.secondary {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

button.secondary:hover {
  background: #f3f4f6;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

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

label {
  display: grid;
  gap: 6px;
  color: #374151;
  font-size: 14px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, #e8f5f3 0%, #f7f2e8 54%, #eef2f6 100%);
}

.login-panel {
  width: min(430px, 100%);
  background: var(--panel);
  border: 1px solid rgba(15, 118, 110, 0.16);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 24px 60px rgba(31, 41, 51, 0.12);
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.login-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.login-head .secondary {
  white-space: nowrap;
}

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

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

.sidebar {
  min-height: 0;
  height: 100vh;
  background: #17212b;
  color: #fff;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.brand {
  min-width: 0;
  padding: 6px 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

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

.brand small {
  color: rgba(255, 255, 255, 0.68);
}

.sidebar-head {
  min-width: 0;
}

.mobile-nav-close,
.mobile-menu-button,
.nav-backdrop {
  display: none;
}

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

.nav button {
  width: 100%;
  text-align: left;
  color: rgba(255, 255, 255, 0.88);
  background: transparent;
  border-color: transparent;
}

.nav-parent {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.nav-arrow {
  color: rgba(255, 255, 255, 0.72);
}

.subnav {
  display: grid;
  gap: 4px;
  padding-left: 14px;
  margin-top: -2px;
}

.subnav button {
  font-size: 13px;
  padding: 7px 10px;
  color: rgba(255, 255, 255, 0.72);
}

.subnav button.active {
  color: #fff;
  background: rgba(15, 118, 110, 0.58);
}

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

.nav .subnav button.active {
  color: #fff;
  background: rgba(15, 118, 110, 0.58);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
}

.main {
  min-width: 0;
  min-height: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  height: 64px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
}

.topbar h2 {
  margin: 0;
  font-size: 20px;
}

.topbar-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.content {
  min-height: 0;
  padding: 22px;
  display: grid;
  gap: 16px;
  align-content: start;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.panel h3 {
  margin: 0 0 14px;
  font-size: 17px;
}

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

.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));
}

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

.notice {
  border: 1px solid #fed7aa;
  background: var(--warn);
  color: #7c2d12;
  border-radius: 6px;
  padding: 10px 12px;
}

.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #14532d;
}

.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #7f1d1d;
}

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

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

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

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

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f3f6f9;
  color: #374151;
  font-weight: 600;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  background: #e5e7eb;
  color: #374151;
}

.pill.good {
  background: #dcfce7;
  color: #166534;
}

.pill.warn {
  background: #ffedd5;
  color: #9a3412;
}

.pill.bad {
  background: #fee2e2;
  color: #991b1b;
}

.person-row,
.setting-row,
.rule-row {
  display: grid;
  grid-template-columns: 1fr 110px auto;
  gap: 8px;
  align-items: end;
}

.setting-row {
  grid-template-columns: 1fr auto auto;
  margin-bottom: 8px;
}

.menu-item-row {
  grid-template-columns: minmax(180px, 1fr) 120px 150px 110px auto;
}

.rule-row {
  grid-template-columns: 90px 76px 110px 120px 120px;
  align-items: center;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.metric {
  background: var(--soft);
  border: 1px solid #cfe6e2;
  border-radius: var(--radius);
  padding: 14px;
}

.metric strong {
  display: block;
  font-size: 24px;
  margin-top: 4px;
}

.metric-muted {
  background: #f3f4f6;
  border-color: #d1d5db;
}

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

.section-head h3 {
  margin: 0;
}

.sticky-actions {
  position: sticky;
  bottom: -1px;
  z-index: 8;
  margin: 14px -16px -16px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
}

.settings-save-bar {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.plan-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: start center;
  padding: 48px 18px;
  background: rgba(15, 23, 42, 0.36);
  overflow: auto;
}

.modal {
  width: min(980px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
  padding: 16px;
  display: grid;
  gap: 14px;
}

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

.modal-head h3,
.modal-section h3 {
  margin: 0;
}

.modal-section {
  display: grid;
  gap: 10px;
}

.modal-rule-row {
  display: grid;
  grid-template-columns: 80px minmax(90px, 110px) minmax(150px, 1fr) minmax(115px, 130px) minmax(130px, 150px) minmax(115px, 130px) auto;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fafb;
}

.modal-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

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

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.check-row input {
  width: auto;
}

.hidden-card-input {
  position: static;
  width: 1px;
  height: 1px;
  opacity: 0;
  padding: 0;
  border: 0;
  color: transparent;
  caret-color: transparent;
}

.card-read-box {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.reader-card-input {
  width: 150px;
  min-width: 130px;
}

.charge-summary {
  margin-bottom: 12px;
}

.charge-items-box {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

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

.charge-items-head h3 {
  margin: 0;
}

.charge-item-row {
  display: grid;
  grid-template-columns: minmax(145px, 0.7fr) minmax(240px, 1.3fr) 90px 110px auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 8px;
}

.charge-total {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 10px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.charge-total strong {
  font-size: 22px;
}

.password-modal,
.reason-modal {
  width: min(560px, 100%);
}

.menu-settings-toolbar,
.menu-items-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

#restaurantMenuCategories {
  display: grid;
  gap: 10px;
}

.menu-category-block {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  overflow: clip;
}

.menu-category-block > summary {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  cursor: pointer;
  background: #f7f9fb;
  list-style-position: inside;
}

.menu-category-block[open] > summary {
  border-bottom: 1px solid var(--line);
}

.menu-category-title {
  min-width: 0;
  overflow-wrap: anywhere;
}

.menu-category-title strong {
  display: inline-block;
  min-width: 38px;
  margin-right: 6px;
  color: var(--brand-dark);
}

.menu-category-body {
  padding: 14px;
}

.menu-category-fields {
  display: grid;
  grid-template-columns: 130px minmax(220px, 1fr) 110px auto;
  align-items: end;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.menu-item-row {
  grid-template-columns: 130px minmax(240px, 1fr) 120px 110px auto;
}

.menu-empty {
  padding: 12px 0;
}

.restaurant-scan-panel {
  border-top: 3px solid var(--brand);
}

.restaurant-scan-controls {
  display: grid;
  grid-template-columns: minmax(150px, 0.7fr) minmax(170px, 0.9fr) minmax(300px, 1.5fr) auto;
  gap: 12px;
  align-items: end;
}

.scan-actions {
  align-items: end;
  padding-bottom: 1px;
}

.scan-ready {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--good);
  font-size: 14px;
}

.scan-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 4px rgba(4, 120, 87, 0.12);
}

.scan-result-state {
  display: grid;
  gap: 5px;
  text-align: center;
  padding: 28px 18px;
}

.scan-result-state strong {
  font-size: 22px;
}

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

.meal-match-card {
  border-left: 4px solid var(--brand);
}

.meal-match-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.meal-match-head > div {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.meal-match-head strong {
  font-size: 20px;
  overflow-wrap: anywhere;
}

.meal-room {
  font-size: 30px;
  line-height: 1;
  font-weight: 700;
  color: var(--brand-dark);
}

.meal-match-facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 8px;
  padding: 12px;
  background: #f7f9fb;
  border-radius: 6px;
}

.meal-match-facts div,
.log-detail-grid div {
  display: grid;
  gap: 3px;
}

.meal-match-facts span,
.log-detail-grid span {
  color: var(--muted);
  font-size: 12px;
}

.meal-check-entry {
  display: grid;
  grid-template-columns: minmax(150px, 0.5fr) minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}

.meal-check-entry input[type="number"] {
  font-size: 20px;
  font-weight: 700;
}

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

.compact-button {
  min-height: 34px;
  padding: 5px 9px;
}

.log-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  background: #f7f9fb;
  border-radius: 6px;
}

.log-detail-json {
  max-height: 52vh;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101820;
  color: #eef2f6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 70;
    width: min(82vw, 300px);
    height: 100dvh;
    max-height: 100dvh;
    overflow-y: auto;
    box-shadow: 18px 0 40px rgba(15, 23, 42, 0.24);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .app-shell.nav-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-head {
    display: flex;
    align-items: flex-start;
    gap: 8px;
  }

  .sidebar-head .brand {
    flex: 1;
  }

  .mobile-nav-close {
    display: inline-grid;
    place-items: center;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    padding: 0;
    color: #fff;
    background: transparent;
    border-color: rgba(255, 255, 255, 0.18);
    font-size: 26px;
    line-height: 1;
  }

  .nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(15, 23, 42, 0.46);
  }

  .app-shell.nav-open .nav-backdrop {
    display: block;
  }

  .mobile-menu-button {
    display: inline-grid;
    place-items: center;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    padding: 0;
    font-size: 21px;
  }

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

  .topbar {
    z-index: 40;
    min-height: 62px;
    height: auto;
    padding: 10px 12px;
    gap: 10px;
  }

  .topbar-title {
    flex: 1;
  }

  .topbar h2 {
    min-width: 0;
    font-size: 18px;
    line-height: 1.3;
  }

  .topbar-actions {
    gap: 8px;
  }

  .topbar-actions .secondary {
    min-height: 42px;
    padding: 7px 10px;
  }

  .topbar-actions .muted {
    display: none;
  }

  .content {
    padding: 12px;
    gap: 12px;
  }

  .main {
    height: 100dvh;
  }

  .panel {
    padding: 13px;
  }

  .person-row,
  .setting-row,
  .rule-row,
  .menu-item-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

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

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

  .menu-category-fields,
  .menu-item-row,
  .restaurant-scan-controls,
  .meal-check-entry {
    grid-template-columns: 1fr;
  }

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

  .reader-card-input {
    width: min(150px, 100%);
    min-width: 0;
  }

  .card-read-box,
  .charge-items-head {
    flex-wrap: wrap;
  }

  .modal-backdrop {
    padding: 0;
    place-items: stretch;
  }

  .modal {
    width: 100%;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 14px;
  }
}

@media (max-width: 700px) {
  .login-shell {
    place-items: stretch;
    padding: 0;
    background: #fff;
  }

  .login-panel {
    width: 100%;
    min-height: 100dvh;
    padding: max(24px, env(safe-area-inset-top)) 20px 24px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    align-content: center;
  }

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

  .login-head {
    gap: 10px;
  }

  input,
  select,
  textarea,
  button {
    min-height: 44px;
  }

  .actions > input,
  .actions > select,
  .actions > label {
    flex: 1 1 100%;
    max-width: none !important;
  }

  .actions > button {
    flex: 1 1 120px;
  }

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

  .metric {
    padding: 12px;
  }

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

  .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tbody tr {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
  }

  tbody td {
    display: grid;
    grid-template-columns: minmax(88px, 36%) minmax(0, 1fr);
    gap: 10px;
    min-height: 42px;
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    white-space: normal;
    overflow-wrap: anywhere;
  }

  tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
  }

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

  tbody td .actions {
    align-items: stretch;
  }

  .charge-total {
    justify-content: space-between;
  }

  .sticky-actions {
    margin-inline: -13px;
    padding-inline: 13px;
  }

  .menu-settings-toolbar,
  .menu-items-head,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .menu-category-block > summary {
    align-items: flex-start;
  }

  .meal-match-head > div {
    display: grid;
    gap: 6px;
  }

  .meal-room {
    font-size: 27px;
  }

  .log-detail-grid {
    grid-template-columns: 1fr;
  }
}

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

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

  .topbar-actions .secondary {
    padding-inline: 8px;
  }
}
