:root {
  --sidebar-w: 240px;
  --bg: #f4f6f9;
  --sidebar-bg: #1e2733;
  --sidebar-bg-active: #2a3644;
  --sidebar-text: #b7c0cc;
  --sidebar-text-active: #ffffff;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #16a34a;
  --card-border: #e5e9f0;
  --text-muted: #6b7280;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  background-color: var(--bg);
  font-family: inherit;
  color: #1f2937;
}

a { text-decoration: none; }

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 1000;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand .logo-badge {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.sidebar-brand .brand-text {
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
}
.sidebar-brand .brand-text small { display: block; color: var(--sidebar-text); font-weight: 400; font-size: 11px; }

.sidebar-nav { padding: 12px 10px; flex: 1; }
.sidebar-nav .nav-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6b7686;
  padding: 14px 12px 6px;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 2px;
  transition: background .12s ease, color .12s ease;
}
.sidebar-nav a:hover { background: var(--sidebar-bg-active); color: #fff; }
.sidebar-nav a.active { background: var(--brand); color: #fff; font-weight: 500; }
.sidebar-nav a .icon { width: 18px; text-align: center; font-size: 15px; }

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

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--card-border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 900;
}
.topbar h1 { font-size: 20px; font-weight: 600; margin: 0; }
.topbar .user-chip {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px;
}
.topbar .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--brand);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
}

.content-area { padding: 24px; flex: 1; }

/* ---------- Cards ---------- */
.card {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(16,24,40,0.04);
}
.card-header {
  background: #fff;
  border-bottom: 1px solid var(--card-border);
  font-weight: 600;
  font-size: 14px;
  border-radius: 12px 12px 0 0 !important;
}

/* Stat tiles */
.stat-tile {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
}
.stat-tile .stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.stat-icon.bg-blue { background: #dbeafe; color: #1d4ed8; }
.stat-icon.bg-red { background: #fee2e2; color: #b91c1c; }
.stat-icon.bg-amber { background: #fef3c7; color: #b45309; }
.stat-icon.bg-green { background: #dcfce7; color: #15803d; }

.stat-tile .stat-label { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.stat-tile .stat-value { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: #fee2e2;
  color: #b91c1c;
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { margin-bottom: 0; font-size: 13.5px; }
table.data-table thead th {
  background: #f9fafb;
  color: #4b5563;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
  padding: 10px 14px;
}
table.data-table tbody td { padding: 10px 14px; vertical-align: middle; border-bottom: 1px solid #f1f3f6; }
table.data-table tbody tr:hover { background: #f9fafb; }
.low-stock-row { background-color: #fff7ed !important; }

.badge-type-in { background: #dcfce7; color: #15803d; }
.badge-type-out { background: #fee2e2; color: #b91c1c; }
.badge-type-adj { background: #e5e7eb; color: #374151; }
.badge-pill {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  display: inline-block;
}
.status-overdue { color: #b91c1c; font-weight: 600; }
.status-pending { color: #b45309; font-weight: 600; }

/* ---------- Forms ---------- */
.form-card { max-width: 720px; }
.form-label { font-weight: 500; font-size: 13.5px; color: #374151; }

.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e2733 0%, #2563eb 140%);
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}
.login-card .logo-badge {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 20px; margin: 0 auto 14px;
}
.login-card h4 { text-align: center; font-weight: 700; margin-bottom: 2px; }
.login-card .subtitle { text-align: center; color: var(--text-muted); font-size: 13.5px; margin-bottom: 24px; }
.password-field { position: relative; }
.password-field .toggle-pw {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  cursor: pointer; color: var(--text-muted); font-size: 13px; user-select: none;
}

/* mobile sidebar toggle */
.sidebar-toggle-btn { display: none; }
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .sidebar-toggle-btn { display: inline-flex; }
}
