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

:root {
  --sidebar-bg: #0c1a10;
  --sidebar-width: 252px;
  --topbar-height: 58px;
  --primary: #1c7a38;
  --primary-hover: #155f2b;
  --primary-light: #25a34c;
  --primary-pale: #eaf6ee;
  --primary-border: #b8ddc4;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --text: #111827;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --danger: #dc2626;
  --radius: 10px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 4px 6px -1px rgba(0,0,0,.06), 0 2px 4px -2px rgba(0,0,0,.04);
  --shadow-lg: 0 20px 40px rgba(0,0,0,.12);
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== SIDEBAR ===== */
#sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-width); height: 100vh;
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  z-index: 100;
}

.brand {
  padding: 18px 14px 16px;
  display: flex; align-items: center; gap: 11px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  text-decoration: none;
}
.brand-avatar {
  width: 36px; height: 36px;
  background: var(--primary-light);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: white;
  flex-shrink: 0; letter-spacing: -.3px;
}
.brand-text .name {
  font-size: .82rem; font-weight: 700; color: white; line-height: 1.2;
}
.brand-text .sub { font-size: .68rem; color: rgba(255,255,255,.38); margin-top: 1px; }

#sidebar nav { flex: 1; overflow-y: auto; padding: 10px 8px; }

.nav-section {
  font-size: .62rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .1em; color: rgba(255,255,255,.25);
  padding: 14px 10px 5px; display: block;
}

#sidebar nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 11px;
  color: rgba(255,255,255,.55);
  text-decoration: none;
  font-size: .8rem; font-weight: 500;
  border-radius: 7px;
  margin-bottom: 1px;
  transition: background .14s, color .14s;
}
#sidebar nav a i { font-size: .95rem; width: 17px; text-align: center; flex-shrink: 0; }
#sidebar nav a:hover { background: rgba(255,255,255,.07); color: rgba(255,255,255,.88); }
#sidebar nav a.active { background: var(--primary); color: white; }

.user-info { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.06); }
.user-email { font-size: .73rem; font-weight: 600; color: white; word-break: break-all; }
.user-role-badge {
  display: inline-block;
  background: rgba(255,255,255,.1); color: rgba(255,255,255,.65);
  padding: 2px 8px; border-radius: 20px;
  font-size: .62rem; font-weight: 600;
  margin-top: 4px; letter-spacing: .04em; text-transform: uppercase;
}

.logout-btn {
  margin: 6px 8px 12px;
  padding: 8px 14px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  background: rgba(255,255,255,.05);
  color: rgba(255,255,255,.55);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 7px; cursor: pointer;
  font-size: .78rem; font-weight: 500; font-family: inherit;
  transition: background .14s, color .14s;
}
.logout-btn:hover { background: rgba(255,255,255,.1); color: rgba(255,255,255,.9); }

/* ===== MAIN ===== */
#main { margin-left: var(--sidebar-width); min-height: 100vh; display: flex; flex-direction: column; }

#topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 12px;
  position: sticky; top: 0; z-index: 50;
}
#topbar h1 { font-size: .95rem; font-weight: 600; color: var(--text); flex: 1; }
.topbar-badge {
  font-size: .68rem; font-weight: 600;
  background: var(--primary-pale); color: var(--primary);
  border: 1px solid var(--primary-border);
  padding: 3px 10px; border-radius: 20px; letter-spacing: .02em;
}

#content { padding: 24px; flex: 1; }

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.card-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-header h2 {
  font-size: .875rem; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.card-header h2 i { color: var(--primary); font-size: 1rem; }
.card-body { padding: 20px; }

/* ===== STAT CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 14px; margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
  display: flex; align-items: flex-start; gap: 14px;
}
.stat-icon-wrap {
  width: 42px; height: 42px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
}
.stat-icon-wrap.green  { background: #dcfce7; color: #16a34a; }
.stat-icon-wrap.blue   { background: #dbeafe; color: #1d4ed8; }
.stat-icon-wrap.orange { background: #ffedd5; color: #ea580c; }
.stat-icon-wrap.purple { background: #ede9fe; color: #7c3aed; }
.stat-icon-wrap.teal   { background: #ccfbf1; color: #0d9488; }
.stat-info { flex: 1; min-width: 0; }
.stat-label { font-size: .68rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 1.7rem; font-weight: 700; color: var(--text); line-height: 1.15; margin-top: 3px; }

/* ===== TABLE ===== */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
thead th {
  background: #f9fafb;
  color: var(--text-muted); font-weight: 600;
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 11px 16px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f9fff9; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: none;
  cursor: pointer; font-size: .8rem; font-weight: 600;
  text-decoration: none; transition: all .14s;
  letter-spacing: .01em; font-family: inherit;
}
.btn-primary   { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #f3f4f6; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e5e7eb; }
.btn-success   { background: #16a34a; color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger    { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning   { background: #d97706; color: white; }
.btn-info      { background: #0284c7; color: white; }
.btn-info:hover { background: #0369a1; }
.btn-outline   { background: transparent; border: 1.5px solid var(--border); color: var(--text-muted); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-pale); }
.btn-sm { padding: 5px 10px; font-size: .73rem; border-radius: 6px; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .77rem; font-weight: 600; color: var(--text); margin-bottom: 5px; }
.form-control {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid #d1d5db; border-radius: 8px;
  font-size: .85rem; background: white; color: var(--text);
  transition: border-color .14s, box-shadow .14s;
  font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(28,122,56,.1); }
.form-control::placeholder { color: #b0b7c3; }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; }
.form-row { display: grid; gap: 14px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity .18s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%; max-width: 580px; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 48px -12px rgba(0,0,0,.18);
  transform: translateY(14px) scale(.985);
  transition: transform .18s;
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal-header {
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: .9rem; font-weight: 700; color: var(--text); }
.modal-close {
  background: var(--border-light); border: none; width: 28px; height: 28px;
  border-radius: 6px; cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; transition: background .14s; line-height: 1;
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 20px;
  font-size: .68rem; font-weight: 700; letter-spacing: .03em;
}
.badge-success  { background: #dcfce7; color: #15803d; }
.badge-danger   { background: #fee2e2; color: #b91c1c; }
.badge-warning  { background: #fef9c3; color: #92400e; }
.badge-info     { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #f3f4f6; color: #4b5563; }

/* ===== ALERTS ===== */
.alert {
  padding: 11px 16px; border-radius: 8px;
  margin-bottom: 16px; font-size: .84rem;
  display: flex; align-items: center; gap: 10px; border: 1px solid;
}
.alert-danger  { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }

/* ===== PAGINATION ===== */
.pagination { display: flex; gap: 4px; align-items: center; margin-top: 16px; }
.pagination button {
  padding: 6px 12px; border-radius: 7px;
  border: 1.5px solid var(--border); background: white;
  cursor: pointer; font-size: .75rem; font-weight: 500;
  color: var(--text-muted); transition: all .14s; font-family: inherit;
}
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination button:hover:not(.active):not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination .pg-info { font-size: .75rem; color: var(--text-muted); margin-left: 6px; }

/* ===== SEARCH BAR ===== */
.search-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-bar input { max-width: 240px; }

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  display: grid; grid-template-columns: 1fr 440px;
}
.login-left {
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 40px; position: relative; overflow: hidden;
}
.login-left::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 30% 70%, rgba(28,122,56,.25) 0%, transparent 60%);
  pointer-events: none;
}
.login-brand { position: relative; z-index: 1; text-align: center; }
.login-brand-icon {
  width: 76px; height: 76px;
  background: var(--primary-light); border-radius: 22px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; color: white;
  margin: 0 auto 20px;
  box-shadow: 0 0 0 10px rgba(255,255,255,.06);
  letter-spacing: -.5px;
}
.login-brand h1 { font-size: 1.5rem; font-weight: 700; color: white; margin-bottom: 10px; line-height: 1.25; }
.login-brand p { font-size: .84rem; color: rgba(255,255,255,.42); max-width: 300px; line-height: 1.6; }
.login-brand-dots {
  margin-top: 40px; display: flex; gap: 8px; justify-content: center;
}
.login-brand-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255,255,255,.15);
}
.login-brand-dots span:first-child { background: var(--primary-light); }

.login-right {
  display: flex; align-items: center; justify-content: center;
  padding: 40px; background: white;
}
.login-box { width: 100%; max-width: 340px; }
.login-box h2 { font-size: 1.3rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.login-box .sub { font-size: .84rem; color: var(--text-muted); margin-bottom: 28px; }
.login-box .form-control { font-size: .88rem; padding: 10px 13px; }
.login-box .btn-primary { width: 100%; justify-content: center; padding: 11px; font-size: .875rem; border-radius: 9px; }
.login-footer { margin-top: 24px; text-align: center; font-size: .75rem; color: var(--text-light); }

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

/* ===== SPINNER ===== */
.spinner {
  display: inline-block; width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,.3); border-top-color: white;
  border-radius: 50%; animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== TOAST ===== */
#toast-container {
  position: fixed; top: 16px; right: 16px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 11px 16px; border-radius: 10px; color: white;
  font-size: .8rem; font-weight: 500;
  box-shadow: 0 4px 14px rgba(0,0,0,.14);
  animation: toastIn .22s ease;
  max-width: 320px;
  display: flex; align-items: center; gap: 9px;
}
.toast.success { background: #16a34a; }
.toast.error   { background: var(--danger); }
.toast.info    { background: #0284c7; }
@keyframes toastIn { from { opacity:0; transform: translateX(12px); } to { opacity:1; transform: translateX(0); } }

/* ===== PERMISSIONS GRID ===== */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.perm-resource { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.perm-resource .perm-title {
  background: #f9fafb; color: var(--text); font-weight: 700;
  font-size: .68rem; padding: 8px 12px; border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: .06em;
}
.perm-resource .perm-actions { padding: 10px 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.perm-check { display: flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--text); }
.perm-check input[type=checkbox] { accent-color: var(--primary); width: 14px; height: 14px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  #main { margin-left: 0; }
  .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }
  .login-page { grid-template-columns: 1fr; }
  .login-left { display: none; }
}

/* ===== UTILS ===== */
.text-muted { color: var(--text-muted); font-size: .82rem; }
.text-right { text-align: right; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.actions-col { display: flex; gap: 5px; flex-wrap: wrap; }

/* ===== VALIDATION ===== */
.form-control.is-invalid { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(220,38,38,.08); }
.field-error { color: var(--danger); font-size: .73rem; margin-top: 4px; display: block; }
.form-label { font-weight: 600; font-size: .77rem; display: block; margin-bottom: 5px; }
.form-feedback { font-size: .73rem; margin-top: 4px; color: var(--text-muted); }

/* ===== DIVIDER ===== */
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ===== TOGGLE SWITCH ===== */
.toggle-switch {
  position: relative; display: inline-block;
  width: 46px; height: 24px; cursor: pointer; flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: #d1d5db; border-radius: 24px;
  transition: background .2s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 18px; height: 18px; border-radius: 50%;
  background: white; left: 3px; top: 3px;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(22px); }

.toggle-group-row {
  display: flex; gap: 24px; align-items: center;
  padding: 14px 0 16px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 14px;
}
.toggle-item { display: flex; align-items: center; gap: 10px; }
.toggle-label { font-size: .82rem; font-weight: 600; color: var(--text); }

.toggle-readonly {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .78rem; font-weight: 600;
}
.toggle-readonly.on  { color: #16a34a; }
.toggle-readonly.off { color: #9ca3af; }

/* ===== FILTER TABS ===== */
.filter-tabs {
  display: flex; gap: 4px;
  background: var(--border-light); border-radius: 8px; padding: 3px;
}
.filter-tab {
  padding: 5px 14px; border: none; border-radius: 6px; cursor: pointer;
  font-size: .78rem; font-weight: 600; color: var(--text-muted);
  background: transparent; transition: background .14s, color .14s;
}
.filter-tab:hover { color: var(--text); }
.filter-tab.active { background: white; color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
