:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e5eb;
  --text: #1f2430;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --warn: #ca8a04;
  --warn-bg: #fefce8;
  --sidebar-bg: #111827;
  --sidebar-text: #d1d5db;
  --sidebar-active: #1f2937;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar .brand {
  padding: 0 20px 20px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid #1f2937;
  margin-bottom: 12px;
}

.sidebar .brand small {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: #9ca3af;
  margin-top: 2px;
}

.sidebar nav a {
  display: block;
  padding: 10px 20px;
  color: var(--sidebar-text);
  font-size: 14px;
}

.sidebar nav a:hover { background: var(--sidebar-active); text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; font-weight: 600; }
.sidebar .nav-section { padding: 14px 20px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #6b7280; }

.sidebar .sidebar-footer {
  margin-top: auto;
  padding: 14px 20px 0;
  border-top: 1px solid #1f2937;
  font-size: 12px;
  color: #9ca3af;
}
.sidebar .sidebar-footer a { color: #d1d5db; }

.main { flex: 1; min-width: 0; padding: 28px 32px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
.page-header h1 { margin: 0 0 4px; font-size: 24px; }
.page-header p { margin: 0; color: var(--text-muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2, .card h3 { margin-top: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 6px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
tbody tr:hover { background: #fafbfc; }
.table-wrap { overflow-x: auto; }
.table-empty { text-align: center; padding: 30px; color: var(--text-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13.5px;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.form-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-weight: 600; font-size: 13px; }
.form-field .hint { color: var(--text-muted); font-size: 12px; }
input[type=text], input[type=email], input[type=password], input[type=search],
input[type=datetime-local], input[type=date], input[type=number], input[type=file],
select, textarea {
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }

.filters-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.filters-bar .form-field { margin-bottom: 0; min-width: 180px; }

.alert { padding: 12px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 13.5px; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: #166534; border-color: #bbf7d0; }
.alert-error { background: var(--danger-bg); color: #991b1b; border-color: #fecaca; }
.alert-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-lightgreen { background: #ecfccb; color: #3f6212; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-blue { background: #dbeafe; color: #1e40af; }

.progress-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.progress-row .name { width: 160px; flex-shrink: 0; font-size: 13px; }
.progress-track { flex: 1; height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.progress-row .count { width: 34px; text-align: right; font-weight: 600; font-size: 13px; }

.modal-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 24px; }
.modal-box h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.perm-table td, .perm-table th { text-align: center; }
.perm-table td:first-child, .perm-table th:first-child { text-align: left; }
.perm-table input[type=checkbox] { width: 18px; height: 18px; }

.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #eff6ff, #f4f6f9);
  padding: 20px;
}
.login-box { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 32px; }
.login-box .logo { text-align: center; margin-bottom: 20px; }
.login-box .logo .mark {
  width: 46px; height: 46px; border-radius: 10px; background: var(--primary);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; margin-bottom: 10px;
}
.login-box h1 { font-size: 19px; text-align: center; margin: 0 0 4px; }
.login-box p.sub { text-align: center; color: var(--text-muted); margin: 0 0 20px; font-size: 13px; }
.login-box .btn-primary { width: 100%; justify-content: center; padding: 10px; }

.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.small { font-size: 12.5px; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

hr.sep { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
