:root {
  --primary: #6f4e37;
  --accent: #d4a373;
  --background: #f7f3ee;
  --surface: #ffffff;
  --text: #1d1b19;
  --muted: #6d6761;
  --border: #ded7d0;
  --danger: #b42318;
  --success: #067647;
  --warning: #b54708;
  --shadow: 0 10px 30px rgba(50, 35, 25, .08);
  --radius: 14px;
  --font: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; font-family: var(--font); background: var(--background); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.danger-text { color: var(--danger); }
.success-text { color: var(--success); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow: auto; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 8px 20px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: var(--primary); color: white; font-weight: 800; }
.brand strong { display: block; }
.brand span { color: var(--muted); font-size: .78rem; }
.nav { display: grid; gap: 5px; }
.nav-button { width: 100%; border: 0; background: transparent; color: var(--text); text-align: left; padding: 11px 12px; border-radius: 10px; display: flex; gap: 10px; align-items: center; }
.nav-button:hover, .nav-button.active { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 700; }
.sidebar-bottom { margin-top: 24px; padding: 12px 8px; border-top: 1px solid var(--border); }

.main { min-width: 0; }
.topbar { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 22px; background: color-mix(in srgb, var(--surface) 92%, transparent); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 15; backdrop-filter: blur(12px); }
.topbar h1 { margin: 0; font-size: 1.25rem; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.mobile-menu { display: none; }
.content { padding: 22px; max-width: 1600px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-heading h2 { margin: 0 0 5px; }
.page-heading p { margin: 0; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h3 { margin-top: 0; }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.metric { min-height: 115px; }
.metric .label { color: var(--muted); font-size: .9rem; }
.metric .value { font-weight: 800; font-size: clamp(1.35rem, 2.2vw, 2rem); margin-top: 10px; }
.metric .hint { color: var(--muted); font-size: .78rem; margin-top: 7px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stack { display: grid; gap: 14px; }

.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 9px; padding: 9px 13px; font-weight: 650; min-height: 40px; }
.btn:hover { filter: brightness(.98); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-accent { background: var(--accent); color: #22170f; border-color: var(--accent); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 32px; padding: 6px 9px; font-size: .84rem; }
.btn-icon { width: 40px; padding: 0; display: grid; place-items: center; }

.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 5px 9px; font-size: .78rem; background: #eee8e2; color: var(--text); }
.badge.success { background: #dcfae6; color: #05603a; }
.badge.warning { background: #fff0c2; color: #78480a; }
.badge.danger { background: #fee4e2; color: #912018; }
.badge.info { background: #e0f2fe; color: #075985; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: .82rem; font-weight: 700; color: var(--muted); }
.field input, .field select, .field textarea, .toolbar input, .toolbar select, .input { width: 100%; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 9px; padding: 10px 11px; min-height: 40px; }
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .toolbar input:focus, .toolbar select:focus { outline: 3px solid color-mix(in srgb, var(--primary) 18%, transparent); border-color: var(--primary); }
.help-text { font-size: .77rem; color: var(--muted); }
.check-row { display: flex; gap: 8px; align-items: center; }
.check-row input { width: auto; min-height: auto; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { flex: 1 1 220px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .77rem; text-transform: uppercase; letter-spacing: .04em; background: color-mix(in srgb, var(--surface) 88%, var(--background)); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }

.pos-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(330px, .75fr); gap: 16px; align-items: start; }
.pos-catalog { min-width: 0; }
.category-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 10px; }
.category-chip { white-space: nowrap; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 8px 12px; }
.category-chip.active { background: var(--primary); color: white; border-color: var(--primary); }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 11px; }
.product-tile { border: 1px solid var(--border); background: var(--surface); border-radius: 13px; padding: 14px; min-height: 118px; text-align: left; display: flex; flex-direction: column; justify-content: space-between; box-shadow: 0 4px 14px rgba(50,35,25,.04); }
.product-tile:hover { border-color: var(--primary); transform: translateY(-1px); }
.product-tile:disabled { opacity: .5; cursor: not-allowed; }
.product-name { font-weight: 750; }
.product-meta { color: var(--muted); font-size: .77rem; }
.product-price { font-weight: 800; color: var(--primary); font-size: 1.05rem; }
.cart-card { position: sticky; top: 82px; max-height: calc(100vh - 104px); display: flex; flex-direction: column; }
.cart-lines { overflow: auto; min-height: 130px; max-height: 42vh; margin: 0 -4px; padding: 0 4px; }
.cart-line { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.qty-controls { display: flex; gap: 4px; align-items: center; }
.qty-controls button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.cart-summary { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 10px; display: grid; gap: 6px; }
.summary-row { display: flex; justify-content: space-between; gap: 10px; }
.summary-row.total { font-size: 1.2rem; font-weight: 850; padding-top: 7px; border-top: 1px solid var(--border); }
.checkout-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 12px; }

.list { display: grid; gap: 9px; }
.list-item { display: flex; justify-content: space-between; gap: 12px; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 9px; }
.list-item:last-child { border-bottom: 0; padding-bottom: 0; }
.progress { height: 9px; background: #eee8e2; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; width: min(360px, calc(100vw - 36px)); }
.toast { background: #1f1f1f; color: white; padding: 12px 14px; border-radius: 10px; box-shadow: 0 12px 34px rgba(0,0,0,.2); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

dialog { border: 0; padding: 0; border-radius: 16px; width: min(680px, calc(100vw - 24px)); max-height: 92vh; background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,15,10,.55); backdrop-filter: blur(3px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.dialog-head h3 { margin: 0; }
.dialog-body { padding: 18px; overflow: auto; max-height: calc(92vh - 132px); }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }
.recipe-row { display: grid; grid-template-columns: minmax(0,1fr) 120px auto; gap: 8px; margin-bottom: 8px; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 18px; background: radial-gradient(circle at top left, color-mix(in srgb, var(--accent) 45%, transparent), transparent 45%), var(--background); }
.login-card { width: min(440px, 100%); }
.viewer-shell { min-height: 100vh; }
.viewer-header { padding: 16px 22px; display: flex; justify-content: space-between; gap: 14px; align-items: center; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.viewer-header h1 { margin: 0; font-size: 1.2rem; }
.viewer-content { max-width: 1400px; margin: auto; padding: 22px; }

.notice { border-left: 4px solid var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); padding: 13px 14px; border-radius: 8px; }
.notice.warning { border-color: var(--warning); background: #fff8e8; }
.notice.danger { border-color: var(--danger); background: #fff1f0; }
.code { background: #181818; color: #f5f5f5; padding: 13px; border-radius: 10px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .84rem; }

@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .pos-layout { grid-template-columns: minmax(0,1fr); }
  .cart-card { position: static; max-height: none; }
  .cart-lines { max-height: none; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-102%); transition: transform .2s ease; box-shadow: 20px 0 50px rgba(0,0,0,.18); width: min(280px, 86vw); }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: grid; }
  .topbar { padding: 10px 14px; }
  .content { padding: 14px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .viewer-header { align-items: flex-start; flex-direction: column; }
  .viewer-content { padding: 14px; }
}
@media (max-width: 520px) {
  .cards { grid-template-columns: 1fr; }
  .page-heading { flex-direction: column; }
  .product-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .product-tile { min-height: 108px; padding: 11px; }
  .topbar h1 { font-size: 1.05rem; }
  .topbar-actions .hide-mobile { display: none; }
  .checkout-actions { grid-template-columns: 1fr; }
  .recipe-row { grid-template-columns: 1fr 90px auto; }
}
@media print {
  .no-print, .sidebar, .topbar { display: none !important; }
  body { background: white; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 0; }
}
