/* ============================================================
   SKYNET AUTOMATION PORTAL - Global Theme
   Brand: Dark (#0D0D0D) + Gold (#F5A623) + White text
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@300;400;500;600;700&family=DM+Sans:wght@300;400;500;600&display=swap');

/* --- CSS Variables --- */
:root {
  /* Brand */
  --gold:          #F5A623;
  --gold-light:    #FFC355;
  --gold-dark:     #C6821A;
  --gold-muted:    rgba(245, 166, 35, 0.15);
  --gold-border:   rgba(245, 166, 35, 0.3);

  /* Backgrounds */
  --bg-primary:    #0D0D0D;
  --bg-secondary:  #161616;
  --bg-card:       #1A1A1A;
  --bg-card-hover: #1F1F1F;
  --bg-sidebar:    #111111;
  --bg-input:      #222222;
  --bg-modal:      #1C1C1C;

  /* Text */
  --text-primary:   #FFFFFF;
  --text-secondary: #AAAAAA;
  --text-muted:     #666666;
  --text-gold:      #F5A623;

  /* Borders */
  --border:         rgba(255,255,255,0.08);
  --border-hover:   rgba(255,255,255,0.15);
  --border-gold:    rgba(245,166,35,0.4);

  /* Status */
  --success:        #22C55E;
  --success-bg:     rgba(34,197,94,0.12);
  --warning:        #F59E0B;
  --warning-bg:     rgba(245,158,11,0.12);
  --danger:         #EF4444;
  --danger-bg:      rgba(239,68,68,0.12);
  --info:           #3B82F6;
  --info-bg:        rgba(59,130,246,0.12);

  /* Layout */
  --sidebar-w:      260px;
  --sidebar-w-sm:   70px;
  --topbar-h:       64px;
  --radius-sm:      6px;
  --radius:         10px;
  --radius-lg:      14px;
  --radius-xl:      20px;
  --shadow:         0 4px 24px rgba(0,0,0,0.4);
  --shadow-gold:    0 4px 20px rgba(245,166,35,0.2);

  /* Typography */
  --font-heading:   'Sora', sans-serif;
  --font-body:      'DM Sans', sans-serif;

  /* Transitions */
  --transition:     0.2s ease;
  --transition-slow:0.35s ease;
}

/* Light mode overrides */
[data-theme="light"] {
  --bg-primary:    #F5F5F0;
  --bg-secondary:  #EBEBE5;
  --bg-card:       #FFFFFF;
  --bg-card-hover: #F2F2EE;
  --bg-sidebar:    #FAFAF7;
  --bg-input:      #F0F0EC;
  --bg-modal:      #FFFFFF;
  --text-primary:  #1A1A1A;
  --text-secondary:#555555;
  --text-muted:    #888888;
  --border:        rgba(0,0,0,0.09);
  --border-hover:  rgba(0,0,0,0.18);
}

/* Light mode topbar */
[data-theme="light"] .topbar {
  background: #FFFFFF;
  border-bottom-color: rgba(0,0,0,0.1);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--gold); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--gold-light); }

input, select, textarea, button { font-family: var(--font-body); }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: #333; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold-dark); }

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

/* --- Sidebar: dark in dark-mode, white/beige in light-mode --- */
.sidebar {
  /* Dark mode defaults */
  --sidebar-bg:      #111111;
  --sidebar-border:  rgba(255,255,255,0.07);
  --sidebar-text:    rgba(255,255,255,0.60);
  --sidebar-text-h:  #FFFFFF;
  --sidebar-footer-border: rgba(255,255,255,0.07);
}
[data-theme="light"] .sidebar {
  --sidebar-bg:      #FAFAF7;
  --sidebar-border:  rgba(0,0,0,0.08);
  --sidebar-text:    #555555;
  --sidebar-text-h:  #111111;
  --sidebar-footer-border: rgba(0,0,0,0.10);
}

.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  transition: width var(--transition-slow), transform var(--transition-slow);
  overflow: hidden; /* logo/footer stay clipped */
}

.sidebar.collapsed { width: var(--sidebar-w-sm); }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--sidebar-border);
  min-height: var(--topbar-h);
  flex-shrink: 0; /* never compress */
}

/* Theme-aware logo swap: logo-white.svg on dark sidebar (gold accent intact),
   logo-dark.svg on light sidebar. No CSS filter — keeps brand colors true. */
.sidebar-logo img {
  object-fit: contain;
  flex-shrink: 0;
}
.sidebar-logo .logo-on-light { display: none; }
[data-theme="light"] .sidebar-logo .logo-on-dark { display: none; }
[data-theme="light"] .sidebar-logo .logo-on-light { display: block; }
.sidebar-logo-text {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  color: var(--sidebar-text-h);
  letter-spacing: 0.04em;
  white-space: nowrap;
  transition: opacity var(--transition);
}
.sidebar-logo-text span {
  display: block;
  font-size: 0.6rem;
  font-weight: 400;
  color: var(--gold);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.sidebar.collapsed .sidebar-logo-text { opacity: 0; width: 0; }

/* Nav groups */
.nav-group {
  padding: 8px 0;
  flex: 1;
  min-height: 0; /* required for flex overflow-y scroll to work */
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  /* Custom slim scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(245,166,35,0.3) transparent;
  /* Force scroll on touch devices */
  overscroll-behavior: contain;
}
.nav-group::-webkit-scrollbar { width: 3px; }
.nav-group::-webkit-scrollbar-track { background: transparent; }
.nav-group::-webkit-scrollbar-thumb { background: rgba(245,166,35,0.3); border-radius: 3px; }

.nav-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.28); /* dark mode */
  padding: 12px 20px 4px;
  white-space: nowrap;
  transition: opacity var(--transition);
}
[data-theme="light"] .nav-label { color: #999999; }
.sidebar.collapsed .nav-label { opacity: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--sidebar-text);
  cursor: pointer;
  border-radius: 0;
  transition: all var(--transition);
  position: relative;
  white-space: nowrap;
  user-select: none;
}

.nav-item:hover {
  color: var(--sidebar-text-h);
  background: rgba(255,255,255,0.07); /* dark mode hover */
}
[data-theme="light"] .nav-item:hover {
  background: rgba(0,0,0,0.05); /* light mode hover */
}

.nav-item.active {
  color: var(--gold-dark);
  background: var(--gold-muted);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--gold);
  border-radius: 0 3px 3px 0;
}

.nav-item i {
  font-size: 1.1rem;
  flex-shrink: 0;
  width: 22px;
  text-align: center;
}

.nav-item span {
  font-size: 0.88rem;
  font-weight: 500;
  transition: opacity var(--transition);
}
.sidebar.collapsed .nav-item span { opacity: 0; width: 0; }

.nav-badge {
  margin-left: auto;
  background: var(--gold);
  color: #000;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 20px;
  transition: opacity var(--transition);
}
.sidebar.collapsed .nav-badge { opacity: 0; }

/* Sidebar bottom */
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--sidebar-footer-border);
  flex-shrink: 0; /* stays at bottom */
}

.sidebar-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition);
  font-size: 0.85rem;
}
.sidebar-toggle:hover { color: var(--text-primary); }
.sidebar-toggle i { font-size: 1rem; }

/* --- Main Content --- */
.main-content {
  flex: 1;
  min-width: 0; /* CRITICAL: lets this flex item shrink below content width,
                   so wide tables/boxes don't stretch the page past the viewport
                   (the cause of mobile "zoom out" / sideways scroll) */
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition-slow);
}

.sidebar.collapsed ~ .main-content { margin-left: var(--sidebar-w-sm); }

/* --- Topbar --- */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

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

/* Theme toggle */
.theme-toggle {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.theme-toggle:hover { border-color: var(--gold); color: var(--gold); }

/* Notification bell */
.notif-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.notif-btn:hover { border-color: var(--gold); color: var(--gold); }
.notif-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 8px; height: 8px;
  background: var(--gold);
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
}

/* Profile dropdown */
.profile-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition);
}
.profile-btn:hover { border-color: var(--gold); }
.profile-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--gold);
  color: #000;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.profile-name {
  font-size: 0.82rem;
  font-weight: 500;
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Dropdown menu */
.dropdown {
  position: relative;
}
.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 200px;
  box-shadow: var(--shadow);
  z-index: 200;
  overflow: hidden;
  display: none;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
}
.dropdown-item:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.dropdown-item.danger:hover { color: var(--danger); }
.dropdown-divider { border-top: 1px solid var(--border); margin: 4px 0; }

/* --- Page Content --- */
.page-content {
  flex: 1;
  padding: 24px;
}

.page-header {
  margin-bottom: 24px;
}
.page-header h1 {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-primary);
}
.page-header p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-top: 4px;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: border-color var(--transition);
}
.card:hover { border-color: var(--border-hover); }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}
.card-subtitle { color: var(--text-secondary); font-size: 0.8rem; margin-top: 2px; }

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--gold);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--transition);
}
.stat-card:hover { border-color: var(--border-gold); }
.stat-card:hover::after { transform: scaleX(1); }

.stat-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  background: var(--gold-muted);
  color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.stat-icon.success { background: var(--success-bg); color: var(--success); }
.stat-icon.danger  { background: var(--danger-bg);  color: var(--danger); }
.stat-icon.info    { background: var(--info-bg);    color: var(--info); }

.stat-val {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}
.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-label span.req { color: var(--gold); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.88rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-control:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(245,166,35,0.12);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled { opacity: 0.5; cursor: not-allowed; }

textarea.form-control { min-height: 90px; resize: vertical; }
select.form-control { cursor: pointer; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 0.75rem; color: var(--danger); margin-top: 4px; }

/* Checkbox / Radio */
.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 16px; height: 16px;
  accent-color: var(--gold);
  cursor: pointer;
}
.form-check-label { font-size: 0.87rem; color: var(--text-secondary); }

/* File upload */
.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}
.file-drop:hover, .file-drop.dragover {
  border-color: var(--gold);
  background: var(--gold-muted);
}
.file-drop i { font-size: 1.8rem; color: var(--text-muted); display: block; margin-bottom: 8px; }
.file-drop p { font-size: 0.85rem; color: var(--text-secondary); }
.file-drop span { font-size: 0.78rem; color: var(--text-muted); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.87rem;
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  outline: none;
}

.btn-primary {
  background: var(--gold);
  color: #000;
}
.btn-primary:hover {
  background: var(--gold-light);
  box-shadow: var(--shadow-gold);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover {
  border-color: var(--gold);
  color: var(--gold);
}

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

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid transparent;
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid transparent;
}
.btn-success:hover { background: var(--success); color: #fff; }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 11px 24px; font-size: 0.95rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Icon-only btn */
.btn-icon {
  width: 34px; height: 34px;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-icon:hover { color: var(--gold); border-color: var(--gold); }

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}
.table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 11px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-secondary);
  vertical-align: middle;
}
.table tr:hover td { background: var(--bg-card-hover); }
.table tr:last-child td { border-bottom: none; }

/* ============================================================
   BADGES / STATUS
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.badge-gold    { background: var(--gold-muted); color: var(--gold); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-info    { background: var(--info-bg);    color: var(--info); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-muted   { background: rgba(255,255,255,0.06); color: var(--text-muted); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.show { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(10px);
  transition: transform var(--transition);
  box-shadow: var(--shadow);
}
.modal-overlay.show .modal { transform: translateY(0); }
.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1100px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
}
.modal-close {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   ALERTS / TOASTS
   ============================================================ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid;
  font-size: 0.86rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.alert-success { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.alert-danger   { background: var(--danger-bg);  border-color: var(--danger);  color: var(--danger); }
.alert-warning  { background: var(--warning-bg); border-color: var(--warning); color: var(--warning); }
.alert-info     { background: var(--info-bg);    border-color: var(--info);    color: var(--info); }

/* Toast container */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.86rem;
  color: var(--text-primary);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: all;
  transform: translateX(100px);
  opacity: 0;
  transition: all 0.3s ease;
  max-width: 320px;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info    { border-left: 3px solid var(--gold); }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 16px;
  justify-content: center;
}
.page-btn {
  min-width: 32px; height: 32px;
  padding: 0 8px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.83rem;
  cursor: pointer;
  transition: all var(--transition);
}
.page-btn:hover { border-color: var(--gold); color: var(--gold); }
.page-btn.active { background: var(--gold); border-color: var(--gold); color: #000; font-weight: 600; }
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ============================================================
   SESSION TIMEOUT OVERLAY
   ============================================================ */
#session-warning {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  display: none;
}
#session-warning .warn-box {
  background: var(--bg-modal);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-xl);
  padding: 32px;
  text-align: center;
  max-width: 380px;
}
#session-warning i { font-size: 2.5rem; color: var(--warning); display: block; margin-bottom: 12px; }
#session-warning h3 { font-family: var(--font-heading); font-size: 1.1rem; margin-bottom: 8px; }
#session-warning p { color: var(--text-secondary); font-size: 0.88rem; margin-bottom: 20px; }
#session-countdown { font-size: 2rem; font-weight: 700; color: var(--gold); font-family: var(--font-heading); }

/* ============================================================
   SEARCH BAR
   ============================================================ */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  transition: border-color var(--transition);
}
.search-bar:focus-within { border-color: var(--gold); }
.search-bar i { color: var(--text-muted); font-size: 0.95rem; }
.search-bar input {
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.87rem;
  flex: 1;
  min-width: 0;
}

/* ============================================================
   TABS
   ============================================================ */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  padding: 9px 18px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.87rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: var(--font-body);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--gold); border-bottom-color: var(--gold); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

/* Subtle background grid */
.login-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(245,166,35,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(245,166,35,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
}

/* Gold glow blob */
.login-page::after {
  content: '';
  position: absolute;
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(245,166,35,0.08) 0%, transparent 70%);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 1;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.login-logo img { width: 120px; }
.login-logo .portal-tag {
  display: inline-block;
  padding: 5px 18px;
  background: var(--gold-muted);
  border: 1px solid var(--gold-border);
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

.login-title {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 4px;
  text-align: center;
}
.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 24px;
}

/* ============================================================
   NOTIFICATIONS PANEL
   ============================================================ */
.notif-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  z-index: 200;
  display: none;
  overflow: hidden;
}
.notif-panel.show { display: block; }
.notif-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
}
.notif-list { max-height: 340px; overflow-y: auto; }
.notif-item {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
  transition: background var(--transition);
}
.notif-item:hover { background: var(--bg-card-hover); }
.notif-item.unread { border-left: 3px solid var(--gold); }
.notif-item-title { font-size: 0.83rem; font-weight: 500; color: var(--text-primary); }
.notif-item-msg { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.notif-item-time { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; }

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

  .sidebar {
    transform: translateX(-100%);
    z-index: 500;
    box-shadow: var(--shadow);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0 !important;
  }

  .mobile-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 490;
    display: none;
  }
  .mobile-overlay.show { display: block; }

  .topbar {
    padding: 0 16px;
  }

  .page-content { padding: 16px; }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .login-card { padding: 28px 20px; }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.text-gold    { color: var(--gold) !important; }
.text-muted   { color: var(--text-muted) !important; }
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }

.d-flex   { display: flex; }
.d-grid   { display: grid; }
.d-none   { display: none; }
.flex-1   { flex: 1; }
.gap-8    { gap: 8px; }
.gap-12   { gap: 12px; }
.gap-16   { gap: 16px; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end  { justify-content: flex-end; }

.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

.w-full { width: 100%; }
.fw-600 { font-weight: 600; }
.fs-sm  { font-size: 0.82rem; }
.nowrap { white-space: nowrap; }

/* Loading spinner */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Pulse dot */
.pulse {
  width: 8px; height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%,100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(0.8); }
}

/* Divider */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ============================================================
   PRINT STYLES (for BOQ / Order PDF preview)
   ============================================================ */
@media print {
  .sidebar, .topbar, .btn, .no-print { display: none !important; }
  .main-content { margin-left: 0 !important; }
  body { background: #fff; color: #000; }
  .card { border: 1px solid #ddd; box-shadow: none; }
}

/* ============================================================
   MOBILE OPTIMISATION - Comprehensive
   ============================================================ */

/* Topbar — tighter on mobile */
@media (max-width: 768px) {
  .topbar-title { font-size: 0.88rem; }

  /* Hide profile name text on small screens */
  .profile-name { display: none; }

  /* Notification panel full-width on mobile */
  .notif-panel { width: calc(100vw - 32px); right: -8px; }

  /* Page header stack on mobile */
  .page-header.d-flex { flex-direction: column; align-items: flex-start !important; gap: 12px; }
  .page-header .d-flex { flex-wrap: wrap; }

  /* Cards stack vertically */
  .card { padding: 16px; }
  .card-header { flex-wrap: wrap; gap: 8px; }

  /* Filter bars stack */
  .card form.d-flex { flex-direction: column; align-items: stretch !important; }
  .card form.d-flex .search-bar { width: 100% !important; }
  .card form.d-flex select,
  .card form.d-flex .form-control { width: 100% !important; }
  .card form.d-flex .btn { width: 100%; justify-content: center; }

  /* Tables — horizontal scroll with sticky first column */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .table th, .table td { padding: 8px 10px; font-size: 0.8rem; white-space: nowrap; }

  /* Stat grid 2-col on mobile */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 12px; }
  .stat-val { font-size: 1.2rem; }
  .stat-icon { width: 36px; height: 36px; font-size: 1rem; }

  /* Modals full-screen on mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100% !important;
    width: 100% !important;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 92vh;
  }

  /* Form rows single column */
  .form-row { grid-template-columns: 1fr !important; }

  /* Dealer approval cards */
  .dealer-action-panel { min-width: 100% !important; }

  /* Collapse ALL inline-styled multi-column grids to single column.
     Catches 1fr 1fr, 1fr 1fr 1fr, 1fr auto, 2fr 1fr, auto-fill variants —
     every panel layout grid set via style="" attributes. Class-based grids
     (.boq-prod-grid, .stat-grid) keep their own responsive rules. */
  .page-content div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Wide tables that aren't wrapped in .table-wrap — make them scroll
     instead of overflowing the viewport */
  .page-content table.table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Kill sideways page scroll / zoom-out (root cause: wide content
        forcing the layout wider than the screen) ── */
  html, body { max-width: 100%; overflow-x: hidden; }
  .app-layout { max-width: 100vw; overflow-x: hidden; }
  .main-content { max-width: 100vw; overflow-x: hidden; }
  .page-content { max-width: 100%; overflow-x: hidden; }

  /* Any inline fixed-pixel width can't exceed the screen */
  .page-content [style*="px"] { max-width: 100%; }
  /* Any inline min-width can't force horizontal overflow */
  .page-content [style*="min-width"] { min-width: 0 !important; }

  /* Scrollable table wrappers stay inside the viewport and scroll internally */
  .table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Long unbreakable tokens (SKUs, emails, URLs) wrap instead of overflowing */
  td, code, .boq-card-meta, .boq-card-name { overflow-wrap: anywhere; word-break: break-word; }

  /* Tabs scrollable */
  .tabs { gap: 0; }
  .tab-btn { padding: 8px 14px; font-size: 0.82rem; }

  /* Button groups wrap */
  .d-flex.gap-8 { flex-wrap: wrap; }

  /* Hide non-essential table columns on small screens */
  .table .hide-mobile { display: none; }

  /* Topbar actions compact */
  .topbar-actions { gap: 4px; }

  /* Profile button minimal */
  .profile-btn { padding: 4px 8px; }

  /* Sidebar footer */
  .sidebar-footer { padding: 12px 16px; }
}

/* Very small screens */
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-val { font-size: 1.1rem; }
  .page-content { padding: 12px; }
  .card { padding: 14px; }

  /* Stack page header buttons */
  .page-header .btn { width: 100%; justify-content: center; }

  /* Topbar squeeze */
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-title { font-size: 0.82rem; max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Theme toggle hidden on very small */
  .theme-toggle { display: none; }
}

/* Tablet landscape — sidebar collapsible */
@media (max-width: 1024px) and (min-width: 769px) {
  :root { --sidebar-w: 220px; }
  .nav-item { padding: 9px 16px; }
  .nav-item span { font-size: 0.84rem; }
}

/* Touch targets — minimum 44px for all interactive elements */
@media (hover: none) and (pointer: coarse) {
  .btn, .btn-icon, .nav-item, .tab-btn, .page-btn,
  .form-control, select.form-control { min-height: 44px; }
  .btn-sm { min-height: 38px; }
  .table td, .table th { padding: 12px 10px; }
  .dropdown-item { padding: 14px 16px; }
  .nav-item { padding: 12px 20px; }
}

/* ============================================================
   LOGO IMAGE FIXES
   ============================================================ */
.sidebar-logo {
  padding: 14px 16px;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
}

.sidebar-logo img {
  height: 34px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  transition: all var(--transition-slow);
  flex-shrink: 0;
}

/* Collapsed sidebar — show only the icon portion */
.sidebar.collapsed .sidebar-logo img {
  width: 34px;
  max-width: 34px;
  object-fit: cover;
  object-position: left center;
}

/* Sidebar logos: two <img> per header.php (logo-white.svg for dark theme,
   logo-dark.svg for light theme) — toggled by the .logo-on-dark/.logo-on-light
   rules near the top of this file. SVGs carry a tight viewBox (424 519 2565 651). */

/* ============================================================
   MOBILE APP SHELL — bottom nav, notif sheet, card-tables (≤768px)
   Added for the 90%-mobile experience. Desktop unaffected.
   ============================================================ */
.mobile-bottomnav { display: none; }

@media (max-width: 768px) {
  /* ── Bottom navigation bar (app-like) ─────────────────── */
  .mobile-bottomnav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0;
    height: 58px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    z-index: 460;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -4px 18px rgba(0,0,0,.28);
  }
  .mobile-bottomnav > a,
  .mobile-bottomnav > button {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    background: none; border: none;
    color: var(--text-muted);
    font-size: 0.6rem; font-weight: 600; letter-spacing: .2px;
    text-decoration: none; cursor: pointer;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-bottomnav i { font-size: 1.4rem; line-height: 1; }
  .mobile-bottomnav .mbn-active { color: var(--gold); }
  .mobile-bottomnav .mbn-active::before {
    content: ''; position: absolute; top: 0; left: 50%;
    width: 26px; height: 3px; transform: translateX(-50%);
    background: var(--gold); border-radius: 0 0 3px 3px;
  }
  .mobile-bottomnav .mbn-badge {
    position: absolute; top: 5px; left: calc(50% + 7px);
    min-width: 15px; height: 15px; padding: 0 4px;
    background: var(--danger); color: #fff;
    border-radius: 8px; font-size: 0.56rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
  }

  /* Reserve space so page content / FABs clear the bar */
  .page-content { padding-bottom: 76px !important; }

  /* ── Notification panel → pinned in-viewport sheet ─────── */
  .notif-panel {
    position: fixed !important;
    left: 8px !important; right: 8px !important;
    top: auto !important; bottom: 66px !important;
    width: auto !important; max-width: none !important;
    max-height: 68vh; overflow-y: auto;
    border-radius: var(--radius-lg);
  }

  /* ── Card-ified tables: <table class="table table-cards"> ──
     Rows become stacked cards; each cell shows its column via data-label. */
  table.table-cards,
  table.table-cards tbody,
  table.table-cards tr,
  table.table-cards td { display: block; width: 100%; }
  table.table-cards thead { display: none; }
  table.table-cards { overflow: visible !important; }
  table.table-cards tr {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 10px;
  }
  table.table-cards td {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px;
    padding: 5px 0 !important;
    border: none !important;
    white-space: normal !important;
    text-align: right;
  }
  table.table-cards td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 0.7rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .3px;
    text-align: left; flex-shrink: 0;
  }
  table.table-cards td:first-child {
    border-bottom: 1px solid var(--border) !important;
    padding-bottom: 9px !important; margin-bottom: 5px;
  }
  table.table-cards td:first-child::before { align-self: center; }
}
