:root {
  --bg: #0f1419;
  --bg-elevated: #1a222d;
  --bg-card: #222b38;
  --border: #2d3848;
  --text: #e8edf4;
  --muted: #8b98a8;
  --primary: #2e7d32;
  --primary-hover: #388e3c;
  --danger: #c62828;
  --warn: #f9a825;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
  --sidebar-w: 260px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .875rem; }

/* Login */
.login-page {
  display: grid;
  place-items: center;
  padding: 1rem;
  background: radial-gradient(circle at top, #1b3a1f 0%, var(--bg) 55%);
}
.login-card {
  width: min(420px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 1.25rem; }
.brand-icon {
  width: 56px; height: 56px; margin: 0 auto .75rem;
  border-radius: 14px; background: var(--primary);
  display: grid; place-items: center; font-weight: 800;
}
.brand h1 { margin: 0; font-size: 1.25rem; }
.brand p { margin: .25rem 0 0; color: var(--muted); font-size: .9rem; }
.login-footer { margin-top: 1rem; text-align: center; }
.hint { font-size: .8rem; color: var(--muted); margin: .5rem 0; }

label { display: block; margin-bottom: .85rem; }
label span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .35rem; }
input, textarea, select {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: .65rem .75rem;
  font: inherit;
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
textarea { min-height: 100px; resize: vertical; }

.btn {
  border: 0; border-radius: var(--radius); padding: .6rem 1rem;
  font: inherit; cursor: pointer; font-weight: 600;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-block { width: 100%; }
.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); width: 40px; height: 40px; cursor: pointer;
}

.alert {
  padding: .75rem 1rem; border-radius: var(--radius); margin: .75rem 0;
  font-size: .9rem;
}
.alert-error { background: #3a1515; border: 1px solid var(--danger); color: #ffcdd2; }
.alert-ok { background: #1b3a1f; border: 1px solid var(--primary); color: #c8e6c9; }

/* Dashboard shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0; z-index: 20;
  transform: translateX(0);
  transition: transform .2s ease;
}
.sidebar-head { padding: 1rem; border-bottom: 1px solid var(--border); }
.module-nav { flex: 1; overflow: auto; padding: .5rem; }
.module-nav button {
  width: 100%; text-align: left; background: transparent; border: 0;
  color: var(--text); padding: .65rem .75rem; border-radius: var(--radius);
  cursor: pointer; margin-bottom: .25rem;
}
.module-nav button.active { background: var(--primary); color: #fff; }
.sidebar-foot { padding: .75rem; border-top: 1px solid var(--border); }
.user-chip { margin-bottom: .5rem; }
.user-name { display: block; font-weight: 600; }
.user-role { font-size: .8rem; color: var(--muted); }

.main-area {
  flex: 1; margin-left: var(--sidebar-w);
  padding: 1rem; max-width: 1400px;
}
.topbar {
  display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem;
}
.topbar h1 { margin: 0; font-size: 1.25rem; }
.topbar .muted { margin: 0; }
#menuToggle { display: none; }

.toolbar { display: flex; gap: .5rem; margin-bottom: .75rem; flex-wrap: wrap; align-items: center; }
.search-input { flex: 1; min-width: 180px; max-width: 420px; }

.status-filters {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
}
.status-chip {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--muted);
  border-radius: 999px;
  padding: .35rem .75rem;
  font-size: .8rem;
  cursor: pointer;
  font: inherit;
}
.status-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-passive { border-color: #8a6d00; color: #ffecb3; }
.btn-activate { border-color: var(--primary); color: #c8e6c9; }

.content { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; }

.table-wrap { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th, .data-table td { border-bottom: 1px solid var(--border); padding: .55rem .5rem; text-align: left; vertical-align: top; }
.data-table th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.row-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.row-actions button { font-size: .75rem; padding: .25rem .5rem; }

.cards { display: none; gap: .75rem; }
.record-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem;
}
.record-card.record-passive { opacity: .85; border-color: #8a6d00; }
.record-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .35rem;
}
.record-card h3 { margin: 0; font-size: 1rem; flex: 1; }
.record-card dl { margin: 0; display: grid; grid-template-columns: 110px 1fr; gap: .25rem .5rem; font-size: .8rem; }
.record-card dt { color: var(--muted); }
.meta-line { margin: .75rem 0 0; }

/* Modal */
.modal {
  border: 1px solid var(--border); border-radius: calc(var(--radius) + 2px);
  background: var(--bg-elevated); color: var(--text);
  padding: 0; max-width: 640px; width: calc(100% - 2rem);
}
.modal::backdrop { background: rgba(0,0,0,.55); }
.modal-sm { max-width: 380px; }
.modal-body { padding: 1rem; margin: 0; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; }
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.form-grid { display: grid; gap: .75rem; max-height: 60vh; overflow: auto; }
.form-grid label.checkbox { display: flex; align-items: center; gap: .5rem; }
.form-grid label.checkbox input { width: auto; }

.badge {
  display: inline-block; padding: .1rem .4rem; border-radius: 4px;
  font-size: .7rem; font-weight: 700;
}
.badge-yes { background: #1b5e20; }
.badge-no { background: #37474f; }
.badge-warn { background: #8a6d00; color: #fff8e1; }

.edit-context {
  margin-bottom: 1rem;
  padding: .75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.field-hint { margin: .35rem 0 0; font-size: .85rem; }
.field-hint strong { color: var(--text); }

.course-filter {
  min-width: 200px;
  max-width: 320px;
}
.form-grid .field-hint-box {
  margin-bottom: 1rem;
  padding: .75rem 1rem;
  background: #1b3a1f33;
  border: 1px solid #2e7d3255;
  border-radius: var(--radius);
  font-size: .85rem;
}
select[multiple] { min-height: 120px; }
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 1rem 0 .5rem;
  flex-wrap: wrap;
}
.pagination-bar.hidden { display: none; }
#pageInfo { min-width: 12rem; text-align: center; }

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; }
  #menuToggle { display: inline-grid; place-items: center; }
  .table-wrap { display: none; }
  .cards { display: grid; }
}

@media (max-width: 480px) {
  .topbar { flex-wrap: wrap; }
  #newBtn { width: 100%; }
}
