/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-5); font-family: var(--font-sans);
  font-size: var(--text-sm); font-weight: 600; border-radius: var(--radius-md);
  cursor: pointer; transition: all var(--transition-fast); border: 1px solid transparent;
  white-space: nowrap; user-select: none; line-height: 1.2;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--gradient-brand); color: white; border-color: transparent;
  box-shadow: var(--shadow-brand);
}
.btn-primary:hover { box-shadow: var(--shadow-glow); transform: translateY(-1px); }
.btn-secondary {
  background: var(--glass-bg); color: var(--text-primary);
  border-color: var(--border-default);
}
.btn-secondary:hover { background: var(--bg-card-hover); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn-ghost:hover { background: var(--glass-bg); color: var(--text-primary); }
.btn-danger { background: rgba(244,63,94,0.12); color: var(--accent-rose); border-color: rgba(244,63,94,0.25); }
.btn-danger:hover { background: rgba(244,63,94,0.22); }
.btn-success { background: rgba(16,185,129,0.12); color: var(--accent-emerald); border-color: rgba(16,185,129,0.25); }
.btn-success:hover { background: rgba(16,185,129,0.22); }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: var(--radius-sm); }
.btn-lg { padding: var(--space-3) var(--space-8); font-size: var(--text-base); }
.btn-icon { padding: var(--space-2); min-width: 36px; height: 36px; }
.btn span, .btn i { display: inline-flex; align-items: center; justify-content: center; }

/* Light theme button overrides */
:root.theme-light .btn-secondary { background: #f8fafc; border-color: rgba(0,0,0,0.12); color: var(--text-primary); }
:root.theme-light .btn-secondary:hover { background: #f1f5f9; border-color: rgba(0,0,0,0.2); }
:root.theme-light .btn-ghost:hover { background: rgba(0,0,0,0.05); }

/* ============ CARDS ============ */
.card {
  background: var(--bg-card); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: var(--space-6);
  transition: all var(--transition-base);
}
.card:hover { border-color: var(--border-default); }
:root.theme-light .card { box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
:root.theme-light .card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.card-glass {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  backdrop-filter: var(--glass-blur); border-radius: var(--radius-lg); padding: var(--space-6);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-5); padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.card-title { font-size: var(--text-base); font-weight: 700; color: var(--text-primary); }
.card-subtitle { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }

/* ============ STAT CARDS ============ */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-5); margin-bottom: var(--space-8); }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: var(--space-5);
  position: relative; overflow: hidden; cursor: default;
  transition: all var(--transition-base);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-default); }
:root.theme-light .stat-card { box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.stat-card-glow {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  background: radial-gradient(circle at top right, rgba(255,255,255,0.15), transparent 70%);
  opacity: 0.5;
}
.stat-card-icon {
  width: 44px; height: 44px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; margin-bottom: var(--space-4); position: relative;
  line-height: 1;
}
.stat-card-value { font-size: var(--text-3xl); font-weight: 800; color: var(--text-primary); margin-bottom: var(--space-1); }
.stat-card-label { font-size: var(--text-sm); color: var(--text-muted); margin-bottom: var(--space-3); }
.stat-card-trend { display: flex; align-items: center; gap: var(--space-1); font-size: var(--text-xs); font-weight: 600; }
.trend-up { color: var(--accent-emerald); }
.trend-down { color: var(--accent-rose); }

/* ============ BADGES ============ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
}
.badge-brand   { background: rgba(99,102,241,0.12);  color: #818cf8; }
.badge-success { background: rgba(16,185,129,0.12);  color: var(--accent-emerald); }
.badge-warning { background: rgba(245,158,11,0.12);  color: var(--accent-amber); }
.badge-danger  { background: rgba(244,63,94,0.12);   color: var(--accent-rose); }
.badge-info    { background: rgba(14,165,233,0.12);  color: var(--accent-sky); }
.badge-muted   { background: var(--glass-bg);        color: var(--text-muted); border: 1px solid var(--border-subtle); }
.badge-purple  { background: rgba(139,92,246,0.12);  color: var(--accent-violet); }
.badge-dot::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ============ DROPDOWNS ============ */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 180px; background: var(--bg-elevated);
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); z-index: var(--z-dropdown);
  overflow: hidden; animation: dropdownIn 0.15s ease;
}
.dropdown-menu.hidden { display: none; }
@keyframes dropdownIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.dropdown-item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4); font-size: var(--text-sm);
  color: var(--text-secondary); cursor: pointer; transition: all var(--transition-fast);
}
.dropdown-item:hover { background: var(--glass-bg); color: var(--text-primary); }
.dropdown-item.danger { color: var(--accent-rose); }
.dropdown-item.danger:hover { background: rgba(244,63,94,0.08); }
.dropdown-sep { height: 1px; background: var(--border-subtle); margin: 4px 0; }

/* ============ MODALS ============ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(6px);
  z-index: var(--z-modal); display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
}
:root.theme-light .modal-backdrop { background: rgba(0,0,0,0.4); }
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--bg-elevated); border: 1px solid var(--border-default);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-xl);
  width: 100%; max-width: 580px; max-height: 90vh;
  display: flex; flex-direction: column;
  animation: modalIn 0.2s var(--transition-spring);
}
:root.theme-light .modal { box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.modal-lg { max-width: 780px; }
.modal-xl { max-width: 960px; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.94) translateY(12px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-5) var(--space-6); border-bottom: 1px solid var(--border-subtle); flex-shrink: 0;
}
.modal-title { font-size: var(--text-lg); font-weight: 700; color: var(--text-primary); }
.modal-body { flex: 1; overflow-y: auto; padding: var(--space-6); }
.modal-footer {
  display: flex; justify-content: flex-end; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-4) var(--space-6); border-top: 1px solid var(--border-subtle); flex-shrink: 0;
}

/* ============ TOASTS ============ */
.toast-container {
  position: fixed; bottom: var(--space-6); right: var(--space-6);
  z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--space-3);
  max-width: 380px;
}
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border-default);
  border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-lg); display: flex; align-items: flex-start; gap: var(--space-3);
  animation: toastIn 0.3s var(--transition-spring);
}
:root.theme-light .toast { box-shadow: 0 8px 24px rgba(0,0,0,0.12); }
@keyframes toastIn { from { opacity: 0; transform: translateX(60px); } to { opacity: 1; transform: translateX(0); } }
.toast-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.toast-body { flex: 1; }
.toast-title { font-size: var(--text-sm); font-weight: 700; margin-bottom: 2px; color: var(--text-primary); }
.toast-msg { font-size: var(--text-xs); color: var(--text-muted); }
.toast-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 18px; padding: 0; flex-shrink: 0; }
.toast-success { border-left: 3px solid var(--accent-emerald); }
.toast-error   { border-left: 3px solid var(--accent-rose); }
.toast-warning { border-left: 3px solid var(--accent-amber); }
.toast-info    { border-left: 3px solid var(--accent-sky); }

/* ============ TABS ============ */
.tabs { display: flex; gap: 2px; background: var(--bg-input); border-radius: var(--radius-md); padding: 4px; margin-bottom: var(--space-6); width: fit-content; }
.tab {
  padding: var(--space-2) var(--space-5); border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-weight: 500; cursor: pointer; color: var(--text-muted);
  transition: all var(--transition-fast); white-space: nowrap;
}
.tab.active { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }
.tab:hover:not(.active) { color: var(--text-secondary); }

/* ============ ROLE PILLS ============ */
.role-super-admin { background: linear-gradient(135deg, rgba(99,102,241,0.18), rgba(139,92,246,0.18)); color: #a78bfa; border: 1px solid rgba(139,92,246,0.28); }
.role-admin       { background: rgba(6,182,212,0.12);   color: var(--accent-cyan);    border: 1px solid rgba(6,182,212,0.28); }
.role-manager     { background: rgba(16,185,129,0.12);  color: var(--accent-emerald); border: 1px solid rgba(16,185,129,0.28); }
.role-staff       { background: rgba(245,158,11,0.12);  color: var(--accent-amber);   border: 1px solid rgba(245,158,11,0.28); }
.role-employee    { background: var(--glass-bg);        color: var(--text-secondary); border: 1px solid var(--border-default); }

/* ============ COMMAND PALETTE ============ */
.palette-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65); backdrop-filter: blur(10px);
  z-index: 9000; display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
  animation: paletteOverlayIn 0.15s ease;
}
:root.theme-light .palette-overlay { background: rgba(0,0,0,0.35); }
@keyframes paletteOverlayIn { from { opacity: 0; } to { opacity: 1; } }
.palette-overlay.palette-closing { animation: paletteOverlayOut 0.12s ease forwards; }
@keyframes paletteOverlayOut  { from { opacity: 1; } to { opacity: 0; } }

.palette-container {
  width: 100%; max-width: 660px; 
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl); 
  box-shadow: 0 32px 64px -12px rgba(0,0,0,0.7), 0 0 0 1px var(--border-subtle);
  overflow: hidden;
  animation: paletteIn 0.18s var(--transition-spring);
}
:root.theme-light .palette-container { box-shadow: 0 24px 48px rgba(0,0,0,0.18); }
@keyframes paletteIn { from { opacity: 0; transform: scale(0.96) translateY(-8px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.palette-search {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; background: var(--bg-elevated); z-index: 2;
}
.palette-search-icon { color: var(--text-muted); flex-shrink: 0; display: flex; align-items: center; }
.palette-input {
  flex: 1; background: none; border: none;
  font-family: var(--font-sans); font-size: 17px; font-weight: 500;
  color: var(--text-primary); outline: none; caret-color: var(--accent-emerald);
  min-width: 0;
}
.palette-input::placeholder { color: var(--text-disabled); font-weight: 400; }
.palette-search-kb {
  background: var(--bg-input); border: 1px solid var(--border-default);
  padding: 3px 7px; border-radius: 5px; font-size: 10px; font-weight: 700;
  color: var(--text-muted); flex-shrink: 0; letter-spacing: 0.03em;
}

.palette-results {
  max-height: 420px; overflow-y: auto; padding: 6px;
  scrollbar-width: thin; scrollbar-color: var(--border-default) transparent;
}
.palette-results::-webkit-scrollbar { width: 4px; }
.palette-results::-webkit-scrollbar-track { background: transparent; }
.palette-results::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 4px; }

.palette-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-md);
  cursor: pointer; transition: background 0.08s;
  margin-bottom: 2px;
}
.palette-item:hover, .palette-item.active {
  background: var(--glass-bg);
  outline: 1px solid var(--border-default);
}
.palette-item.active { background: rgba(255,255,255,0.06); }
:root.theme-light .palette-item.active { background: rgba(0,0,0,0.05); }
:root.theme-classic .palette-item.active { background: rgba(99,102,241,0.14); }

.palette-insight {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: var(--radius-md);
  opacity: 0.75; cursor: default; margin-bottom: 2px;
}

.palette-item-icon {
  width: 36px; height: 36px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}

.palette-item-info { flex: 1; min-width: 0; }
.palette-item-label {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.palette-item-label mark { background: rgba(255,255,255,0.18); color: var(--text-primary); border-radius: 2px; padding: 0 1px; }
:root.theme-light .palette-item-label mark { background: rgba(15,23,42,0.12); }
:root.theme-classic .palette-item-label mark { background: rgba(99,102,241,0.25); }
.palette-item-sub {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.palette-item-type {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  padding: 2px 7px; border-radius: 4px; flex-shrink: 0; letter-spacing: 0.04em;
}

.palette-footer {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  font-size: 11px; color: var(--text-muted);
}
.palette-footer b { color: var(--text-secondary); font-weight: 700; }

.palette-divider {
  padding: 10px 12px 5px; font-size: 10px; font-weight: 800; text-transform: uppercase;
  color: var(--text-disabled); letter-spacing: 0.06em;
  margin-top: 4px;
}

/* ============ SIDEBAR WIDGETS ============ */
.sidebar-widget {
  margin: var(--space-4) var(--space-3); padding: var(--space-4);
  background: var(--glass-bg); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}
.widget-label { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; letter-spacing: 0.06em; }
.health-bar { height: 5px; background: var(--border-subtle); border-radius: 3px; overflow: hidden; margin-bottom: 8px; }
.health-bar-fill { height: 100%; transition: width 1s var(--transition-spring); border-radius: 3px; }
.health-val { font-size: 11px; color: var(--text-muted); display: flex; justify-content: space-between; }

/* ============ FLOATING ACTION BUTTON ============ */
.fab {
  position: fixed; bottom: var(--space-8); right: var(--space-8);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--gradient-brand); color: white;
  border: none; box-shadow: var(--shadow-xl);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: var(--z-dropdown);
  transition: all var(--transition-base);
}
.fab:hover { transform: scale(1.08) rotate(4deg); box-shadow: var(--shadow-glow); }
.fab:active { transform: scale(0.95); }

/* ============ TOPBAR SEARCH (inline) ============ */
.topbar-search-wrapper {
  position: relative; display: flex; align-items: center;
}
.topbar-search-input {
  background: var(--bg-input); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); padding: 8px 12px 8px 36px;
  font-size: var(--text-sm); color: var(--text-primary);
  font-family: var(--font-sans); outline: none; width: 220px;
  transition: all var(--transition-fast); caret-color: var(--accent-emerald);
}
.topbar-search-input::placeholder { color: var(--text-disabled); }
.topbar-search-input:focus {
  border-color: var(--border-strong); width: 280px;
  background: var(--bg-elevated); box-shadow: 0 0 0 2px rgba(255,255,255,0.05);
}
:root.theme-light .topbar-search-input:focus { box-shadow: 0 0 0 2px rgba(15,23,42,0.08); }
:root.theme-classic .topbar-search-input:focus { box-shadow: 0 0 0 2px rgba(99,102,241,0.2); }
.topbar-search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); display: flex; align-items: center; pointer-events: none;
}
.topbar-search-kb-hint {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: 4px; padding: 1px 5px; font-size: 10px; font-weight: 700;
  color: var(--text-muted); pointer-events: none; letter-spacing: 0.02em;
}

/* ============ FORM INPUTS (global) ============ */
.form-control {
  width: 100%; padding: var(--space-3) var(--space-4);
  background: var(--bg-input); border: 1px solid var(--border-default);
  border-radius: var(--radius-md); font-family: var(--font-sans);
  font-size: var(--text-sm); color: var(--text-primary);
  outline: none; transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  caret-color: var(--accent-emerald);
}
.form-control::placeholder { color: var(--text-disabled); }
.form-control:focus {
  border-color: var(--border-brand);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.05);
}
:root.theme-light .form-control:focus { box-shadow: 0 0 0 2px rgba(15,23,42,0.08); }
:root.theme-classic .form-control:focus {
  border-color: var(--border-brand);
  box-shadow: 0 0 0 2px rgba(99,102,241,0.18);
}
.form-control:read-only { opacity: 0.65; cursor: not-allowed; }
select.form-control { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
select.form-control option { background: var(--bg-elevated); color: var(--text-primary); }
.form-group { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-5); }
.form-label { font-size: var(--text-sm); font-weight: 600; color: var(--text-secondary); }
.form-label .req { color: var(--accent-rose); margin-left: 2px; }
.form-hint { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
textarea.form-control { resize: vertical; min-height: 100px; }

/* ============ VIEW MODE TOGGLE ============ */
.view-mode-toggle {
  display: flex; align-items: center; gap: 2px;
  background: var(--bg-input); border: 1px solid var(--border-default);
  border-radius: var(--radius-md); padding: 3px;
}
.view-mode-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 28px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted); cursor: pointer;
  transition: all var(--transition-fast);
}
.view-mode-btn:hover { background: var(--glass-bg); color: var(--text-primary); }
.view-mode-btn.active {
  background: var(--bg-elevated); color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* ============ ROLE MANAGER PAGE ============ */
.role-list-item:hover { background: var(--glass-bg); }
.role-list-item { transition: background var(--transition-fast), border-color var(--transition-fast); }
.role-list-item.active { background: var(--glass-bg); }

/* Permission matrix table */
.perm-matrix table tr:hover { background: rgba(255,255,255,0.02); }
.perm-matrix table tbody tr { border-bottom: 1px solid var(--border-subtle); }
:root.theme-light .perm-matrix table tr:hover { background: rgba(0,0,0,0.02); }

/* ============ ACCENT COLORS AS VARIABLES ============ */
/* Ensure these are available in variables.css if not already present */
