:root {
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --text: #1A1A1A;
  --muted: #6B7280;
  --primary: #1E5B4F;
  --primary-dark: #163F37;
  --accent: #E8A33D;
  --danger: #C0392B;
  --success: #2E7D32;
  --border: #E5E7EB;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }

/* ---------- Auth ---------- */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-dark);
}
.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.auth-logo { font-size: 40px; margin-bottom: 8px; }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-sub { color: var(--muted); margin: 0 0 20px; }
.auth-error { color: var(--danger); font-size: 14px; margin-bottom: 12px; }
.auth-pin-input {
  letter-spacing: 12px;
  text-align: center;
  font-size: 24px;
}

.field { display: block; text-align: left; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
}

/* ---------- Layout ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "topbar topbar" "sidenav content";
  min-height: 100vh;
}
.topbar {
  grid-area: topbar;
  background: var(--primary-dark);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  font-size: 14px;
}
.topbar-brand { font-weight: 700; }
.topbar-user a { color: #fff; text-decoration: underline; }
.sidenav {
  grid-area: sidenav;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.sidenav a {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
.sidenav a:hover { background: var(--bg); }
.content { grid-area: content; padding: 20px; overflow-x: auto; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; grid-template-areas: "topbar" "content"; }
  .sidenav {
    grid-area: unset;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--surface);
  }
  .sidenav a { white-space: nowrap; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-accent { background: var(--accent); color: #1A1A1A; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; }

/* ---------- Cards / tables ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 18px; border: 1px solid var(--border); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 16px; border: 1px solid var(--border); }
.stat-card .label { font-size: 12px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.stat-card .value { font-size: 24px; font-weight: 800; }
.stat-card .value.accent { color: var(--primary); }

table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
table th, table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
table th { background: var(--bg); font-size: 12px; text-transform: uppercase; color: var(--muted); }
.mono { font-family: "SF Mono", Consolas, monospace; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash-success { background: #E4F5E9; color: var(--success); }
.flash-error { background: #FCE8E6; color: var(--danger); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-low { background: #FCE8E6; color: var(--danger); }
.badge-ok { background: #E4F5E9; color: var(--success); }

.connectivity-banner {
  background: var(--danger);
  color: white;
  text-align: center;
  padding: 8px;
  font-size: 14px;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 50;
}
.connectivity-banner.hidden { display: none; }

/* ---------- POS screen ---------- */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  height: calc(100vh - 130px);
}
@media (max-width: 860px) {
  .pos-layout { grid-template-columns: 1fr; height: auto; }
}

.pos-categories { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 4px; }
.pos-cat-btn {
  flex: 0 0 auto;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.pos-cat-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

.pos-products {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  overflow-y: auto;
  align-content: start;
}
.pos-product-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  min-height: 84px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.pos-product-btn:active { transform: scale(0.96); background: #EAF3F1; }
.pos-product-btn .pname { font-weight: 700; font-size: 14px; }
.pos-product-btn .pprice { color: var(--primary); font-weight: 700; }
.pos-product-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.pos-cart { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.pos-cart-header { padding: 14px; font-weight: 700; border-bottom: 1px solid var(--border); }
.pos-cart-items { flex: 1; overflow-y: auto; padding: 8px; }
.pos-cart-item { display: flex; align-items: center; gap: 8px; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.pos-cart-item .name { flex: 1; font-size: 14px; font-weight: 600; }
.pos-cart-item .qty-controls { display: flex; align-items: center; gap: 6px; }
.pos-cart-item .qty-controls button {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); font-weight: 700; cursor: pointer;
}
.pos-cart-item .line-total { width: 60px; text-align: right; font-weight: 700; font-size: 14px; }
.pos-cart-footer { padding: 14px; border-top: 1px solid var(--border); }
.pos-cart-total { display: flex; justify-content: space-between; font-size: 20px; font-weight: 800; margin-bottom: 12px; }
.pos-pay-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100;
}
.modal-card { background: var(--surface); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 340px; text-align: center; }
.modal-card h3 { margin-top: 0; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 16px 0; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--primary); }
.pin-dots span.filled { background: var(--primary); }
.pin-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-keypad button { padding: 16px; font-size: 18px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; }
