/* ============================================================
   Canal Homes ERP — Premium Design System
   Plain PHP build — no framework, hand-crafted CSS
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  /* Brand */
  --primary-900: #0f172a;
  --primary-800: #1e293b;
  --primary-600: #1e40af;
  --primary-500: #3b82f6;
  --primary-100: #dbeafe;
  --primary-50:  #eff6ff;

  --success-600: #059669;
  --success-100: #d1fae5;
  --warning-600: #d97706;
  --warning-100: #fef3c7;
  --danger-600:  #dc2626;
  --danger-100:  #fee2e2;
  --purple-600:  #7c3aed;
  --purple-100:  #ede9fe;

  --gray-900: #0f172a;
  --gray-700: #374151;
  --gray-600: #64748b;
  --gray-400: #94a3b8;
  --gray-200: #e2e8f0;
  --gray-100: #f1f5f9;
  --gray-50:  #f8fafc;
  --white: #ffffff;
  --surface: #ffffff;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(15,23,42,0.06);
  --shadow-md: 0 4px 14px rgba(15,23,42,0.08);
  --shadow-lg: 0 12px 32px rgba(15,23,42,0.12);

  --sidebar-w: 260px;

  /* Redesign additions — premium white theme, KPI/chart cards, sidebar */
  --accent: #2a78d6;
  --accent-light: #e6f1fb;
  --card-border: #ececec;
  --card-radius: 12px;
  --trend-up-bg: #e7f5ee;
  --trend-up-fg: #0f6e56;
  --trend-down-bg: #fdeceb;
  --trend-down-fg: #a32d2d;

  /* Hero/alert colors used by dashboard.php's inline style block —
     kept as tokens here (rather than literal hex there) so dark mode
     can override them from one place instead of duplicating per-page. */
  --hero-danger-bg: #fee2e2;
  --hero-danger-fg: #dc2626;
  --hero-warning-bg: #fef3c7;
  --hero-warning-fg: #d97706;
}

/* ── DARK THEME ───────────────────────────────────
   Every rule elsewhere in this file reads colors through the variables
   above, so overriding the variables here re-themes the whole app
   without touching individual component rules. Toggled via
   [data-theme="dark"] on <html>, set by the theme-toggle script in
   footer.php. Default is light — no prefers-color-scheme auto-detect,
   per product decision. */
[data-theme="dark"] {
  --primary-900: #f1f5f9;
  --primary-800: #e2e8f0;
  --primary-600: #4a94e0;
  --primary-500: #5ea3e8;
  --primary-100: #1c3a5e;
  --primary-50:  #16283f;

  --success-600: #34d399;
  --success-100: #103826;
  --warning-600: #fbbf46;
  --warning-100: #3d2c0a;
  --danger-600:  #f37272;
  --danger-100:  #3d1414;
  --purple-600:  #a78bfa;
  --purple-100:  #2e1f57;

  --gray-900: #eef0f3;
  --gray-700: #c7cad1;
  --gray-600: #9aa0ab;
  --gray-400: #74798a;
  --gray-200: #2a2d35;
  --gray-100: #1e2027;
  --gray-50:  #191b21;
  --white: #14161b;
  --surface: #191b21;

  --accent: #4a94e0;
  --accent-light: #16283f;
  --card-border: #2a2d35;
  --trend-up-bg: #103826;
  --trend-up-fg: #34d399;
  --trend-down-bg: #3d1414;
  --trend-down-fg: #f37272;

  --hero-danger-bg: #3d1414;
  --hero-danger-fg: #f37272;
  --hero-warning-bg: #3d2c0a;
  --hero-warning-fg: #fbbf46;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.35);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.45);
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }

/* ── SHELL LAYOUT ─────────────────────────────── */
.erp-shell { display: flex; min-height: 100vh; }

/* ── SIDEBAR ──────────────────────────────────── */
.erp-sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--card-border);
  flex-shrink: 0;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  transition: margin-left .25s ease;
  scrollbar-width: thin;
  scrollbar-color: var(--gray-200) transparent;
}
.erp-sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }
.erp-sidebar::-webkit-scrollbar { width: 5px; }
.erp-sidebar::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 3px; }

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--card-border);
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--card-border);
  padding: 4px; object-fit: contain;
  flex-shrink: 0;
}
.brand-text { color: var(--gray-900); font-weight: 600; font-size: 14px; line-height: 1.2; }
.brand-text small { display: block; font-size: 10px; font-weight: 500; color: var(--gray-400); letter-spacing: .1em; }

.sidebar-nav { padding: 10px 10px 32px; }

/* Top-level item (Dashboard) — not inside a collapsible group */
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin-bottom: 2px;
  border-radius: 8px;
  color: var(--gray-600); font-size: 13px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(42,120,214,0.06); color: var(--gray-700); }
.nav-item.active { background: var(--accent-light); color: var(--accent); font-weight: 600; border-left: 3px solid var(--accent); padding-left: 7px; }
.nav-item.active .nav-icon { filter: none; }
.nav-icon { font-size: 16px; width: 18px; text-align: center; flex-shrink: 0; color: var(--gray-400); }
.nav-item:hover .nav-icon { color: var(--accent); }
.nav-item.active .nav-icon { color: var(--accent); }
.dash-card-icon { color: var(--accent); }

/* Collapsible nav groups — <details>/<summary>, no JS required */
.nav-group { border: none; margin-top: 2px; }
.nav-group-label {
  display: flex; align-items: center; justify-content: space-between;
  list-style: none; cursor: pointer; user-select: none;
  font-size: 11px; font-weight: 600; color: var(--gray-400);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 9px 10px 9px 10px; border-radius: 8px;
}
.nav-group-label::-webkit-details-marker { display: none; }
.nav-group-label:hover { background: rgba(42,120,214,0.06); color: var(--gray-700); }
.nav-group-label::after {
  content: ''; width: 6px; height: 6px; flex-shrink: 0;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg); transition: transform .15s;
}
.nav-group[open] > .nav-group-label::after { transform: rotate(-135deg); }
.nav-group-body { padding: 2px 0 4px; }

/* ── MAIN ─────────────────────────────────────── */
.erp-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.erp-topbar {
  height: 64px; background: var(--surface); border-bottom: 1px solid var(--card-border);
  display: flex; align-items: center; gap: 16px; padding: 0 24px;
  position: sticky; top: 0; z-index: 20;
}
.sidebar-toggle {
  background: none; border: none; font-size: 18px; cursor: pointer;
  color: var(--gray-600); padding: 6px; border-radius: 6px;
}
.sidebar-toggle:hover { background: var(--gray-100); }
.page-title { font-size: 18px; font-weight: 700; color: var(--gray-900); flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-user { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary-600); color: #fff; font-weight: 700; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.user-name { font-size: 13px; font-weight: 600; color: var(--gray-700); }
.btn-logout {
  width: 32px; height: 32px; border-radius: 8px; background: var(--gray-100);
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-600); font-size: 15px;
}
.btn-logout:hover { background: var(--danger-100); color: var(--danger-600); }

.erp-content { padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ── ALERTS / FLASH ───────────────────────────── */
.alert {
  padding: 12px 16px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500; margin-bottom: 16px;
  border-left: 3px solid;
  animation: slideDown .25s ease;
}
.alert-success { background: var(--success-100); color: var(--success-600); border-color: var(--success-600); }
.alert-error   { background: var(--danger-100); color: var(--danger-600); border-color: var(--danger-600); }
@keyframes slideDown { from { opacity:0; transform:translateY(-8px);} to {opacity:1; transform:translateY(0);} }

/* ── CARDS ────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--card-radius);
  padding: 20px; margin-bottom: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--gray-100);
}
.card-header h3 { font-size: 15px; font-weight: 700; color: var(--gray-900); }

/* ── KPI CARDS ────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 12px; margin-bottom: 20px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--card-radius);
  padding: 16px 18px;
  transition: border-color .15s;
}
.kpi-card:hover { border-color: var(--gray-200); }
.kpi-label { font-size: 12px; font-weight: 500; color: var(--gray-600); }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--gray-900); margin-top: 6px; }
.kpi-sub { font-size: 12px; color: var(--gray-400); margin-top: 4px; }
.kpi-sub.up { color: var(--success-600); }
.kpi-sub.down { color: var(--danger-600); }

/* KPI trend badge — small pill with arrow, next to or below the value */
.kpi-trend {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px;
  margin-top: 6px;
}
.kpi-trend.up { background: var(--trend-up-bg); color: var(--trend-up-fg); }
.kpi-trend.down { background: var(--trend-down-bg); color: var(--trend-down-fg); }

/* Chart card — hosts a Chart.js canvas, no extra padding tricks needed */
.chart-card { background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--card-radius); padding: 18px 20px; margin-bottom: 20px; }
.chart-card h3 { font-size: 13px; font-weight: 600; color: var(--gray-900); margin-bottom: 14px; }
.chart-canvas-wrap { position: relative; width: 100%; }

/* Filter pills — row of quick-filter chips above KPI grid */
.filter-pills { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-pill {
  font-size: 12px; font-weight: 500; padding: 6px 14px; border-radius: 99px;
  border: 1px solid var(--card-border); color: var(--gray-600);
}
.filter-pill:hover { background: var(--gray-50); }
.filter-pill.active { background: var(--accent-light); color: var(--accent); border-color: var(--accent-light); font-weight: 600; }

/* ── BUTTONS ──────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 600;
  border: none; cursor: pointer; transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary-600); color: #fff; }
.btn-primary:hover { filter: brightness(0.9); }
.btn-secondary { background: var(--surface); border: 1px solid var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-50); }
.btn-success { background: var(--success-600); color: #fff; }
.btn-danger { background: var(--danger-600); color: #fff; }
.btn-warning { background: var(--warning-600); color: #fff; }
.btn-purple { background: var(--purple-600); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ── FORMS ────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .03em; }
.form-control {
  width: 100%; padding: 9px 12px; border: 1px solid var(--gray-200); border-radius: 8px;
  font-size: 13px; font-family: inherit; color: var(--gray-900); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus { outline: none; border-color: var(--primary-500); box-shadow: 0 0 0 3px var(--primary-100); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 16px; }

/* ── TABLES ───────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--card-radius); border: 1px solid var(--card-border); }
table.erp-table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 13px; }
table.erp-table thead th {
  background: var(--gray-50); color: var(--gray-600); text-align: left;
  padding: 10px 14px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--card-border);
}
table.erp-table tbody td { padding: 11px 14px; border-bottom: 1px solid var(--gray-100); color: var(--gray-700); }
table.erp-table tbody tr:hover { background: var(--gray-50); }
table.erp-table tbody tr:last-child td { border-bottom: none; }

/* ── BADGES ───────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em;
}
.badge-green  { background: var(--success-100); color: var(--success-600); }
.badge-red    { background: var(--danger-100); color: var(--danger-600); }
.badge-amber  { background: var(--warning-100); color: var(--warning-600); }
.badge-blue   { background: var(--primary-100); color: var(--primary-600); }
.badge-purple { background: var(--purple-100); color: var(--purple-600); }
.badge-gray   { background: var(--gray-100); color: var(--gray-600); }

/* ── UTILITY ──────────────────────────────────── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-400); }
.text-success { color: var(--success-600); }
.text-danger { color: var(--danger-600); }
.font-mono { font-family: 'JetBrains Mono', monospace; }
.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; }
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-4 { gap: 16px; }

/* ── EMPTY STATE ──────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--gray-400); }
.empty-state .icon { font-size: 44px; margin-bottom: 12px; }
.empty-state .title { font-size: 15px; font-weight: 600; color: var(--gray-600); }

/* ── PAGINATION ───────────────────────────────── */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; }
.pagination a, .pagination span {
  padding: 7px 12px; border-radius: 6px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--gray-200); color: var(--gray-700);
}
.pagination .active { background: var(--primary-600); color: #fff; border-color: var(--primary-600); }

/* ── ANIMATIONS ───────────────────────────────── */
@keyframes fadeInUp { from { opacity:0; transform:translateY(8px);} to {opacity:1; transform:translateY(0);} }
.card, .kpi-card { animation: fadeInUp .3s ease; }

/* ── RESPONSIVE ───────────────────────────────── */
@media (max-width: 900px) {
  .erp-sidebar { position: fixed; z-index: 50; margin-left: calc(-1 * var(--sidebar-w)); }
  .erp-sidebar.mobile-open { margin-left: 0; box-shadow: var(--shadow-lg); }
  .erp-content { padding: 16px; }
}

/* ── THEME TOGGLE ─────────────────────────────── */
.theme-toggle {
  background: none; border: none; font-size: 18px; cursor: pointer;
  color: var(--gray-600); padding: 6px; border-radius: 8px; line-height: 1;
}
.theme-toggle:hover { background: var(--gray-50); }

/* ── NOTIFICATION BELL ────────────────────────── */
.notif-bell-wrap { position: relative; }
.notif-bell {
  background: none; border: none; font-size: 19px; cursor: pointer; position: relative;
  padding: 6px; border-radius: 8px; line-height: 1;
}
.notif-bell:hover { background: var(--gray-100); }
.notif-badge {
  position: absolute; top: 0; right: 0; background: #dc2626; color: #fff;
  font-size: 10px; font-weight: 700; border-radius: 99px; min-width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px;
}
.nav-badge {
  margin-left: auto; background: #dc2626; color: #fff;
  font-size: 10px; font-weight: 700; border-radius: 99px; min-width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
.notif-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 8px); width: 300px;
  background: var(--surface); border: 1px solid var(--gray-200); border-radius: 10px;
  box-shadow: var(--shadow-lg); z-index: 100; overflow: hidden;
}
.notif-dropdown.open { display: block; }
.notif-dropdown-header {
  padding: 10px 14px; font-size: 11px; font-weight: 700; text-transform: uppercase;
  color: var(--gray-400); border-bottom: 1px solid var(--gray-100);
}
.notif-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; font-size: 13px;
  color: var(--gray-700); text-decoration: none; border-bottom: 1px solid var(--gray-50);
}
.notif-item:hover { background: var(--gray-50); }
.notif-item:last-child { border-bottom: none; }
.notif-icon { font-size: 15px; }
.notif-empty { padding: 20px 14px; text-align: center; font-size: 12px; color: var(--gray-400); }

/* ── TOPBAR SEARCH ────────────────────────────── */
.topbar-search { flex: 1; max-width: 380px; margin: 0 20px; }
.topbar-search-input {
  width: 100%; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--gray-200);
  background: var(--gray-50); font-size: 13px; outline: none;
}
.topbar-search-input:focus { border-color: var(--accent); background: var(--surface); }
@media (max-width: 900px) { .topbar-search { display: none; } }
