/* ============================================================
   SupplyBranch — Stylesheet  (v2)
   CSS variables drive white-label theming.
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
  /* App UI color — buttons, focus rings, links. Never overridden by company theme. */
  --primary:        #2563EB;
  --primary-dark:   #1D4ED8;
  --primary-light:  #DBEAFE;
  --primary-subtle: #EFF6FF;

  /* Company brand color — sidebar logo badge + active item only. */
  --brand:          #4A7C3F;
  --danger:         #DC2626;
  --danger-light:   #FEE2E2;
  --warning:        #D97706;
  --warning-light:  #FEF3C7;
  --success:        #16A34A;
  --success-light:  #DCFCE7;

  --sidebar-bg:     #0F172A;
  --sidebar-text:   #94A3B8;
  --sidebar-hover:  #1E293B;
  --sidebar-active: #4A7C3F;
  --sidebar-width:  240px;

  --bg:             #F1F5F9;
  --bg-alt:         #F8FAFC;
  --surface:        #FFFFFF;
  --surface-raised: #FFFFFF;
  --border:         #E2E8F0;
  --border-strong:  #CBD5E1;
  --text:           #0F172A;
  --text-muted:     #64748B;
  --text-subtle:    #94A3B8;

  --radius:         8px;
  --radius-lg:      12px;
  --shadow-sm:      0 1px 2px rgba(0,0,0,.06);
  --shadow:         0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:      0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:      0 10px 30px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.08);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ============================================================
   AUTH PAGE
   ============================================================ */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
  padding: 24px;
}

.auth-container {
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo img {
  height: 48px;
  object-fit: contain;
}

.auth-logo .logo-text {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.auth-logo .logo-icon {
  width: 42px;
  height: 42px;
  background: var(--brand);
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}

.auth-logo .logo-icon svg { color: #fff; }

.auth-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.3px;
}

.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 24px 64px rgba(0,0,0,.40);
}

.auth-card h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.auth-card p {
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: 14px;
}

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: .1px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.form-group input::placeholder { color: var(--text-subtle); }
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background .15s, opacity .15s, box-shadow .15s, transform .1s;
  white-space: nowrap;
  letter-spacing: .1px;
}

.btn:active { transform: scale(.98); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); box-shadow: 0 2px 8px rgba(37,99,235,.4); }
.btn-primary:active { box-shadow: none; }

.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover  { background: #B91C1C; box-shadow: 0 2px 8px rgba(220,38,38,.35); }
.btn-danger:active { box-shadow: none; }

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border-strong);
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.btn-outline:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; padding: 10px; }
.btn:disabled { opacity: .38; cursor: not-allowed; transform: none !important; filter: saturate(.4); }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Error / Status ---------- */
.error-msg   { color: var(--danger);  font-size: 13px; margin-bottom: 12px; min-height: 18px; }
.success-msg { color: var(--success); font-size: 13px; margin-bottom: 12px; }

/* ============================================================
   APP SHELL
   ============================================================ */
#app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  transition: transform .25s;
  border-right: 1px solid rgba(255,255,255,.04);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar-logo img { height: 32px; object-fit: contain; }

.sidebar-logo .logo-icon {
  width: 32px; height: 32px;
  background: var(--brand);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.sidebar-logo .logo-icon svg { color: #fff; width: 18px; height: 18px; }

.sidebar-logo span {
  font-size: 14.5px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
  letter-spacing: -.2px;
}

.sidebar-section { padding: 12px 8px 4px; }

.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #334155;
  padding: 0 8px;
  margin-bottom: 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  color: #94A3B8;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, color .12s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  margin-bottom: 1px;
}

.sidebar-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .65; transition: opacity .12s; }
.sidebar-item:hover { background: #1E293B; color: #CBD5E1; }
.sidebar-item:hover svg { opacity: .9; }
.sidebar-item.active { background: rgba(37,99,235,.2); color: #60A5FA; font-weight: 600; }
.sidebar-item.active svg { opacity: 1; color: #60A5FA; }

/* Badge on sidebar items */
.sidebar-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 10px 8px 12px;
  border-top: 1px solid rgba(255,255,255,.06);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--sidebar-text);
  transition: background .12s;
}

.user-chip:hover { background: #1E293B; }

.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

.user-info { overflow: hidden; }
.user-name { font-size: 13px; font-weight: 600; color: #E2E8F0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: #475569; font-weight: 500; }

/* ---------- Main Content ---------- */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.topbar-title {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 55%;
  letter-spacing: -.2px;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }

.page-body { padding: 24px; flex: 1; }

/* ============================================================
   STATS CARDS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.stat-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .7px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 30px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  letter-spacing: -1px;
  margin-bottom: 6px;
}

.stat-sub { font-size: 12px; color: var(--text-muted); font-weight: 500; }

.stat-card.danger  { border-left: 4px solid var(--danger); }
.stat-card.warning { border-left: 4px solid var(--warning); }
.stat-card.success { border-left: 4px solid var(--success); }

.stat-card.danger  .stat-value { color: var(--danger); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.success .stat-value { color: var(--success); }

/* ============================================================
   CARDS / PANELS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.card-title { font-size: 13.5px; font-weight: 700; color: var(--text); letter-spacing: -.1px; }
.card-body  { padding: 20px; }

/* ============================================================
   TABLE
   ============================================================ */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  background: #F8FAFC;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  padding: 11px 16px;
  border-bottom: 1.5px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid #F1F5F9;
  transition: background .1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #F8FAFC; }

tbody td {
  padding: 12px 16px;
  vertical-align: middle;
  color: var(--text);
}

/* Product name in table — stronger */
tbody td:first-child { font-weight: 600; }

/* ============================================================
   BADGES / PILLS
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .2px;
}

.badge-danger  { background: #FEE2E2; color: #B91C1C; }
.badge-warning { background: #FEF3C7; color: #B45309; }
.badge-success { background: #DCFCE7; color: #15803D; }
.badge-neutral { background: #F1F5F9; color: #475569; }
.badge-primary { background: #DBEAFE; color: #1D4ED8; }

/* ============================================================
   SEARCH / FILTER BAR
   ============================================================ */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-input-wrap svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input-wrap input {
  width: 100%;
  padding: 8px 10px 8px 34px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}

.search-input-wrap input::placeholder { color: var(--text-subtle); }

.search-input-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.10);
}

.filter-select {
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}

.filter-select:focus { border-color: var(--primary); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  backdrop-filter: blur(2px);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  transform: translateY(16px) scale(.98);
  transition: transform .2s;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-overlay.open .modal { transform: translateY(0) scale(1); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 15px; font-weight: 700; color: var(--text); }

.modal-close {
  width: 30px; height: 30px;
  border: none;
  background: var(--bg);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .12s, color .12s;
  font-size: 18px;
  line-height: 1;
}

.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body   { padding: 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg);
}

/* Ensure enabled primary buttons in modal footers are always clearly blue */
.modal-footer .btn-primary:not(:disabled) {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 4px rgba(37,99,235,.3);
}

/* ============================================================
   BRANCH CARDS (Super Admin)
   ============================================================ */
.branch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 4px;
}

.branch-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow .2s, border-color .2s, transform .15s;
}

.branch-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.branch-card-name { font-size: 15px; font-weight: 700; margin-bottom: 3px; color: var(--text); }
.branch-card-loc  { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; font-weight: 500; }

.branch-card-stats { display: flex; gap: 20px; padding-top: 14px; border-top: 1px solid var(--border); }
.branch-stat { text-align: center; }
.branch-stat-val  { font-size: 22px; font-weight: 800; color: var(--text); letter-spacing: -1px; }
.branch-stat-lbl  { font-size: 10.5px; color: var(--text-muted); margin-top: 1px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }

/* ============================================================
   EMPTY STATES
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  opacity: .25;
  display: block;
}

.empty-state h3 { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.empty-state p  { font-size: 13px; color: var(--text-muted); }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.toast {
  background: #1E293B;
  color: #E2E8F0;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 320px;
  animation: slideIn .2s ease;
  border-left: 3px solid transparent;
}

.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger);  }
.toast.warning { border-left-color: var(--warning); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0);    }
}

/* ============================================================
   LOADING SPINNER
   ============================================================ */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

.spinner-dark {
  border: 2.5px solid rgba(37,99,235,.15);
  border-top-color: var(--primary);
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px;
  color: var(--text-muted);
  gap: 14px;
  font-size: 13px;
  font-weight: 500;
}

/* ============================================================
   ROLE BADGES
   ============================================================ */
.role-platform { background: #FEF3C7; color: #92400E; }
.role-super    { background: #EDE9FE; color: #6D28D9; }
.role-admin    { background: #DBEAFE; color: #1D4ED8; }
.role-tech     { background: #D1FAE5; color: #065F46; }
.role-staff    { background: #F1F5F9; color: #475569; }

/* ============================================================
   PRODUCT QUANTITY DISPLAY
   ============================================================ */
.qty-display {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13.5px;
  font-weight: 700;
}

.qty-ok       { color: #15803D; }
.qty-low      { color: #B45309; }
.qty-critical { color: #B91C1C; }

/* ============================================================
   TOGGLE / HAMBURGER (mobile)
   ============================================================ */
.hamburger {
  display: none;
  width: 36px; height: 36px;
  align-items: center; justify-content: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: none;
  cursor: pointer;
  color: var(--text);
}

/* ============================================================
   SECTION HEADERS (inline page headers above tables)
   ============================================================ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

/* ============================================================
   PLATFORM ADMIN — Company cards
   ============================================================ */
.company-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: box-shadow .2s, border-color .2s;
}

.company-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }

  .sidebar {
    transform: translateX(-240px);
    width: 240px;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.35);
  }

  .main-content { margin-left: 0; }
  .hamburger { display: flex; }
  .topbar { padding: 0 16px; }
  .page-body { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .search-input-wrap { min-width: 100%; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .modal { max-width: 100%; max-height: 85vh; margin: 0; border-radius: 14px 14px 0 0; align-self: flex-end; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .topbar-title { max-width: 45%; }
}

/* ============================================================
   UTILITY
   ============================================================ */
.hidden  { display: none !important; }
.text-muted   { color: var(--text-muted); font-size: 12px; }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.ml-auto { margin-left: auto; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.w-full { width: 100%; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
