:root {
  --primary: #4a6a53;
  --primary-light: #5d8567;
  --primary-dark: #3a5442;
  --primary-xlight: #eef4f0;
  --secondary: #f3b4c4;
  --secondary-dark: #e897ac;
  --secondary-light: #fde8ef;
  --sidebar-width: 260px;
  --topbar-height: 60px;
  --text-dark: #1a2b22;
  --text-muted: #6b7c72;
  --border-color: #e2e8e4;
  --bg-light: #f7f9f8;
  --white: #ffffff;
  --shadow-sm: 0 1px 3px rgba(74,106,83,.08);
  --shadow-md: 0 4px 16px rgba(74,106,83,.12);
  --radius: 10px;
  --radius-sm: 6px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-light);
  color: var(--text-dark);
  min-height: 100vh;
}

/* ─── SIDEBAR ────────────────────────────────── */
#sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--primary);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow-y: auto;
  transition: transform .3s ease;
}

.sidebar-logo {
  padding: 14px 20px 12px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-logo img {
  height: 26px;
  filter: brightness(0) invert(1);
}

.sidebar-logo-text {
  color: white;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  opacity: .85;
}

.sidebar-section {
  padding: 20px 0 8px;
  flex: 1;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: rgba(255,255,255,.45);
  padding: 0 20px 8px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-radius: 0;
  transition: all .2s;
  position: relative;
  margin: 1px 0;
}

.sidebar-item:hover {
  background: rgba(255,255,255,.08);
  color: white;
}

.sidebar-item.active {
  background: rgba(243,180,196,.18);
  color: white;
}

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

.sidebar-item .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .8;
}

.sidebar-item.active .icon { opacity: 1; }

.sidebar-badge {
  margin-left: auto;
  background: var(--secondary);
  color: var(--primary-dark);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.12);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-avatar {
  width: 36px;
  height: 36px;
  background: var(--secondary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary-dark);
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 11px;
  color: rgba(255,255,255,.5);
}

.sidebar-logout {
  color: rgba(255,255,255,.5);
  text-decoration: none;
  font-size: 18px;
  transition: color .2s;
}

.sidebar-logout:hover { color: var(--secondary); }

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

/* ─── TOPBAR ─────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--white);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--primary);
  font-size: 22px;
}

.topbar-breadcrumb {
  flex: 1;
  font-size: 14px;
  color: var(--text-muted);
}

.topbar-breadcrumb strong {
  color: var(--text-dark);
}

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

/* ─── PAGE CONTENT ───────────────────────────── */
.page-content {
  flex: 1;
  padding: 28px;
}

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

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-dark);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── CARDS ──────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

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

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dark);
}

.card-body { padding: 20px; }

/* ─── STAT CARDS ─────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: transform .2s, box-shadow .2s;
}

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

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.stat-icon.green  { background: var(--primary-xlight); color: var(--primary); }
.stat-icon.pink   { background: var(--secondary-light); color: #c0637d; }
.stat-icon.blue   { background: #e8f0fe; color: #3b6fd8; }
.stat-icon.orange { background: #fff4e5; color: #e07d10; }
.stat-icon.purple { background: #f3e8ff; color: #7c3aed; }
.stat-icon.teal   { background: #e0f7f5; color: #0d9488; }
.stat-icon.red    { background: #fee2e2; color: #dc2626; }

.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-dark);
  line-height: 1;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── ALERTS / FLASH ─────────────────────────── */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.flash.success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.flash.error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

/* ─── BUTTONS ────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all .2s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  color: white;
}

.btn-secondary {
  background: var(--secondary);
  color: var(--primary-dark);
}

.btn-secondary:hover {
  background: var(--secondary-dark);
  color: var(--primary-dark);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary);
  color: white;
}

.btn-danger {
  background: #dc2626;
  color: white;
}

.btn-danger:hover { background: #b91c1c; color: white; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border-color);
}

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

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  justify-content: center;
  border-radius: var(--radius-sm);
}

/* ─── TABLES ─────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  background: var(--primary-xlight);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  padding: 12px 16px;
  text-align: left;
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border-color);
  transition: background .15s;
}

tbody tr:last-child { border-bottom: none; }

tbody tr:hover { background: var(--primary-xlight); }

td {
  padding: 12px 16px;
  vertical-align: middle;
}

.table-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ─── BADGES ─────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green  { background: #d1fae5; color: #065f46; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-orange { background: #ffedd5; color: #92400e; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }
.badge-gray   { background: #f3f4f6; color: #374151; }
.badge-pink   { background: var(--secondary-light); color: #9d174d; }

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

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-dark);
  background: var(--white);
  transition: border-color .2s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74,106,83,.12);
}

textarea { resize: vertical; min-height: 90px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  cursor: pointer;
}

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

/* ─── MODAL ──────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

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

.modal {
  background: var(--white);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  animation: modalIn .25s ease;
}

.modal-lg { max-width: 760px; }
.modal-xl { max-width: 960px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-dark);
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all .2s;
}

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

.modal-body { padding: 20px 24px; }

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ─── PERMISSIONS MATRIX ─────────────────────── */
.perm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.perm-table th, .perm-table td { padding: 7px 10px; text-align: center; border-bottom: 1px solid var(--border-color); }
.perm-table th:first-child, .perm-table td:first-child { text-align: left; }
.perm-table thead th { background: var(--primary-xlight); color: var(--primary-dark); font-size: 11px; font-weight: 700; }
.perm-table input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--primary); }

/* ─── SCORE BARS ─────────────────────────────── */
.score-bar-wrap { display: flex; align-items: center; gap: 8px; }
.score-bar { flex: 1; height: 6px; background: var(--border-color); border-radius: 10px; overflow: hidden; }
.score-bar-fill { height: 100%; border-radius: 10px; transition: width .6s ease; }
.score-val { font-size: 12px; font-weight: 700; min-width: 32px; text-align: right; }

/* ─── PAGINATION ─────────────────────────────── */
.pagination {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-dark);
  border: 1.5px solid var(--border-color);
  transition: all .2s;
}

.page-link:hover { background: var(--primary-xlight); border-color: var(--primary); color: var(--primary); }
.page-link.active { background: var(--primary); border-color: var(--primary); color: white; }
.page-link.disabled { opacity: .4; pointer-events: none; }

/* ─── SEARCH BAR ─────────────────────────────── */
.search-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-input-wrap {
  position: relative;
  flex: 1;
  max-width: 320px;
}

.search-input-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input-wrap input {
  padding-left: 34px;
}

/* ─── TABS ───────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 20px;
}

.tab-btn {
  background: none;
  border: none;
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .2s;
}

.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── DIAGNOSTIC CARD ────────────────────────── */
.diag-card {
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.diag-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.diag-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-dark);
}

.diag-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.diag-scores {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.diag-score-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.diag-score-name {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ─── USER INFO CARD ─────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.info-item label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.info-item .value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-dark);
}

/* ─── EMPTY STATE ────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ─── UTILITY GRIDS ─────────────────────────── */
.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.grid-1-2 {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 20px;
  align-items: start;
}

.grid-3col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

/* ─── RESPONSIVE ─────────────────────────────── */

/* Tablet */
@media (max-width: 1024px) {
  :root { --sidebar-width: 220px; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .page-content { padding: 20px; }
  .topbar { padding: 0 20px; }
}

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

  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  #main { margin-left: 0; }

  .topbar-toggle { display: block; }
  .topbar { padding: 0 14px; }
  .topbar-actions { display: none; }

  .page-content { padding: 14px; }
  .page-header { flex-direction: column; align-items: flex-start; }

  .form-row { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }

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

  .modal {
    max-width: 100%;
    max-height: 85vh;
    border-radius: var(--radius) var(--radius) 0 0;
    margin: 0;
  }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-lg { max-width: 100%; }

  .search-input-wrap { max-width: 100%; }
  .search-bar { flex-wrap: wrap; }

  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab-btn { white-space: nowrap; font-size: 13px; padding: 9px 14px; }

  .sidebar-logo-text { display: none; }

  .card-header { padding: 12px 16px; }
  .card-body { padding: 14px 16px; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; }
  .modal-header { padding: 16px; }

  thead th, td { padding: 10px 12px; }
}

/* Small mobile */
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .grid-3col { grid-template-columns: 1fr; }
  .page-title { font-size: 18px; }
  .stat-value { font-size: 22px; }
  .topbar-breadcrumb { font-size: 12px; }
}

/* ─── SCROLLBAR ──────────────────────────────── */
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 4px; }

/* ─── LOGIN PAGE ─────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, #7aaa87 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: white;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 80px rgba(0,0,0,.25);
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.login-logo img { height: 48px; }

.login-title {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 6px;
}

.login-sub {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

/* ─── TRANSITION ─────────────────────────────── */
.fade-in { animation: fadeIn .3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── OVERLAY CLOSE ──────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 999;
}

.sidebar-overlay.open { display: block; }
