/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg-secondary); color: var(--text-primary); line-height: 1.5; }

/* ── CSS Variables ─────────────────────────────────────── */
:root {
  --green:        #1D9E75;
  --green-dark:   #0F6E56;
  --green-light:  #E1F5EE;
  --blue:         #185FA5;
  --blue-light:   #E6F1FB;
  --amber:        #854F0B;
  --amber-light:  #FAEEDA;
  --red:          #A32D2D;
  --red-light:    #FCEBEB;

  --bg-primary:   #ffffff;
  --bg-secondary: #f5f5f3;
  --bg-tertiary:  #eeede9;
  --border:       rgba(0,0,0,0.1);
  --border-md:    rgba(0,0,0,0.15);

  --text-primary: #1a1a18;
  --text-muted:   #6b6b68;
  --text-faint:   #9e9d9a;

  --sidebar-w:    220px;
  --topbar-h:     52px;
  --radius:       8px;
  --radius-lg:    12px;
}

/* ── Layout ────────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar-logo {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .brand { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.sidebar-logo .brand span { color: var(--green); }
.sidebar-logo small { font-size: 11px; color: var(--text-faint); }
.nav-section { padding: 10px 0 4px; }
.nav-label {
  font-size: 10px; font-weight: 600; color: var(--text-faint);
  letter-spacing: .08em; text-transform: uppercase;
  padding: 0 20px 5px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 20px; font-size: 13px; color: var(--text-muted);
  cursor: pointer; border-left: 2px solid transparent;
  transition: all .15s; text-decoration: none;
}
.nav-item:hover { background: var(--bg-secondary); color: var(--text-primary); }
.nav-item.active { background: var(--bg-secondary); color: var(--text-primary); border-left-color: var(--green); font-weight: 500; }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto; font-size: 10px; font-weight: 600;
  padding: 1px 6px; border-radius: 10px;
  background: var(--red-light); color: var(--red);
}
.nav-badge.warn { background: var(--amber-light); color: var(--amber); }
.sidebar-bottom { margin-top: auto; border-top: 1px solid var(--border); padding: 10px 0; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 8px 16px; cursor: pointer; }
.user-row:hover { background: var(--bg-secondary); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--green-light); color: var(--green-dark);
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.user-role { font-size: 11px; color: var(--text-faint); }

/* ── Main area ─────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: var(--topbar-h); background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  flex-shrink: 0;
}
.topbar-title { font-size: 15px; font-weight: 500; flex: 1; }
.topbar-search { position: relative; }
.topbar-search input {
  padding: 6px 12px 6px 32px; font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-secondary); width: 220px; outline: none;
  color: var(--text-primary);
}
.topbar-search input:focus { border-color: var(--green); background: var(--bg-primary); }
.topbar-search svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text-faint); }
.topbar-icon {
  width: 32px; height: 32px; border-radius: var(--radius);
  border: 1px solid var(--border); display: flex; align-items: center;
  justify-content: center; cursor: pointer; color: var(--text-muted);
  position: relative;
}
.topbar-icon:hover { background: var(--bg-secondary); }
.topbar-icon svg { width: 16px; height: 16px; }
.notif-dot::after {
  content: ''; width: 7px; height: 7px;
  background: #E24B4A; border-radius: 50%;
  position: absolute; top: 4px; right: 4px;
  border: 1.5px solid var(--bg-primary);
}
.content { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Pages ─────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
}
.card-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; flex: 1; }
.card-body { padding: 16px; }

/* ── Stat cards ────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--bg-secondary); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.stat-val { font-size: 22px; font-weight: 600; color: var(--text-primary); line-height: 1; }
.stat-sub { font-size: 11px; color: var(--text-faint); margin-top: 4px; }
.stat-val.danger { color: var(--red); }
.stat-val.warn   { color: var(--amber); }
.stat-val.ok     { color: var(--green); }

/* ── Tables ────────────────────────────────────────────── */
.table-wrap { background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  padding: 10px 14px; text-align: left;
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  background: var(--bg-secondary); border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text-primary); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-secondary); }
.td-name { font-weight: 500; }
.td-sub { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

/* ── Badges ────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
}
.badge-ok     { background: #EAF3DE; color: #3B6D11; }
.badge-warn   { background: var(--amber-light); color: var(--amber); }
.badge-danger { background: var(--red-light); color: var(--red); }
.badge-info   { background: var(--blue-light); color: var(--blue); }
.badge-gray   { background: var(--bg-tertiary); color: var(--text-muted); }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; font-size: 13px; font-weight: 500;
  border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-primary);
  color: var(--text-primary); transition: all .15s; text-decoration: none;
}
.btn:hover { background: var(--bg-secondary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn-primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn-danger  { background: var(--red-light); color: var(--red); border-color: #F09595; }
.btn-danger:hover { background: #F7C1C1; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Section header ────────────────────────────────────── */
.section-header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.section-title { font-size: 15px; font-weight: 600; flex: 1; }

/* ── Filter bar ────────────────────────────────────────── */
.filter-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select {
  font-size: 13px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-primary); color: var(--text-primary); outline: none;
}
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--green); }
.filter-search { position: relative; }
.filter-search svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 13px; height: 13px; color: var(--text-faint); }
.filter-search input { padding-left: 28px; min-width: 200px; }

/* ── Pagination ────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; font-size: 12px; color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.pagination-btns { display: flex; gap: 4px; }
.page-btn {
  width: 28px; height: 28px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-primary);
  font-size: 12px; cursor: pointer; display: flex;
  align-items: center; justify-content: center; color: var(--text-primary);
}
.page-btn:hover { background: var(--bg-secondary); }
.page-btn.active { background: var(--green); color: #fff; border-color: var(--green); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Forms ─────────────────────────────────────────────── */
.form-card { background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1/-1; }
.form-label { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.form-control {
  padding: 8px 10px; font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-primary); color: var(--text-primary); outline: none;
  transition: border .15s;
}
.form-control:focus { border-color: var(--green); }
.form-control.error { border-color: var(--red); }
.form-error { font-size: 11px; color: var(--red); }
textarea.form-control { min-height: 70px; resize: vertical; }

/* ── Modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-primary); border-radius: var(--radius-lg);
  width: 100%; max-width: 560px; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-lg { max-width: 720px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px; border-radius: 4px; }
.modal-close:hover { background: var(--bg-secondary); }
.modal-close svg { width: 18px; height: 18px; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 14px 20px; border-top: 1px solid var(--border);
}

/* ── Alerts ────────────────────────────────────────────── */
.alert-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius);
  font-size: 13px; margin-bottom: 8px;
  border-left: 3px solid transparent;
}
.alert-banner.danger { background: var(--red-light); border-left-color: var(--red); color: var(--red); }
.alert-banner.warn   { background: var(--amber-light); border-left-color: #EF9F27; color: var(--amber); }
.alert-banner.ok     { background: #EAF3DE; border-left-color: var(--green); color: #3B6D11; }
.alert-banner svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ── Progress bar ──────────────────────────────────────── */
.progress { background: var(--bg-tertiary); border-radius: 4px; height: 5px; overflow: hidden; width: 80px; }
.progress-bar { height: 100%; border-radius: 4px; background: var(--green); }
.progress-bar.warn   { background: #EF9F27; }
.progress-bar.danger { background: #E24B4A; }

/* ── Tabs ──────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab { padding: 8px 16px; font-size: 13px; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--green); border-bottom-color: var(--green); font-weight: 500; }

/* ── Toast ─────────────────────────────────────────────── */
.toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 16px; border-radius: var(--radius); font-size: 13px;
  font-weight: 500; color: #fff; min-width: 240px;
  animation: slideIn .2s ease;
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
.toast.warn    { background: #EF9F27; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Loading ───────────────────────────────────────────── */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--border-md); border-top-color: var(--green);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row td { text-align: center; padding: 32px; color: var(--text-faint); }
.empty-row td   { text-align: center; padding: 32px; color: var(--text-faint); }

/* ── Charts ────────────────────────────────────────────── */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.chart-wrap { position: relative; height: 200px; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  .form-grid  { grid-template-columns: 1fr; }
  .form-group.full { grid-column: 1; }
}
@media (max-width: 640px) {
  .sidebar { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
