:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #1b2430;
  --muted: #5f6b7a;
  --line: #dde2e8;
  --brand: #0f766e;
  --brand-soft: #e3f3f1;
  --danger: #c0392b;
  --warn: #b7791f;
  --ok: #1e8449;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.45; display: flex; flex-direction: column; }
a { color: var(--brand); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 58px; padding: 0 20px; }
.logo { font-weight: 800; font-size: 20px; text-decoration: none; color: var(--text); white-space: nowrap; }
.logo span { color: var(--brand); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 6px; font-size: 15px; }
.nav a.active, .nav a:hover { background: var(--brand-soft); color: var(--brand); }
.account { display: flex; align-items: center; gap: 10px; font-size: 14px; white-space: nowrap; }
.role { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #eef1f5; color: var(--muted); text-transform: capitalize; }

/* controls */
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
textarea { width: 100%; resize: vertical; min-height: 80px; }
button, .btn { font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.danger { color: var(--danger); border-color: #f0c6c1; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* sale screen */
main { flex: 1; min-height: 0; }
.sale { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; padding: 16px 20px; height: 100%; min-height: 0; }
.catalog { display: flex; flex-direction: column; min-height: 0; }
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.toolbar input { flex: 1; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { padding: 6px 12px; font-size: 13px; }
.tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.products { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; overflow-y: auto; padding-bottom: 8px; align-content: start; }
.product { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: left; display: flex; flex-direction: column; align-items: stretch; gap: 4px; min-height: 118px; }
.product:hover:not(:disabled) { border-color: var(--brand); }
.product .sku { font-size: 12px; color: var(--muted); }
.product .name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.product .price { margin-top: auto; font-weight: 700; color: var(--brand); }
.stock { font-size: 12px; color: var(--muted); }
.stock.low { color: var(--warn); font-weight: 600; }
.stock.out { color: var(--danger); font-weight: 600; }

.cart { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.cart-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.cart-head h2 { margin: 0; font-size: 18px; }
.cart-lines { flex: 1; overflow-y: auto; padding: 0 16px; min-height: 80px; }
.line { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.line .lname { font-size: 14px; font-weight: 600; }
.line .lprice { font-size: 12px; color: var(--muted); }
.line .ltotal { text-align: right; font-weight: 600; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { padding: 2px 10px; }
.qty input { width: 52px; text-align: center; padding: 4px; }
.line .remove { padding: 2px 8px; font-size: 12px; justify-self: end; }
.cart-empty { color: var(--muted); text-align: center; padding: 30px 0; font-size: 14px; }
.cart-foot { grid-template-columns: minmax(0, 1fr); border-top: 1px solid var(--line); padding: 12px 16px 16px; display: grid; gap: 10px; }
.promo { display: flex; gap: 6px; }
.promo input { flex: 1; min-width: 0; text-transform: uppercase; }
.field-msg { font-size: 13px; }
.field-msg.err { color: var(--danger); }
.field-msg.ok { color: var(--ok); }
.summary { display: grid; gap: 3px; font-size: 14px; }
.summary div { display: flex; justify-content: space-between; }
.summary .total { font-size: 20px; font-weight: 800; border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 4px; }
.pay-methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pay-methods label { border: 1px solid var(--line); border-radius: 8px; padding: 7px; text-align: center; cursor: pointer; font-size: 14px; }
.pay-methods input { position: absolute; opacity: 0; pointer-events: none; }
.pay-methods label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.paid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 10px; align-items: center; font-size: 14px; }
.cart-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
.cart-actions .primary { padding: 12px; font-size: 16px; font-weight: 700; }

/* transactions */
.page { padding: 20px; max-width: 1200px; margin: 0 auto; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.page-head h1 { margin: 0; font-size: 24px; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #f6f8fa; font-size: 13px; color: var(--muted); }
td.r, th.r { text-align: right; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7fbfa; }
.status { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.status.completed { background: #e3f3e8; color: var(--ok); }
.status.voided { background: #fdecea; color: var(--danger); }

/* receipt */
.receipt { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; background: #fbfbf8; border: 1px dashed var(--line); padding: 14px; border-radius: 8px; }
.receipt .rrow { display: flex; justify-content: space-between; gap: 10px; }
.receipt hr { border: 0; border-top: 1px dashed #bbb; margin: 8px 0; }
.receipt .center { text-align: center; }
.receipt .big { font-weight: 700; font-size: 15px; }

/* login */
.login { max-width: 380px; margin: 60px auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.login h1 { margin: 0 0 4px; font-size: 24px; }
.field { display: grid; gap: 4px; margin-top: 14px; }
.field label { font-size: 14px; font-weight: 600; }
.field .err { color: var(--danger); font-size: 13px; }
.alert { margin-top: 14px; padding: 10px 12px; border-radius: 8px; font-size: 14px; background: #fdecea; color: var(--danger); border: 1px solid #f5c6c0; }
.login button[type=submit] { width: 100%; margin-top: 18px; padding: 10px; }

/* modal + toast */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal-backdrop[hidden] { display: none; }
.modal { background: #fff; border-radius: 12px; width: min(440px, calc(100% - 32px)); max-height: calc(100vh - 40px); overflow-y: auto; padding: 22px; position: relative; }
.modal h2 { margin: 0 0 14px; font-size: 19px; }
.modal-close { position: absolute; right: 10px; top: 8px; border: 0; font-size: 22px; padding: 2px 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.toasts { position: fixed; left: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 30; }
.toast { background: #1b2430; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }

@media (max-width: 960px) {
  .sale { grid-template-columns: 1fr; height: auto; }
  .products { overflow: visible; }
  .topbar-inner { gap: 12px; }
}
