:root {
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --amber: #f59e0b;
  --purple: #8b5cf6;
  --orange: #fb923c;
  --ink: #0f172a;
  --ink-soft: #475569;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --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(--ink);
}

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

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: #111827;
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 24px;
}

.brand-mark {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--green), var(--blue));
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white;
}

.brand-name { font-weight: 700; font-size: 17px; color: white; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; padding: 0 12px; }

.sidebar-nav a {
  padding: 10px 12px;
  border-radius: 8px;
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 500;
}

.sidebar-nav a:hover { background: #1f2937; color: white; }
.sidebar-nav a.active { background: var(--green); color: #052e16; }

.sidebar-footer { padding: 16px 20px 0; border-top: 1px solid #1f2937; margin-top: 12px; }

.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }

.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--purple); color: white;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}

.user-name { font-size: 13px; font-weight: 600; color: white; }
.user-role { font-size: 11px; color: #94a3b8; }
.logout-link { font-size: 13px; color: #f87171; }

.main-content { flex: 1; padding: 28px 36px; max-width: 1400px; }

.page-header { margin-bottom: 24px; }
.page-header-row { display: flex; justify-content: space-between; align-items: flex-start; }
.page-header h1 { margin: 0 0 4px; font-size: 24px; }
.page-subtitle { color: var(--ink-soft); margin: 0; font-size: 14px; }
.section-title { margin: 28px 0 12px; font-size: 17px; }

.flash-stack { margin-bottom: 18px; display: flex; flex-direction: column; gap: 8px; }
.flash-stack-auth { max-width: 420px; margin: 20px auto 0; }
.flash { padding: 12px 16px; border-radius: 8px; font-size: 14px; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

.btn {
  border: none; border-radius: 8px; padding: 10px 18px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--green); color: #052e16; }
.btn-primary:hover { background: #16a34a; }
.btn-primary:disabled { background: #cbd5e1; color: #64748b; cursor: not-allowed; }
.btn-secondary { background: #e2e8f0; color: var(--ink); }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: var(--blue); font-size: 13px; cursor: pointer; padding: 0; }
.btn-link-danger { color: var(--red); }
.inline-form { display: inline; }

.kpi-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 28px; }
.kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }
.kpi-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 16px;
  border-left: 4px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.kpi-green { border-left-color: var(--green); }
.kpi-red { border-left-color: var(--red); }
.kpi-blue { border-left-color: var(--blue); }
.kpi-amber { border-left-color: var(--amber); }
.kpi-purple { border-left-color: var(--purple); }
.kpi-orange { border-left-color: var(--orange); }
.kpi-label { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 6px; }
.kpi-value { display: block; font-size: 19px; font-weight: 700; }

.chart-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.chart-card { background: var(--card-bg); border-radius: var(--radius); padding: 18px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.chart-card h3 { margin: 0 0 14px; font-size: 14px; color: var(--ink-soft); }
.chart-card-wide { grid-column: span 3; }

.report-actions { display: flex; gap: 10px; margin-top: 10px; }
.permission-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.permission-list .checkbox-label { flex-direction: row !important; font-weight: 400; color: var(--ink); }

.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini-table th, .mini-table td { padding: 6px 4px; text-align: left; border-bottom: 1px solid var(--border); }

.filter-bar { margin-bottom: 16px; }
.filter-form { display: flex; gap: 10px; }
.filter-form input, .filter-form select { padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }

.table-wrap { background: var(--card-bg); border-radius: var(--radius); overflow: auto; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; padding: 12px 16px; background: #f1f5f9; color: var(--ink-soft); font-size: 12px; text-transform: uppercase; }
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.row-low-stock { background: #fffbeb; }
.empty-row { text-align: center; color: var(--ink-soft); padding: 30px !important; }
.empty-note { color: var(--ink-soft); font-size: 13px; }
.actions-cell { display: flex; gap: 12px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; margin-left: 6px; }
.badge-muted { background: #f1f5f9; color: var(--ink-soft); }

.modal { display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.5); align-items: center; justify-content: center; z-index: 100; }
.modal.open { display: flex; }
.modal-box { background: white; border-radius: var(--radius); width: 520px; max-width: 92vw; max-height: 88vh; overflow: auto; }
.modal-box-narrow { width: 380px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--ink-soft); }
.modal-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 20px 22px; }
.modal-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.modal-form input, .modal-form select, .modal-form textarea { padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-weight: 400; color: var(--ink); }
.full-width { grid-column: 1 / -1; }

.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #f0fdf4, #eff6ff); padding: 20px; }
.auth-card { background: white; border-radius: 16px; padding: 36px; width: 420px; max-width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,0.08); }
.auth-card-wide { width: 560px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.auth-page h1 { margin: 0 0 6px; font-size: 22px; }
.auth-subtitle { color: var(--ink-soft); margin: 0 0 22px; font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.auth-form input, .auth-form select { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-weight: 400; color: var(--ink); }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 13px; color: var(--ink-soft); }

.pos-layout { display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: start; }
.pos-search { width: 100%; padding: 11px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; margin-bottom: 16px; }
.product-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.product-tile { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.product-tile:hover { border-color: var(--green); }
.product-tile-name { font-weight: 600; font-size: 14px; }
.product-tile-price { color: var(--green); font-weight: 700; font-size: 14px; }
.product-tile-stock { font-size: 12px; color: var(--ink-soft); }

.pos-cart { background: var(--card-bg); border-radius: var(--radius); padding: 18px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); position: sticky; top: 20px; }
.pos-cart h3 { margin: 0 0 12px; }
.cart-items { max-height: 260px; overflow-y: auto; margin-bottom: 14px; }
.cart-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.cart-item-qty { display: flex; align-items: center; gap: 8px; }
.cart-item-qty button { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border); background: white; cursor: pointer; }
.cart-summary { border-top: 1px solid var(--border); padding-top: 12px; margin-bottom: 14px; }
.cart-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; margin-bottom: 8px; color: var(--ink-soft); }
.cart-row input { width: 90px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; }
.cart-total { font-weight: 700; color: var(--ink); font-size: 15px; }
.pos-cart form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 12px; }
.pos-cart form select, .pos-cart form input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-weight: 400; color: var(--ink); }

.receipt-actions { display: flex; gap: 10px; margin-bottom: 20px; }
.receipt-paper { background: white; max-width: 380px; margin: 0 auto; padding: 24px; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); font-size: 13px; }
.receipt-header { text-align: center; margin-bottom: 14px; }
.receipt-header h2 { margin: 0 0 4px; font-size: 17px; }
.receipt-header p { margin: 0; color: var(--ink-soft); }
.receipt-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; }
.receipt-table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.receipt-table th, .receipt-table td { text-align: left; padding: 4px 2px; font-size: 12px; border-bottom: 1px dashed var(--border); }
.receipt-totals { border-top: 1px dashed var(--border); padding-top: 10px; }
.receipt-totals div { display: flex; justify-content: space-between; margin-bottom: 4px; }
.receipt-total-line { font-weight: 700; font-size: 14px; }
.receipt-balance { color: var(--red); font-weight: 700; }
.receipt-footer { text-align: center; margin-top: 16px; color: var(--ink-soft); font-size: 12px; }

@media print {
  .sidebar, .no-print, .flash-stack, .sidebar-toggle, .sidebar-overlay { display: none !important; }
  .main-content { padding: 0; }
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 210;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: #111827;
  color: white;
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 190;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.sidebar-overlay.visible { opacity: 1; pointer-events: auto; }