:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --success: #16a34a;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --sidebar-bg: #14162b;
  --sidebar-text: #c7c9e3;
  --sidebar-active: #23264a;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 4px 16px rgba(16, 24, 40, 0.2);
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
}
.btn:hover { background: #f3f4f6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: #f3f4f6; color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- login screen ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-dark);
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}
.login-brand { text-align: center; margin-bottom: 28px; }
.brand-mark {
  width: 44px; height: 44px;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
  margin: 0 auto 12px;
}
.login-brand h1 { margin: 0; font-size: 22px; }
.login-brand p { margin: 4px 0 0; color: var(--text-muted); font-size: 13px; }

#login-form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 14px;
}
#login-form input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
#login-form input:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }

.form-error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin: 12px 0 0;
}

.login-hint {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-muted);
}
.login-hint ul { margin: 6px 0 0; padding-left: 18px; }
.login-hint code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; }

/* ---------- app shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 18px 12px;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 20px;
  color: #fff; font-weight: 700; font-size: 16px;
}
.nav-list { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-item:hover { background: var(--sidebar-active); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-footer { border-top: 1px solid #2a2c4d; padding-top: 10px; margin-top: 10px; }
.notif-btn { position: relative; width: 100%; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-chip {
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

.content { padding: 28px; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ---------- cards / stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.stat-card.warn .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}
.panel-header h3 { margin: 0; font-size: 15px; }
.panel-body { padding: 16px 20px; }
.panel-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.panel-toolbar input, .panel-toolbar select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 13px;
}

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 11px 12px; border-bottom: 1px solid #f1f2f5; vertical-align: middle; }
tbody tr:hover { background: #fafafe; }
tbody tr:last-child td { border-bottom: none; }
.table-empty { color: var(--text-muted); text-align: center; padding: 28px; font-size: 13.5px; }
.row-actions { display: flex; gap: 6px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  background: #e5e7eb;
  color: var(--text-muted);
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.notif-btn .badge { position: absolute; right: 10px; top: 8px; background: var(--danger); color: #fff; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.single { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea {
  font-weight: 400; color: var(--text);
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.field textarea { resize: vertical; min-height: 60px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.line-items { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-top: 6px; }
.line-item-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.line-item-row:last-child { margin-bottom: 0; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(17, 18, 40, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px;
  max-height: 88vh;
  display: flex; flex-direction: column;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px 22px; overflow-y: auto; }

/* ---------- drawer (notifications) ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(17, 18, 40, 0.35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 360px;
  background: var(--surface); box-shadow: var(--shadow-lg); z-index: 45;
  display: flex; flex-direction: column;
}
.drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.drawer-header h3 { margin: 0; font-size: 16px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 8px 0; }
.notif-item { padding: 12px 20px; border-bottom: 1px solid #f1f2f5; cursor: pointer; }
.notif-item:hover { background: #fafafe; }
.notif-item.unread { background: var(--primary-light); }
.notif-item .notif-msg { font-size: 13.5px; }
.notif-item .notif-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

/* ---------- toasts ---------- */
.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 99; }
.toast {
  background: var(--text); color: #fff; padding: 12px 18px; border-radius: 6px;
  font-size: 13.5px; box-shadow: var(--shadow-lg); min-width: 220px;
}
.toast.toast-success { background: var(--success); }
.toast.toast-error { background: var(--danger); }

/* ---------- misc ---------- */
.muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.03em; margin: 22px 0 10px; }
.pagination { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 14px; font-size: 13px; color: var(--text-muted); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
