:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e3e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

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

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; font-weight: 800; font-size: 15px;
  border-radius: 12px; letter-spacing: 0.5px;
}
.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.topbar-actions { display: flex; gap: 10px; align-items: center; }
.user-menu { display: flex; align-items: center; gap: 8px; padding-left: 12px; margin-left: 4px; border-left: 1px solid var(--border); }
.user-name { font-size: 13px; color: var(--muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Login screen */
.login-view { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, #eef2ff, #f4f6fb); z-index: 200; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 20px 50px rgba(16,24,40,0.15); padding: 32px; width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login-card .logo-lg { width: 60px; height: 60px; font-size: 18px; border-radius: 16px; margin: 0 auto; }
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card p { margin: 0 0 8px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; text-align: left; font-size: 13px; color: var(--muted); }
.login-card input { padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; margin-top: 4px; }
.modal-sm { max-width: 420px; }
.form-grid.one-col { grid-template-columns: 1fr; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

/* ===== Sidebar app layout ===== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 244px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 18px; border-bottom: 1px solid var(--border);
}
.sidebar-brand strong { display: block; font-size: 15px; line-height: 1.2; }
.sidebar-brand span { display: block; font-size: 12px; color: var(--muted); }

.sidebar-nav { flex: 1; padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border: none; background: none;
  border-radius: 9px; width: 100%; text-align: left;
  color: var(--text); font-size: 14px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: #f3f4f6; }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer { padding: 14px 12px; border-top: 1px solid var(--border); }
.user-info { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
  width: 36px; height: 36px; flex-shrink: 0; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff;
}
.user-meta { min-width: 0; }
.user-meta strong { display: block; font-size: 13px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer-actions { display: flex; gap: 8px; }
.sidebar-footer-actions .btn { flex: 1; }

/* Main content */
.content { flex: 1; min-width: 0; padding: 24px 32px; }
.content-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.content-head h1 { margin: 0; font-size: 24px; }
.view { width: 100%; }        /* data views fill the available width */
.view.readable { max-width: 960px; }  /* text-heavy views (docs) stay readable */

/* Card wrapper for panel-style views */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.card-narrow { max-width: 520px; }

@media (max-width: 820px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: auto; height: auto; position: static; flex-direction: column;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .sidebar-nav { flex-direction: row; overflow-x: auto; padding: 8px; }
  .nav-item { flex-direction: column; gap: 4px; font-size: 12px; padding: 8px 12px; white-space: nowrap; }
  .content { padding: 18px 16px; }
  .content-head h1 { font-size: 20px; }
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat-card .value { font-size: 28px; font-weight: 700; }
.stat-card .label { color: var(--muted); font-size: 13px; margin-top: 4px; text-transform: capitalize; }

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}
.toolbar input, .toolbar select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
}
.toolbar #search { flex: 1; min-width: 220px; }

/* Table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #f9fafb; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
tbody tr:hover { background: #fafbff; }
tbody tr:last-child td { border-bottom: none; }
.actions-col { text-align: right; }
td.actions { text-align: right; }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}
.badge.enrolled { background: #dcfce7; color: var(--success); }
.badge.graduated { background: #dbeafe; color: var(--primary); }
.badge.dropped { background: #fee2e2; color: var(--danger); }
.badge.loa { background: #fef3c7; color: var(--warning); }
.badge.transferred { background: #ede9fe; color: #7c3aed; }

/* Buttons */
.btn {
  padding: 9px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #f3f4f6; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger-outline { color: var(--danger); border-color: #f3c6c6; background: #fff; }
.btn-danger-outline:hover { background: #fef2f2; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-link { border: none; background: none; color: var(--primary); cursor: pointer; padding: 4px 8px; font-size: 13px; }
.btn-link.danger { color: var(--danger); }
.btn-link:disabled { color: var(--muted); cursor: not-allowed; opacity: 0.6; }
.icon-btn { border: none; background: none; font-size: 24px; cursor: pointer; color: var(--muted); line-height: 1; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }
.page-controls { display: flex; gap: 8px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, 0.5);
  display: grid; place-items: center;
  padding: 20px; z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%; max-width: 640px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 18px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 22px; }
.form-grid label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 5px; }
.form-grid input, .form-grid select {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; color: var(--text);
}
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.form-error { background: #fee2e2; color: var(--danger); padding: 10px 12px; border-radius: 8px; font-size: 13px; }

/* Programs modal */
.modal-body { padding: 22px; }
.prog-add-form {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--border);
}
.prog-add-form input:not([type="checkbox"]):not([type="hidden"]),
.prog-add-form select {
  height: 38px; padding: 0 11px; border: 1px solid var(--border); border-radius: 8px;
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
}
.prog-add-form select { padding-right: 8px; cursor: pointer; }
.prog-add-form input:focus, .prog-add-form select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.prog-add-form .btn { height: 38px; }
.prog-add-form #u_name, .prog-add-form #u_email, .prog-add-form #u_password { flex: 1; min-width: 180px; }
.prog-add-form #u_role { width: 140px; }
.prog-add-form #p_name { flex: 1; min-width: 180px; }
.prog-add-form #p_code { width: 120px; }
.inline-check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.inline-check input { width: 16px; height: 16px; }
.prog-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.prog-table th, .prog-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.prog-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
.prog-table td.actions { text-align: right; white-space: nowrap; }

/* Settings */
.setting-block { display: flex; flex-direction: column; gap: 10px; }
.setting-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.setting-head h3 { margin: 0 0 2px; font-size: 16px; }
.setting-head p { margin: 0; font-size: 13px; }
.small { font-size: 12.5px; line-height: 1.5; }
.pin-form { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.pin-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.pin-form input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 18px; letter-spacing: 6px; font-family: monospace;
}

/* Inline confirm dialog */
.confirm-overlay { z-index: 70; }
.confirm-card { max-width: 400px; padding: 26px 24px 20px; text-align: center; }
.confirm-body { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.confirm-icon {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: #fee2e2; color: var(--danger);
  font-size: 28px; font-weight: 800; line-height: 1;
}
.confirm-card h2 { margin: 4px 0 0; font-size: 19px; }
.confirm-card #confirmMessage { margin: 0; font-size: 14px; line-height: 1.5; }
.confirm-pin {
  display: flex; flex-direction: column; gap: 6px; margin-top: 8px;
  font-size: 13px; color: var(--muted); width: 100%; text-align: left;
}
.confirm-pin input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 18px; letter-spacing: 6px; font-family: monospace; text-align: center;
}
.confirm-actions { justify-content: center; margin-top: 18px; width: 100%; }
.confirm-actions .btn { min-width: 110px; }

/* API docs */
.docs-intro { color: var(--muted); font-size: 14px; line-height: 1.6; margin: -6px 0 16px; }
.docs-links { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 24px; }
.docs-links a { text-decoration: none; }
.docs-section { margin-bottom: 28px; }
.docs-section > h2 {
  font-size: 15px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); border-bottom: 1px solid var(--border);
  padding-bottom: 8px; margin: 0 0 14px;
}
.endpoint {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.endpoint-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.method {
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px;
  padding: 3px 8px; border-radius: 6px; color: #fff; text-transform: uppercase;
}
.method.get { background: #16a34a; }
.method.post { background: #2563eb; }
.method.put, .method.patch { background: #d97706; }
.method.delete { background: #dc2626; }
.endpoint-path { font-family: monospace; font-size: 14px; font-weight: 600; }
.endpoint-desc { color: var(--muted); font-size: 13px; margin: 8px 0 0; line-height: 1.5; }
.endpoint table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
.endpoint table th, .endpoint table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.endpoint table th { color: var(--muted); font-weight: 600; }
.endpoint table code, .endpoint-desc code, .docs-intro code { font-family: monospace; background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

.code-block { position: relative; margin: 12px 0 4px; }
.code-block pre {
  background: #0f172a; color: #e2e8f0; border-radius: 8px;
  padding: 14px 16px; overflow-x: auto; margin: 0;
  font-family: monospace; font-size: 12.5px; line-height: 1.6;
}
.code-block .copy-btn {
  position: absolute; top: 8px; right: 8px;
  background: rgba(255,255,255,0.1); color: #e2e8f0; border: none;
  border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.code-block .copy-btn:hover { background: rgba(255,255,255,0.2); }
.code-label { font-size: 12px; color: var(--muted); margin: 10px 0 2px; font-weight: 600; }

/* API keys */
.new-key-box {
  margin-top: 14px; padding: 14px 16px; border-radius: 10px;
  background: #ecfdf5; border: 1px solid #a7f3d0;
}
.new-key-box strong { display: block; font-size: 13px; color: #065f46; margin-bottom: 8px; }
.new-key-row { display: flex; gap: 10px; align-items: center; }
.new-key-row code {
  flex: 1; font-family: monospace; font-size: 13px; background: #fff;
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px;
  overflow-x: auto; white-space: nowrap;
}
.key-mono { font-family: monospace; font-size: 13px; color: var(--muted); }

/* Playground */
.playground .pg-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.playground #pg_method { padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; font-weight: 600; font-size: 13px; background: var(--surface); }
.playground #pg_path { flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-family: monospace; font-size: 13px; }
.pg-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.pg-field textarea, .pg-field input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-family: monospace; font-size: 13px; resize: vertical;
}
.pg-result { margin-top: 6px; }
.pg-status { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; font-family: monospace; font-size: 13px; }
.pg-status .ok { color: var(--success); font-weight: 700; }
.pg-status .err { color: var(--danger); font-weight: 700; }
.pg-result pre {
  background: #0f172a; color: #e2e8f0; border-radius: 8px; padding: 14px 16px;
  overflow: auto; max-height: 380px; margin: 0; font-family: monospace; font-size: 12.5px; line-height: 1.6;
}

/* Audit action badges */
.badge.act-create { background: #dcfce7; color: var(--success); }
.badge.act-update { background: #fef3c7; color: var(--warning); }
.badge.act-delete { background: #fee2e2; color: var(--danger); }
.badge.act-login, .badge.act-password_change, .badge.act-password_reset { background: #dbeafe; color: var(--primary); }
.audit-ip { font-family: monospace; font-size: 12px; color: var(--muted); }

/* Role badges + inline role select */
.badge.role-admin { background: #dbeafe; color: var(--primary); }
.badge.role-registrar { background: #dcfce7; color: var(--success); }
.badge.role-instructor { background: #ede9fe; color: #7c3aed; }
.badge.role-viewer { background: #f1f5f9; color: var(--muted); }
.role-select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; background: var(--surface); }
.status-pill { font-size: 12px; color: var(--muted); }
.status-pill.warn { color: var(--warning); font-weight: 600; }

/* Schedule form */
.sched-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.sched-form select, .sched-form input {
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: var(--surface);
}
.sched-form #sch_subject { min-width: 200px; flex: 1; }
.sched-dash { color: var(--muted); }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 12px 20px; border-radius: 8px;
  font-size: 14px; box-shadow: 0 8px 20px rgba(0,0,0,0.3); z-index: 100;
}
.toast.error { background: var(--danger); }

/* Utilities */
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
}
