/* ============================================================
   SPYXTECH ERP — Main Stylesheet
   Modern SaaS design system. Responsive, theme-driven.
   ============================================================ */

/* --- CSS Variables (overridden by theme settings) --- */
:root {
  --primary: #1a56db;
  --primary-hover: #1648c0;
  --primary-light: #e8effd;
  --secondary: #0d9488;
  --accent: #f59e0b;
  --sidebar-bg: #1e293b;
  --sidebar-text: #f1f5f9;
  --sidebar-width: 250px;
  --sidebar-collapsed: 0px;
  --topbar-height: 60px;
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --transition: 0.2s ease;
}

/* Dark mode */
[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --border-light: #1e293b;
  --sidebar-bg: #0f172a;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
}

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

html { font-size: 15px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-family);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
}

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

img { max-width: 100%; height: auto; }

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

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition);
  overflow-y: auto;
}

.sidebar-logo {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar-height);
}

.sidebar-logo img {
  height: 36px;
  width: auto;
  border-radius: 6px;
}

.sidebar-logo .logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.sidebar-logo .logo-sub {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.5);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.sidebar-nav .nav-label {
  padding: 8px 20px 4px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.35);
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  border-left: 3px solid transparent;
  cursor: pointer;
}

.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.nav-item.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-left-color: var(--primary);
}

.nav-item i {
  width: 22px;
  margin-right: 12px;
  font-size: 1.1rem;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 0.75rem;
  color: rgba(255,255,255,0.4);
}

/* --- Top Bar --- */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 999;
  gap: 16px;
  transition: left var(--transition);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.sidebar-toggle:hover { background: var(--border-light); }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .current { color: var(--text); font-weight: 600; }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Global search */
.global-search {
  position: relative;
  width: 320px;
}

.global-search input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  transition: all var(--transition);
}

.global-search input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.15);
}

.global-search i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Search results dropdown */
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 360px;
  overflow-y: auto;
  display: none;
  z-index: 2000;
}

.search-results.active { display: block; }

.search-result-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background var(--transition);
}

.search-result-item:hover { background: var(--primary-light); }
.search-result-item:last-child { border-bottom: none; }

.search-result-item .result-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.search-result-item .result-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.search-result-item .result-badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  margin-right: 6px;
}

/* User menu */
.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: background var(--transition);
  position: relative;
}

.user-menu:hover { background: var(--border-light); }

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
  overflow: hidden;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-info { line-height: 1.3; }
.user-name { font-size: 0.85rem; font-weight: 600; color: var(--text); }
.user-role { font-size: 0.7rem; color: var(--text-muted); text-transform: capitalize; }

.user-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 200px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 2000;
}

.user-dropdown.active { display: block; }
.user-dropdown a {
  display: block;
  padding: 10px 16px;
  font-size: 0.85rem;
  color: var(--text);
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}

.user-dropdown a:hover { background: var(--border-light); }
.user-dropdown a:last-child { border-bottom: none; }
.user-dropdown a i { width: 20px; margin-right: 8px; color: var(--text-muted); }

/* --- Main Content --- */
.main-content {
  margin-left: var(--sidebar-width);
  padding-top: var(--topbar-height);
  flex: 1;
  transition: margin-left var(--transition);
  min-height: 100vh;
}

.page-content {
  padding: 24px;
  max-width: 1400px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.page-title small {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 8px;
}

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

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

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.card-body { padding: 20px; }
.card-body:only-child { padding: 20px; }
.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* --- KPI Cards --- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all var(--transition);
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 6px;
}

.kpi-trend.up { color: var(--success); }
.kpi-trend.down { color: var(--danger); }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.4;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--border-light); }

.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-info { background: var(--info); color: #fff; }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }

.btn-group {
  display: inline-flex;
  gap: 6px;
}

/* --- Forms --- */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.15);
}

.form-control.error, .form-select.error, .form-textarea.error {
  border-color: var(--danger);
}

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

.form-textarea { min-height: 100px; resize: vertical; }

.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: 2px;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.form-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* --- Tables --- */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.dataTable {
  width: 100% !important;
  border-collapse: collapse;
}

.dataTable th {
  background: var(--bg);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 12px 14px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.dataTable td {
  padding: 10px 14px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.dataTable tbody tr:hover {
  background: var(--primary-light);
}

.dataTable .actions-cell {
  white-space: nowrap;
  text-align: right;
}

/* --- Status Badges --- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #e2e8f0; color: #475569; }
.badge-primary { background: var(--primary-light); color: var(--primary); }

[data-theme="dark"] .badge-success { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-warning { background: #78350f; color: #fcd34d; }
[data-theme="dark"] .badge-danger { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .badge-info { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-secondary { background: #334155; color: #cbd5e1; }
[data-theme="dark"] .badge-primary { background: #1e3a5f; color: #93c5fd; }

/* --- Modals --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}

.modal-lg { max-width: 900px; }
.modal-sm { max-width: 400px; }

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

.modal-title { font-size: 1.1rem; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  border-radius: 4px;
}

.modal-close:hover { color: var(--text); background: var(--border-light); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* --- Alerts / Notifications --- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

[data-theme="dark"] .alert-success { background: #064e3b; color: #6ee7b7; border-color: #065f46; }
[data-theme="dark"] .alert-danger { background: #7f1d1d; color: #fca5a5; border-color: #991b1b; }
[data-theme="dark"] .alert-warning { background: #78350f; color: #fcd34d; border-color: #92400e; }
[data-theme="dark"] .alert-info { background: #1e3a5f; color: #93c5fd; border-color: #1e40af; }

/* Toast notifications */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s ease;
  max-width: 400px;
}

.toast-success { background: var(--success); color: #fff; }
.toast-danger { background: var(--danger); color: #fff; }
.toast-warning { background: var(--warning); color: #fff; }
.toast-info { background: var(--info); color: #fff; }

/* --- Charts --- */
.chart-container {
  position: relative;
  height: 280px;
  width: 100%;
}

.chart-container-sm { height: 200px; }

/* --- Line Item Editor --- */
.line-item-editor { width: 100%; }
.line-item-editor th {
  background: var(--bg);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 10px;
  text-align: left;
  border-bottom: 2px solid var(--border);
}

.line-item-editor td { padding: 6px 8px; border-bottom: 1px solid var(--border-light); }
.line-item-editor input, .line-item-editor select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: var(--bg-card);
  color: var(--text);
}

.line-item-editor input:focus { outline: none; border-color: var(--primary); }
.line-item-editor .item-total { font-weight: 700; text-align: right; }

.summary-row {
  display: flex;
  justify-content: flex-end;
  gap: 40px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 2px solid var(--border);
}

.summary-item { text-align: right; }
.summary-item .label { font-size: 0.8rem; color: var(--text-muted); }
.summary-item .value { font-size: 1.1rem; font-weight: 700; }
.summary-item .value.total { font-size: 1.4rem; color: var(--primary); }

/* --- Avatar initials --- */
.avatar-initials {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  background: var(--primary);
  flex-shrink: 0;
}

/* --- Login Page --- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 100%;
  max-width: 420px;
  padding: 40px;
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  width: 64px;
  height: 64px;
  background: var(--primary);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  color: #fff;
  font-size: 1.6rem;
  font-weight: 800;
}

.login-header h1 { font-size: 1.4rem; color: #1e293b; font-weight: 700; }
.login-header p { font-size: 0.85rem; color: #64748b; margin-top: 4px; }

.login-form .form-group { margin-bottom: 20px; }
.login-form .form-label { color: #475569; font-size: 0.85rem; font-weight: 600; }
.login-form .form-control {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.95rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}

.login-form .form-control:focus {
  background: #fff;
  border-color: var(--primary);
}

.login-btn {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background var(--transition);
}

.login-btn:hover { background: var(--primary-hover); }
.login-btn:disabled { opacity: 0.7; cursor: not-allowed; }

.login-error {
  background: #fee2e2;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: none;
}

.login-error.active { display: block; }

.login-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 0.75rem;
  color: #94a3b8;
}

/* --- Utility Classes --- */
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.ml-auto { margin-left: auto; }
.w-100 { width: 100%; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* --- Activity Feed --- */
.activity-feed { list-style: none; }
.activity-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

.activity-content { flex: 1; }
.activity-content .activity-text { font-size: 0.85rem; color: var(--text); }
.activity-content .activity-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* --- Responsive --- */
@media (max-width: 991px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle { display: block; }

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

  .topbar {
    left: 0;
  }

  .global-search { width: 200px; }

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

@media (max-width: 767px) {
  :root { --topbar-height: 56px; }

  .page-content { padding: 16px; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .kpi-value { font-size: 1.3rem; }

  .page-header { flex-direction: column; align-items: flex-start; }

  .global-search { width: 160px; }

  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

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

  .summary-row { flex-direction: column; gap: 12px; }

  .topbar { padding: 0 12px; }
  .user-info { display: none; }

  .modal { max-width: 100%; margin: 10px; max-height: 95vh; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-card { padding: 14px; }
  .kpi-value { font-size: 1.1rem; }
  .kpi-label { font-size: 0.7rem; }

  .login-card { padding: 24px; }
}

/* --- Animations --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(100px); } to { opacity: 1; transform: translateX(0); } }

/* --- DataTables overrides --- */
.dataTables_wrapper .dataTables_filter input {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  padding: 6px 12px !important;
  font-size: 0.85rem !important;
  background: var(--bg) !important;
  color: var(--text) !important;
}

.dataTables_wrapper .dataTables_length select {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  padding: 4px 8px !important;
  background: var(--bg-card) !important;
  color: var(--text) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
  border-radius: 6px !important;
  padding: 4px 12px !important;
  font-size: 0.85rem !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff !important;
}

/* --- Slide-over panel (for forms) --- */
.slide-panel {
  position: fixed;
  top: 0;
  right: -480px;
  width: 480px;
  height: 100vh;
  background: var(--bg-card);
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  z-index: 6000;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
}

.slide-panel.open { right: 0; }

.slide-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.slide-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.slide-panel-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 5999;
  display: none;
}

.backdrop.active { display: block; }

@media (max-width: 520px) {
  .slide-panel { width: 100%; right: -100%; }
}

/* --- Color picker swatch --- */
.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
}

.color-swatch::-webkit-color-swatch-wrapper { padding: 0; }
.color-swatch::-webkit-color-swatch { border: none; border-radius: 6px; }

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state i { font-size: 3rem; margin-bottom: 16px; opacity: 0.3; }
.empty-state h3 { font-size: 1.1rem; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 0.9rem; }

/* --- Loading spinner --- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

.spinner-lg { width: 36px; height: 36px; border-width: 3px; }

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

/* --- Settings Page --- */
.tab-content { min-height: 300px; }
.tab-content .card { margin-bottom: 20px; }

/* Settings tab navigation — pill style */
.settings-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
  overflow-x: auto;
  padding-bottom: 0;
  flex-wrap: nowrap;
}

.settings-tab {
  padding: 10px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all 0.2s;
  border-radius: 8px 8px 0 0;
}

.settings-tab:hover {
  color: var(--primary) !important;
  background: var(--primary-light);
}

.settings-tab.active {
  color: var(--primary) !important;
  border-bottom-color: var(--primary);
  background: var(--primary-light);
}

.settings-tab i {
  margin-right: 6px;
}

/* Settings forms — consistent spacing */
.tab-content .form-row {
  margin-bottom: 0;
}

.tab-content .form-group {
  margin-bottom: 16px;
}

.tab-content hr {
  margin: 20px 0;
  border: none;
  border-top: 1px solid var(--border);
}

.tab-content h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--primary);
}

/* Users table permission matrix */
.permission-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.permission-matrix th,
.permission-matrix td {
  padding: 8px 10px;
  border: 1px solid var(--border);
  text-align: center;
}

.permission-matrix th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.permission-matrix td:first-child {
  font-weight: 600;
  text-align: left;
}

.permission-matrix input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Appearance tab — two columns, responsive */
.appearance-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .appearance-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 767px) {
  .settings-tabs {
    gap: 0;
  }
  .settings-tab {
    padding: 8px 12px;
    font-size: 0.8rem;
  }
  .settings-tab i {
    display: none;
  }
}
