:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef2ff;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --info: #0ea5e9;
  --bg: #f6f7fb;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }

/* ---------- Login ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #eef2ff 0%, #faf5ff 100%);
  padding: 20px;
}
.login-card {
  background: var(--card);
  width: 100%; max-width: 400px;
  padding: 36px 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.logo-badge {
  width: 60px; height: 60px; border-radius: 16px;
  background: var(--primary-light); color: var(--primary);
  font-size: 30px; display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
}
.login-logo h1 { font-size: 18px; font-weight: 700; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; font-size: 13px; }
.checkbox-row input { width: auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: all .15s; background: #fff; color: var(--text); border-color: var(--border);
}
.btn:hover { background: #f9fafb; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f3f4f6; }

.error-box { background: var(--danger-light); color: var(--danger); padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; font-size: 13px; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0;
  z-index: 30; transition: transform .2s;
}
.sidebar-header {
  padding: 20px 18px; font-weight: 800; font-size: 15px;
  display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border);
}
.sidebar-header .logo-badge { width: 34px; height: 34px; font-size: 18px; border-radius: 10px; margin: 0; }
.nav { flex: 1; overflow-y: auto; padding: 10px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px; color: var(--muted);
  cursor: pointer; font-weight: 500; margin-bottom: 2px; font-size: 13.5px;
}
.nav-item:hover { background: #f3f4f6; color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; }

.main { flex: 1; margin-left: 250px; min-width: 0; }
.topbar {
  height: 62px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.badge-online { background: var(--success-light); color: var(--success); padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; cursor: pointer; }
.content { padding: 24px; }

.menu-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; }

/* ---------- Cards ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 22px; }
.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; }
.stat-value { font-size: 26px; font-weight: 800; margin: 8px 0 6px; }
.stat-unit { display: inline-block; background: var(--primary-light); color: var(--primary-dark); padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }

.banner {
  background: linear-gradient(120deg, #eef2ff, #f5f3ff);
  border: 1px solid #e0e7ff; border-radius: var(--radius);
  padding: 20px 24px; margin-bottom: 22px; display: flex; align-items: center; gap: 16px;
}
.banner .icon { font-size: 34px; }
.banner h3 { font-size: 16px; margin-bottom: 4px; }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; padding: 11px 12px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid #f3f4f6; }
tbody tr:hover { background: #fafbff; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill-green { background: var(--success-light); color: var(--success); }
.pill-red { background: var(--danger-light); color: var(--danger); }
.pill-amber { background: var(--warning-light); color: var(--warning); }
.pill-blue { background: #dbeafe; color: #2563eb; }
.pill-gray { background: #f3f4f6; color: var(--muted); }
.pill-purple { background: #f3e8ff; color: #7c3aed; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; font-family: inherit; font-size: 13px;
}
.toolbar .spacer { flex: 1; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(17,24,39,.5); display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: var(--radius); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal .close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast { background: #fff; border-left: 4px solid var(--primary); padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow-lg); min-width: 240px; animation: slidein .2s; }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- States ---------- */
.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state .emoji { font-size: 40px; margin-bottom: 10px; }
.spinner { border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; width: 30px; height: 30px; animation: spin .7s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 18px; align-items: center; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .stat-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
.overlay-mask { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 25; display: none; }
.overlay-mask.show { display: block; }
