:root, [data-theme="light"] {
  --bg: #f4efe8;
  --card: #ffffff;
  --text: #1c1410;
  --muted: #6d625a;
  --line: #eadfd4;
  --accent: #c45c26;
  --accent-2: #e8893a;
  --side: #2b211c;
  --side-text: #f7f1ea;
  --side-muted: #cbbbae;
  --good: #157a45;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(44, 28, 16, .08);
}
[data-theme="dark"] {
  --bg: #12100e;
  --card: #1e1916;
  --text: #f6f1ea;
  --muted: #b5a79c;
  --line: #3a312b;
  --accent: #e8893a;
  --accent-2: #f0a35a;
  --side: #0c0a09;
  --side-text: #f6f1ea;
  --side-muted: #b5a79c;
  --good: #3ddc84;
  --danger: #ff8a80;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}
a { color: inherit; }
button, input, select { font: inherit; }
.cafe-shell { display: flex; min-height: 100vh; }
.cafe-side {
  width: 240px;
  background: var(--side);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.cafe-brand {
  font-weight: 800;
  font-size: 1.15rem;
  text-decoration: none;
  padding: 8px 10px 16px;
}
.cafe-nav { display: flex; flex-direction: column; gap: 6px; }
.cafe-nav a {
  text-decoration: none;
  color: var(--side-muted);
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 700;
}
.cafe-nav a.is-active, .cafe-nav a:hover {
  background: rgba(232, 137, 58, .18);
  color: #fff;
}
.cafe-side-foot {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 10px 4px;
  color: var(--side-muted);
  font-size: .9rem;
}
.cafe-side-foot a { color: #fff; }
.cafe-main { flex: 1; min-width: 0; }
.cafe-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 0;
}
.cafe-top h1 { margin: 0; font-size: 1.6rem; }
.cafe-top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.cafe-content { padding: 16px 22px 32px; }
.theme-toggle, .btn, .pay-btn, .item-btn, .chip {
  border: 0;
  cursor: pointer;
  border-radius: 14px;
}
.theme-toggle, .btn {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  min-height: 44px;
  padding: 0 16px;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-accent {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff;
  border: 0;
}
.btn-danger { background: var(--danger); color: #fff; border: 0; }
.btn-lg { min-height: 58px; font-size: 1.15rem; width: 100%; }
.btn-outline {
  margin-top: 10px;
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}
#printSaved[hidden] { display: none !important; }
.cards, .summary, .item-grid, .report-grid {
  display: grid;
  gap: 14px;
}
.cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.summary { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.card, .stat, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.dash-card {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 110px;
  text-decoration: none;
  font-size: 1.15rem;
  font-weight: 800;
  text-align: center;
  padding: 16px;
}
.dash-card.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: 0;
  min-height: 140px;
  font-size: 1.45rem;
}
.stat { padding: 16px 18px; }
.stat span { display: block; color: var(--muted); font-size: .85rem; font-weight: 700; }
.stat strong { display: block; margin-top: 4px; font-size: 1.45rem; }
.bill-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(480px, 560px); gap: 16px; align-items: start; }
.bill-layout > .panel { min-width: 0; }
.panel { padding: 16px; }
.item-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.item-btn {
  background: var(--card);
  color: var(--text);
  border: 2px solid var(--line);
  min-height: 124px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: var(--shadow);
}
.item-btn:hover, .item-btn:focus { border-color: var(--accent); }
.item-btn .emoji { font-size: var(--item-icon-size, 2rem); line-height: 1; }
.item-btn .item-icon { width: var(--item-icon-size, 2rem); height: var(--item-icon-size, 2rem); object-fit: contain; display: block; }
.item-icon-preview .item-icon { width: 32px; height: 32px; object-fit: contain; display: inline-block; vertical-align: middle; }
.item-btn .name { font-weight: 800; font-size: 1.05rem; }
.item-btn .price { color: var(--accent); font-weight: 800; }
.bill-title { margin: 0 0 2px; line-height: 1.1; font-size: 1.25rem; }
.bill-table { width: 100%; border-collapse: collapse; }
.bill-table th, .bill-table td { text-align: left; padding: 4px; border-bottom: 1px solid var(--line); vertical-align: middle; line-height: 1.2; }
.bill-table .line-math { margin-top: 1px; font-size: .82rem; font-weight: 800; color: var(--accent); white-space: nowrap; }
.bill-table .btn { min-height: 28px; padding: 0 8px; font-size: .85rem; }
.qty { display: inline-flex; align-items: center; gap: 4px; }
.qty button {
  width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 1rem; font-weight: 800; cursor: pointer;
}
.total-bar {
  margin: 14px 0;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--bg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.45rem;
  font-weight: 900;
}
.contact-bar {
  width: 100%;
  min-height: 40px;
  margin: 0 0 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 0 14px;
}
.contact-bar[hidden] { display: none; }
.pay-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  margin-bottom: 10px;
}
.name-slot { min-width: 0; }
.name-slot .contact-bar { width: 100%; min-width: 0; }
.pending-amount {
  margin: -2px 0 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--bg);
  font-weight: 800;
}
.credit-box[hidden] { display: none; }
.credit-add {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}
.credit-add input {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 0 12px;
}
.credit-add input[name="pending_name"] { min-width: 180px; }
.credit-add input[name="credit_limit"] { width: 150px; }
.credit-picker { max-width: 520px; margin-bottom: 14px; }
.credit-picker select { width: 100%; }
.credit-card { margin-bottom: 14px; }
.credit-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  font-weight: 800;
}
.credit-pay {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-top: 14px;
}
.credit-pay input, .credit-pay select {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 0 12px;
}
.credit-pay input { width: 140px; }
.pay-btn {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  min-height: 34px;
  font-size: .72rem;
  font-weight: 800;
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--line);
  padding: 0 4px;
  white-space: nowrap;
}
select.contact-bar {
  width: 100%;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text) 50%), linear-gradient(135deg, var(--text) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}
.name-hint {
  margin: -4px 0 10px;
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted);
}
.bill-layout .btn-lg { min-height: 42px; font-size: 1rem; }
.pay-btn.is-on { background: var(--accent); color: #fff; border-color: var(--accent); }
.actions { display: flex; gap: 8px; margin-top: 10px; }
.actions .btn { flex: 1; }
.alert {
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 12px;
  font-weight: 700;
  background: #e8f7ee;
  color: #0f6b38;
}
[data-theme="dark"] .alert { background: #143224; color: #b6f5cf; }
.alert.error { background: #fde8e6; color: #8f1d16; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.chip {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  min-height: 42px;
  padding: 0 14px;
  text-decoration: none;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
}
.chip.is-on { background: var(--accent); color: #fff; border-color: var(--accent); }
.table-wrap { overflow-x: auto; max-width: 100%; }
.sales-fit { overflow: hidden; max-width: 100%; }
.sales-fit table.data { table-layout: auto; width: 100%; }
.row-actions { display: flex; flex-wrap: nowrap; align-items: center; gap: 6px; white-space: nowrap; }
.row-actions form { margin: 0; display: flex; }
.row-actions .btn { min-height: 36px; padding: 0 12px; flex: 0 0 auto; font-size: .9rem; }
table.data { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 16px; overflow: hidden; }
table.data th, table.data td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.sales-fit table.data th, .sales-fit table.data td { white-space: nowrap; }
.sales-fit table.data th:nth-child(3),
.sales-fit table.data td:nth-child(3) { width: 100%; max-width: 0; overflow: hidden; text-overflow: ellipsis; }
table.data th { color: var(--muted); font-size: .85rem; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field input, .field select {
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 0 12px;
}
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(232,137,58,.25), transparent 40%),
    var(--bg);
}
.login-card { width: min(420px, 100%); padding: 28px; }
.login-card h1 { margin: 0 0 6px; }
.muted { color: var(--muted); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.report-grid { grid-template-columns: 1fr 1fr; }
.empty { color: var(--muted); padding: 12px 0; }
.receipt {
  width: min(360px, 100%);
  margin: 24px auto;
  background: #fff;
  color: #111;
  padding: 18px;
  border-radius: 12px;
}
.receipt h2, .receipt p { margin: 0 0 6px; text-align: center; }
.receipt table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.receipt td { padding: 4px 0; }
@media (max-width: 1100px) {
  .sales-fit table.data { font-size: .92rem; }
  .row-actions .btn { font-size: .8rem; padding: 0 6px; min-height: 34px; }
}
@media (max-width: 900px) {
  .cafe-shell { flex-direction: column; }
  .cafe-side { width: 100%; height: auto; position: static; }
  .cafe-nav { flex-direction: row; overflow-x: auto; }
  .cafe-nav a { white-space: nowrap; }
  .bill-layout, .report-grid, .row-2 { grid-template-columns: 1fr; }
  .cafe-content, .cafe-top { padding-left: 14px; padding-right: 14px; }
}
@media print {
  .cafe-side, .cafe-top, .no-print { display: none !important; }
  body, .receipt { background: #fff; color: #000; }
}
