/* ============================================================
   MODERN ERP ADMIN UI — Complete Stylesheet
   ============================================================ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary:       #6366f1;
  --primary-dark:  #4f46e5;
  --primary-light: #eef2ff;
  --sidebar-bg:    #0f172a;
  --sidebar-w:     260px;
  --sidebar-text:  #94a3b8;
  --sidebar-hover: rgba(99,102,241,.15);
  --sidebar-active:#6366f1;
  --topbar-h:      64px;
  --body-bg:       #f1f5f9;
  --card-bg:       #ffffff;
  --border:        #e2e8f0;
  --text:          #0f172a;
  --muted:         #64748b;
  --success:       #10b981;
  --warning:       #f59e0b;
  --danger:        #ef4444;
  --info:          #3b82f6;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg:     0 10px 40px rgba(0,0,0,.12);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--body-bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
}

/* ============================================================
   APP LAYOUT — Sidebar + Main
   ============================================================ */
.app-wrapper { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 200;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  text-decoration: none;
}
.sidebar-logo-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; flex-shrink: 0;
}
.sidebar-logo-text { color: #fff; font-weight: 700; font-size: .95rem; line-height: 1.3; }
.sidebar-logo-text small { display: block; color: var(--sidebar-text); font-size: .72rem; font-weight: 400; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }

.nav-section-label {
  padding: 14px 20px 6px;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(148,163,184,.5);
}

/* Single nav item */
.nav-item {
  display: block;
  padding: 9px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 0;
  transition: background .15s, color .15s;
  position: relative;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active {
  background: var(--sidebar-hover);
  color: #fff;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}
.nav-icon { font-size: 1.1rem; width: 22px; text-align: center; flex-shrink: 0; }

/* Nav group (accordion) */
.nav-group { position: relative; }
.nav-group-btn {
  width: 100%;
  padding: 9px 20px;
  background: none;
  border: none;
  color: var(--sidebar-text);
  font: inherit;
  font-size: .875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background .15s, color .15s;
  text-align: left;
}
.nav-group-btn:hover { background: var(--sidebar-hover); color: #fff; }
.nav-group-btn.open { color: #fff; }
.nav-group-btn .nav-arrow {
  margin-left: auto;
  font-size: .75rem;
  transition: transform .25s;
  opacity: .6;
}
.nav-group-btn.open .nav-arrow { transform: rotate(90deg); }

.nav-submenu {
  display: none;
  background: rgba(0,0,0,.15);
  padding: 4px 0;
}
.nav-submenu.open { display: block; }
.nav-submenu a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 20px 7px 52px;
  color: var(--sidebar-text);
  font-size: .82rem;
  text-decoration: none;
  transition: color .15s, background .15s;
}
.nav-submenu a:hover { color: #fff; background: rgba(255,255,255,.04); }
.nav-submenu a::before { content: '›'; color: var(--primary); font-size: 1rem; }

/* Sidebar footer */
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-avatar {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .85rem; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { color: #e2e8f0; font-size: .82rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role { color: var(--sidebar-text); font-size: .72rem; }
.sidebar-logout {
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 1.1rem;
  padding: 4px;
  border-radius: 6px;
  transition: color .15s, background .15s;
}
.sidebar-logout:hover { color: var(--danger); background: rgba(239,68,68,.1); }

/* ── Main Wrapper ── */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.topbar-toggle:hover { background: var(--primary-light); color: var(--primary); }
.topbar-breadcrumb { flex: 1; }
.topbar-breadcrumb span { color: var(--muted); font-size: .85rem; }
.topbar-breadcrumb strong { color: var(--text); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-date { color: var(--muted); font-size: .8rem; display: flex; align-items: center; gap: 6px; }
.topbar-user-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--primary-light); color: var(--primary-dark);
  padding: 6px 12px; border-radius: 999px;
  font-size: .8rem; font-weight: 600;
}
.notify-count {
  background: var(--danger); color: #fff;
  border-radius: 999px; min-width: 18px; height: 18px;
  padding: 0 5px; font-size: .68rem; line-height: 18px;
  text-align: center; font-weight: 700; display: inline-block;
}

/* ── Content ── */
.content { flex: 1; padding: clamp(14px, 2.4vw, 28px) clamp(12px, 2.4vw, 24px); width: 100%; }
.app-footer { padding: 16px 24px; border-top: 1px solid var(--border); color: var(--muted); font-size: .8rem; background: var(--card-bg); }

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 199;
  -webkit-tap-highlight-color: transparent;
}

/* ── Responsive Breakpoints ─────────────────────────────────
   ≥1200  full layout
   ≤1100  slightly narrower sidebar
   ≤900   sidebar becomes an off-canvas drawer
   ≤600   compact topbar, tighter spacing
   ≤480   single-column stats, stacked chips
   ─────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  :root { --sidebar-w: 230px; }
}
@media (max-width: 900px) {
  :root { --sidebar-w: 260px; }
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .topbar-toggle { display: flex; align-items: center; }
  .sidebar-overlay.show { display: block; }
}
@media (max-width: 600px) {
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar-date { display: none; }
  .topbar-breadcrumb span { display: none; }
  .topbar-user-chip { padding: 6px 10px; }
  .app-footer { padding: 14px 16px; text-align: center; }
}
@media (max-width: 420px) {
  .topbar-user-chip { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-bg {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 40%, #4f46e5 100%);
  padding: 20px;
}
.auth-card {
  background: #fff; padding: 40px; border-radius: 20px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo-icon {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.6rem; margin-bottom: 12px;
}
.auth-logo h2 { font-size: 1.25rem; color: var(--text); margin-bottom: 4px; }
.auth-logo p  { color: var(--muted); font-size: .85rem; }

/* ============================================================
   TYPOGRAPHY & PAGE HEADERS
   ============================================================ */
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 1.6rem; font-weight: 700; color: var(--text); }
.page-header p  { color: var(--muted); font-size: .9rem; margin-top: 4px; }

h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 6px; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 14px; color: var(--text); }
h4 { font-size: .95rem; font-weight: 600; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info    { color: var(--info); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--card-bg);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  border: 1px solid rgba(226,232,240,.6);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 12px;
}
.card-header h3 { margin-bottom: 0; }
.card-sm { padding: 16px; }
.notification-card { border-left: 4px solid var(--primary); }

/* Stat Cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}
.stat-card {
  padding: 20px;
  border-radius: var(--radius);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.stat-card::after {
  content: '';
  position: absolute;
  right: -12px; bottom: -12px;
  width: 80px; height: 80px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
}
.stat-card-icon {
  font-size: 1.6rem;
  opacity: .9;
  margin-bottom: 2px;
}
.stat-num { font-size: 2rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: .8rem; opacity: .85; font-weight: 500; }
.stat-trend { font-size: .75rem; opacity: .8; }

/* Gradient backgrounds */
.sc-blue    { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.sc-green   { background: linear-gradient(135deg, #10b981, #059669); }
.sc-orange  { background: linear-gradient(135deg, #f59e0b, #d97706); }
.sc-gray    { background: linear-gradient(135deg, #64748b, #475569); }
.sc-red     { background: linear-gradient(135deg, #ef4444, #dc2626); }
.sc-purple  { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.sc-teal    { background: linear-gradient(135deg, #14b8a6, #0d9488); }
.sc-pink    { background: linear-gradient(135deg, #ec4899, #db2777); }
.sc-indigo  { background: linear-gradient(135deg, #6366f1, #4f46e5); }
.sc-cyan    { background: linear-gradient(135deg, #06b6d4, #0891b2); }

/* ============================================================
   MODERN KPI CARDS (borderless, icon-left style)
   ============================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: box-shadow .2s;
}
.kpi-card:hover { box-shadow: var(--shadow-lg); }
.kpi-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; flex-shrink: 0;
}
.kpi-icon-blue   { background: #dbeafe; color: #2563eb; }
.kpi-icon-green  { background: #d1fae5; color: #059669; }
.kpi-icon-orange { background: #fef3c7; color: #d97706; }
.kpi-icon-red    { background: #fee2e2; color: #dc2626; }
.kpi-icon-purple { background: #ede9fe; color: #7c3aed; }
.kpi-icon-teal   { background: #ccfbf1; color: #0d9488; }
.kpi-icon-pink   { background: #fce7f3; color: #db2777; }
.kpi-icon-gray   { background: #f1f5f9; color: #475569; }
.kpi-body { flex: 1; min-width: 0; }
.kpi-body .kpi-value { font-size: 1.6rem; font-weight: 800; line-height: 1.1; color: var(--text); }
.kpi-body .kpi-label { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.kpi-body .kpi-sub   { font-size: .75rem; margin-top: 4px; font-weight: 500; }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 480px;
  font-size: .875rem;
}
.table thead { background: #f8fafc; }
.table th {
  padding: 11px 14px;
  text-align: left;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #fafbff; }
.table tfoot td, .table tfoot th {
  padding: 11px 14px;
  background: #f8fafc;
  font-weight: 700;
  border-top: 2px solid var(--border);
  font-size: .85rem;
}
.table a { color: var(--primary); text-decoration: none; font-weight: 600; }
.table a:hover { text-decoration: underline; }

/* Transaction table */
.transaction-entry { margin: 18px 0 4px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.transaction-table { min-width: 760px; }
.transaction-table th, .transaction-table td { padding: 9px 10px; vertical-align: middle; }
.transaction-table input, .transaction-table select { margin: 0; padding: 7px 10px; font-size: .85rem; }
.transaction-table tfoot td { background: #f8fafc; font-weight: 700; }
.transaction-table .row-no { text-align: center; color: var(--muted); font-weight: 700; }
.transaction-table .line-amount, .transaction-table tfoot input { text-align: right; font-weight: 700; background: #f8fafc; }

/* KV table */
.kv { width: 100%; }
.kv td { padding: 8px 12px; border-bottom: 1px solid #f1f5f9; font-size: .9rem; }
.kv td:first-child { color: var(--muted); width: 140px; white-space: nowrap; font-weight: 500; }

/* ============================================================
   FORMS
   ============================================================ */
label { display: block; margin: 14px 0 5px; font-weight: 600; font-size: .83rem; color: var(--text); }
input, select, textarea {
  width: 100%; padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem; font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
input[readonly], input[disabled] { background: #f8fafc; color: var(--muted); cursor: not-allowed; }
textarea { resize: vertical; min-height: 80px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 18px; }
.form-grid .col-2 { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

/* Input group */
.input-group { position: relative; }
.input-prefix {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: .9rem; pointer-events: none;
}
.input-group input { padding-left: 32px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px;
  border: 1.5px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer; font-weight: 600; text-decoration: none;
  background: #f1f5f9; color: var(--text);
  font-size: .875rem; font-family: inherit;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { background: #e2e8f0; }
.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); margin-top: 16px; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success   { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #059669; }
.btn-danger    { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-warning   { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-warning:hover { background: #d97706; }
.btn-outline   { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: #f8fafc; }
.btn-block     { width: 100%; }
.btn-sm        { padding: 5px 12px; font-size: .78rem; }
.btn-lg        { padding: 13px 28px; font-size: 1rem; }
.btn-icon      { padding: 8px; border-radius: var(--radius-sm); }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-block; padding: 3px 10px;
  border-radius: 999px; font-size: .72rem; font-weight: 700;
  text-transform: capitalize; letter-spacing: .02em; white-space: nowrap;
}
.badge-success   { background: #d1fae5; color: #065f46; }
.badge-danger    { background: #fee2e2; color: #991b1b; }
.badge-warning   { background: #fef3c7; color: #92400e; }
.badge-info      { background: #dbeafe; color: #1e40af; }
.badge-primary   { background: var(--primary-light); color: var(--primary-dark); }
.badge-gray      { background: #f1f5f9; color: #475569; }

/* Legacy task / priority badges */
.b-completed   { background: #d1fae5; color: #065f46; }
.b-in_progress { background: #fef3c7; color: #92400e; }
.b-pending     { background: #f1f5f9; color: #475569; }
.b-overdue     { background: #fee2e2; color: #991b1b; }
.b-rejected    { background: #fce7f3; color: #9d174d; }
.p-low         { background: #e0f2fe; color: #0369a1; }
.p-medium      { background: #f1f5f9; color: #475569; }
.p-high        { background: #fed7aa; color: #9a3412; }
.p-urgent      { background: #fee2e2; color: #991b1b; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
  padding: 13px 16px; border-radius: var(--radius-sm);
  margin-bottom: 16px; font-size: .875rem;
  display: flex; align-items: flex-start; gap: 10px;
  border-left: 4px solid;
}
.alert-success { background: #f0fdf4; color: #166534; border-color: var(--success); }
.alert-danger  { background: #fff5f5; color: #991b1b; border-color: var(--danger); }
.alert-warning { background: #fffbeb; color: #92400e; border-color: var(--warning); }
.alert-info    { background: #eff6ff; color: #1e40af; border-color: var(--info); }

/* ============================================================
   PROGRESS BARS
   ============================================================ */
.progress { background: #e2e8f0; border-radius: 20px; height: 8px; overflow: hidden; }
.progress div { background: var(--primary); height: 100%; border-radius: 20px; transition: width .3s; }
.progress-sm { height: 5px; }
.progress-success div { background: var(--success); }
.progress-warning div { background: var(--warning); }
.progress-danger  div { background: var(--danger); }

/* ============================================================
   NOTIFICATIONS & TIMELINE
   ============================================================ */
.notification-list { display: grid; gap: 10px; }
.notification-item {
  display: grid; grid-template-columns: auto minmax(0,1fr) auto;
  gap: 12px; align-items: center; padding: 13px 16px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; background: #fafbff;
  transition: all .15s;
}
.notification-item:hover { border-color: #c7d2fe; background: var(--primary-light); }
.notification-main { display: flex; flex-direction: column; min-width: 0; }
.notification-main strong { overflow-wrap: anywhere; }
.notification-dot { width: 10px; height: 10px; border-radius: 999px; flex-shrink: 0; }
.nd-danger  { background: var(--danger); }
.nd-warning { background: var(--warning); }
.nd-info    { background: var(--info); }

.timeline-item { border-left: 3px solid var(--primary); padding: 10px 0 10px 18px; margin-bottom: 14px; position: relative; }
.timeline-item::before { content: ''; position: absolute; left: -6px; top: 14px; width: 9px; height: 9px; border-radius: 50%; background: var(--primary); }
.ti-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }

/* ============================================================
   FILTERS / CHIPS
   ============================================================ */
.filters { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.chip {
  padding: 6px 16px; border-radius: 999px; background: #fff;
  text-decoration: none; color: var(--muted); font-size: .82rem;
  border: 1.5px solid var(--border); font-weight: 500; transition: all .15s;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ============================================================
   RECOMMENDATION BOXES
   ============================================================ */
.rec-box { background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin-top: 16px; }
.rec-tag  { display: inline-block; padding: 5px 12px; border-radius: 6px; font-size: .78rem; font-weight: 600; }
.rec-success { background: #d1fae5; color: #065f46; }
.rec-info    { background: #dbeafe; color: #1e40af; }
.rec-warning { background: #fef3c7; color: #92400e; }
.rec-danger  { background: #fee2e2; color: #991b1b; }

/* ============================================================
   MISC
   ============================================================ */
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.fw-bold { font-weight: 700; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.w-100 { width: 100%; }

/* Quick action grid */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.quick-btn {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 18px 12px; background: var(--card-bg);
  border: 1.5px solid var(--border); border-radius: var(--radius);
  text-decoration: none; color: var(--text); font-size: .82rem; font-weight: 600;
  text-align: center; transition: all .15s; box-shadow: var(--shadow);
}
.quick-btn:hover { border-color: var(--primary); background: var(--primary-light); color: var(--primary); box-shadow: var(--shadow-lg); }
.quick-btn-icon { font-size: 1.6rem; }

/* Dashboard chart cards */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: 1fr; gap: 16px; } }

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
@media (max-width: 900px)  { .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px)  { .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 16px; } }

/* ============================================================
   RESPONSIVE REFINEMENTS  (fluid grids + mobile component tweaks)
   ============================================================ */
/* Auto-fitting stat / kpi grids already collapse on their own, but
   tighten gaps and force a clean 2-up then 1-up on small screens. */
@media (max-width: 600px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .kpi-grid  { grid-template-columns: 1fr; gap: 12px; }
  .stat-num  { font-size: 1.6rem; }
  .kpi-body .kpi-value { font-size: 1.35rem; }
  .card { padding: 18px; }
  .page-header h1 { font-size: 1.35rem; }
}
@media (max-width: 400px) {
  .stat-grid { grid-template-columns: 1fr; }
}

/* Card headers wrap their actions instead of overflowing on mobile */
@media (max-width: 600px) {
  .card-header { flex-wrap: wrap; }
  .card-header h3 { flex: 1 1 100%; }
}

/* Filters / chips scroll horizontally rather than wrapping into tall stacks */
@media (max-width: 600px) {
  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  .filters::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; }
}

/* Buttons stretch full-width in tight footers / forms on phones */
@media (max-width: 480px) {
  .btn { padding: 10px 16px; }
  .card-header .btn,
  .filters + .btn { width: 100%; }
}

/* Quick-action tiles shrink gracefully */
@media (max-width: 600px) {
  .quick-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
  .quick-btn { padding: 14px 8px; font-size: .78rem; }
  .quick-btn-icon { font-size: 1.4rem; }
}

/* Tables: keep horizontal scroll but hint it on touch + larger tap targets */
@media (max-width: 600px) {
  .table { font-size: .82rem; }
  .table th, .table td { padding: 10px 10px; }
  .table-wrap { box-shadow: inset -12px 0 12px -12px rgba(0,0,0,.12); }
}

/* Forms: any multi-column grid drops to one column comfortably */
@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; gap: 0; }
}

/* Touch devices: bigger nav tap targets in the drawer */
@media (hover: none) and (pointer: coarse) {
  .nav-item, .nav-group-btn { padding-top: 12px; padding-bottom: 12px; }
  .nav-submenu a { padding-top: 10px; padding-bottom: 10px; }
}

/* ── Project-wide safety net for INLINE layouts ──────────────
   Many pages use inline `style="display:grid;grid-template-columns:…"`.
   Inline styles beat external CSS, so we use !important inside a media
   query (a media-query !important rule still wins over a non-important
   inline declaration) to collapse every inline grid to one column on
   phones — no per-page edits required. Auto-fit grids are unaffected
   in spirit (they'd collapse anyway); fixed 2/3-col grids now do too. */
@media (max-width: 760px) {
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }
}
/* Tablet: soften dense fixed 3-up inline grids handled per-page where needed */
@media (min-width: 761px) and (max-width: 1000px) {
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* Inline flex rows (filters, stat strips) wrap instead of overflowing */
@media (max-width: 600px) {
  [style*="display:flex"]:not(.topbar):not(.sidebar-footer),
  [style*="display: flex"]:not(.topbar):not(.sidebar-footer) {
    flex-wrap: wrap;
  }
}

/* Never let an inline fixed pixel width force a horizontal scrollbar.
   (Tables manage their own width via .table-wrap; canvases are sized by
   Chart.js, so both are excluded from the blanket max-width clamp.) */
.content [style*="width:"]:not(table):not(canvas):not(.table-wrap) { max-width: 100%; }
.content img, .content video, .content svg { max-width: 100%; height: auto; }

/* Print */
@media print { .sidebar, .topbar, .btn, .filters { display: none !important; } .main-wrapper { margin-left: 0; } }
