:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e5e8;
  --text: #1c1e21;
  --text-2: #6b7078;
  --text-muted: #9a9ea5;
  --primary: #2f6f4f;
  --primary-dark: #235a3f;
  --primary-light: #e8f3ee;
  --danger: #c0392b;
  --danger-light: #fbeae8;
  --warning: #b8790a;
  --warning-light: #fdf2e1;
  --success: #2f6f4f;
  --success-light: #e8f3ee;
  --info: #2166b0;
  --info-light: #e7f0fb;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(20,20,20,0.06), 0 1px 8px rgba(20,20,20,0.04);
  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 600; margin: 0 0 0.5rem; }
p { margin: 0 0 0.75rem; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }

/* ---------- Auth pages ---------- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(180deg, #f4f5f7 0%, #eef1ee 100%);
}
.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 340px;
  box-shadow: var(--shadow);
}
.auth-box h1 { color: var(--primary-dark); font-size: 22px; }
.auth-logo { display: block; max-width: 80px; max-height: 80px; margin: 0 auto 14px; object-fit: contain; }
.auth-box label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--text-2); }
.auth-box input { width: 100%; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: #1b2b22;
  color: #d9ded9;
  flex-shrink: 0;
  padding: 1.25rem 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  font-size: 19px;
  font-weight: 700;
  color: #fff;
  padding: 0 0.5rem 1.25rem;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-logo { width: 100%; height: 100%; object-fit: contain; border-radius: 4px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #c7cec8;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 13.5px;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar nav a i { font-size: 17px; width: 18px; text-align: center; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar .spacer { flex: 1; }
.topbar .user-chip { font-size: 13px; color: var(--text-2); }
.topbar .user-chip em { font-style: normal; color: var(--text-muted); }
.menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); }
.content { padding: 1.5rem; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #a33224; }
.btn-ghost { background: transparent; }
.btn-sm { height: 30px; padding: 0 12px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-disabled { opacity: 0.4; pointer-events: none; cursor: not-allowed; }

/* ---------- Forms ---------- */
input, select, textarea {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
}
textarea { height: auto; padding: 10px 12px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
label { font-size: 13px; color: var(--text-2); display: block; margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { margin-bottom: 12px; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 1rem; display: flex; align-items: center; gap: 8px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 1.25rem; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.3rem;
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 700; color: var(--text); }
.stat-card.warn .value { color: var(--warning); }
.stat-card.danger .value { color: var(--danger); }
.stat-card.good .value { color: var(--success); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

/* ---------- Badges / alerts ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 100px; font-size: 12px; font-weight: 600; }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger); color: #fff; }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-gray { background: #eef0f2; color: var(--text-2); }

.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 13.5px; margin-bottom: 1rem; }
.alert-success { background: var(--success-light); color: var(--primary-dark); }
.alert-danger { background: var(--danger-light); color: var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning); }
.alert-info { background: var(--info-light); color: var(--info); }

/* ---------- Filters / toolbar ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.toolbar .grow { flex: 1; min-width: 200px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,20,20,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-box {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 1.5rem; width: 320px; box-shadow: var(--shadow);
}

/* ---------- Misc ---------- */
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: 1rem; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state i { font-size: 40px; display: block; margin-bottom: 10px; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -240px; z-index: 50; transition: left 0.2s; box-shadow: var(--shadow); }
  .layout.sidebar-open .sidebar { left: 0; }
  .menu-toggle { display: block; }
}

/* ---------- Print (invoices) ---------- */
@media print {
  .sidebar, .topbar, .toolbar, .menu-toggle, .btn, form button, a.btn, .no-print {
    display: none !important;
  }
  body { background: #fff; }
  .layout { display: block; }
  .main { display: block; }
  .content { padding: 0; max-width: 100%; margin: 0; }
  .card { box-shadow: none; border: none; padding: 0; }

  /* Default paper size for the printed receipt - change to 58mm here
     if your thermal printer uses 58mm paper instead of 80mm. Most
     printer drivers already fix this from their own settings, so this
     is just a sensible fallback. */
  @page { size: 80mm auto; margin: 0; }
}

/* ---------- Thermal / mini-printer receipt ---------- */
.receipt {
  width: var(--receipt-width, 80mm);
  max-width: 100%;
  margin: 0 auto;
  background: #fff;
  border: 1px dashed var(--border);
  padding: 10px 12px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  color: #000;
}
.receipt-center { text-align: center; }
.receipt-logo { display: block; max-width: 55mm; max-height: 20mm; margin: 0 auto 4px; object-fit: contain; }
.receipt-shop-name { font-size: 16px; font-weight: 700; letter-spacing: 0.5px; margin-bottom: 2px; }
.receipt-line { font-size: 11.5px; }
.receipt-dashed { border-top: 1px dashed #000; margin: 8px 0; }
.receipt-row { display: flex; justify-content: space-between; gap: 8px; }
.receipt-item-name { margin-top: 4px; font-weight: 600; }
.receipt-item-detail { font-size: 11.5px; padding-left: 4px; }
.receipt-total { font-size: 15px; font-weight: 700; margin-top: 2px; }
.receipt-due { font-weight: 700; }
.receipt-footer { margin-top: 6px; font-size: 11.5px; }

@media print {
  .receipt {
    border: none;
    padding: 0 4mm;
    width: 100%;
  }
}

/* ---------- Stock alert row highlighting ---------- */
.row-out-of-stock { background: var(--danger-light) !important; }
.row-low-stock { background: var(--danger-light) !important; }
