/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent:       #4F6EF7;
  --accent-hover: #3B57D9;
  --bg:           #F4F6FA;
  --surface:      #FFFFFF;
  --border:       #E2E8F0;
  --text:         #1A202C;
  --text-sub:     #718096;
  --success:      #38A169;
  --danger:       #E53E3E;
  --warn:         #D69E2E;
  --sidebar-w:    220px;
  --radius:       10px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ── Login ────────────────────────────────────────────────── */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
}
.login-box {
  background: var(--surface); border-radius: var(--radius);
  padding: 2.5rem; width: 340px; box-shadow: 0 4px 24px rgba(0,0,0,.1);
  display: flex; flex-direction: column; gap: 1rem;
}
.login-logo {
  display: flex; align-items: center; gap: .75rem;
  font-size: 1.2rem; font-weight: 700; margin-bottom: .5rem;
}
.login-box input {
  border: 1px solid var(--border); border-radius: 8px;
  padding: .65rem 1rem; font-size: .95rem; outline: none;
  transition: border-color .15s;
}
.login-box input:focus { border-color: var(--accent); }
.error-msg { color: var(--danger); font-size: .85rem; text-align: center; }

/* ── Layout ───────────────────────────────────────────────── */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); background: var(--surface);
  border-right: 1px solid var(--border); display: flex;
  flex-direction: column; position: fixed; top: 0; left: 0;
  height: 100vh; z-index: 100; transition: transform .25s ease;
}
.sidebar-logo {
  padding: 1.25rem 1.2rem; display: flex; align-items: center;
  gap: .6rem; font-weight: 700; font-size: 1rem; border-bottom: 1px solid var(--border);
}
.nav-links { flex: 1; padding: .75rem 0; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: .65rem;
  padding: .6rem 1.2rem; color: var(--text-sub); text-decoration: none;
  border-radius: 8px; margin: 0 .5rem; font-size: .9rem; transition: all .15s;
}
.nav-link svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: #EEF1FF; color: var(--accent); }
.sidebar-footer { padding: .75rem .5rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: .25rem; }
.nav-username { font-size: .8rem; color: var(--text-sub); padding: .25rem .75rem; }
.logout-btn {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .75rem; font-size: .85rem; color: var(--text-sub);
  border: none; background: none; cursor: pointer; border-radius: 8px;
  transition: all .15s;
}
.logout-btn:hover { background: #FFF5F5; color: var(--danger); }

.main-content {
  margin-left: var(--sidebar-w); flex: 1; padding: 2rem;
  max-width: calc(100vw - var(--sidebar-w));
}

.menu-toggle {
  display: none; position: fixed; top: 1rem; right: 1rem;
  z-index: 200; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem; cursor: pointer;
}
.menu-toggle svg { width: 22px; height: 22px; stroke: var(--text); fill: none; stroke-width: 2; stroke-linecap: round; display: block; }

/* ── Page ─────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; }
.header-actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.term-selector { display: flex; align-items: center; gap: .5rem; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: .55rem 1.1rem; font-size: .9rem; cursor: pointer; font-weight: 500;
  transition: background .15s; white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem 1rem; font-size: .9rem; cursor: pointer;
  font-weight: 500; text-decoration: none; display: inline-block; transition: all .15s;
  white-space: nowrap;
}
.btn-secondary:hover { background: var(--bg); }
.btn-ghost {
  background: none; border: none; cursor: pointer; font-size: .9rem;
  color: var(--text-sub); padding: .4rem .6rem;
}
.btn-sm { font-size: .8rem; padding: .35rem .7rem; }
.btn-danger {
  background: #FFF5F5; color: var(--danger); border: 1px solid #FEB2B2;
  border-radius: 8px; padding: .35rem .75rem; font-size: .85rem;
  cursor: pointer; transition: all .15s;
}
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-icon {
  background: none; border: none; cursor: pointer; color: var(--text-sub);
  padding: .25rem; border-radius: 6px; transition: all .15s; line-height: 1;
}
.btn-icon:hover { color: var(--accent); background: var(--bg); }
.btn-icon svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Inputs / Selects ─────────────────────────────────────── */
input[type="text"], input[type="email"], input[type="tel"],
input[type="date"], input[type="password"], input[type="search"],
select, textarea {
  border: 1px solid var(--border); border-radius: 8px;
  padding: .55rem .85rem; font-size: .9rem; outline: none;
  background: var(--surface); color: var(--text); transition: border-color .15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select { cursor: pointer; }
.search-input { min-width: 180px; }

/* ── Card ─────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow); margin-bottom: 1.25rem;
}
.card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }
.card-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.card-header-row h3 { margin-bottom: 0; }

/* ── Stats ────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .8rem; color: var(--text-sub); margin-top: .25rem; }
.stat-card.accent .stat-value { color: var(--accent); }
.stat-card.green .stat-value { color: var(--success); }
.stat-card.warn .stat-value { color: var(--warn); }

/* ── Tables ───────────────────────────────────────────────── */
.data-table {
  width: 100%; border-collapse: collapse; font-size: .875rem;
}
.data-table th {
  text-align: left; padding: .6rem .75rem; font-weight: 600;
  color: var(--text-sub); border-bottom: 1px solid var(--border);
  font-size: .8rem; text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap;
}
.data-table td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #FAFBFF; }

/* ── Compact list ─────────────────────────────────────────── */
.compact-list { display: flex; flex-direction: column; gap: .5rem; font-size: .875rem; }
.compact-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: .5rem .6rem; border-radius: 6px; background: var(--bg);
}
.compact-item .ci-label { font-weight: 500; }
.compact-item .ci-value { color: var(--text-sub); font-size: .8rem; }
.progress-bar-wrap { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 4px; min-width: 80px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 3px; }

/* ── Attendance List ──────────────────────────────────────── */
.att-selector-card label { font-weight: 600; display: block; margin-bottom: .6rem; }
.att-event-filters { display: flex; gap: .75rem; flex-wrap: wrap; }
.att-event-filters select { flex: 1; min-width: 140px; }
.att-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.att-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
#att-search-wrap { margin-bottom: 1rem; }
#att-search { width: 100%; }
.att-list { display: flex; flex-direction: column; gap: .4rem; max-height: 60vh; overflow-y: auto; }
.att-row {
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem .8rem; border-radius: 8px; border: 1px solid var(--border);
  cursor: pointer; transition: all .15s; user-select: none;
}
.att-row:hover { border-color: var(--accent); background: #F7F9FF; }
.att-row.present { background: #F0FFF4; border-color: #9AE6B4; }
.att-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.att-row .att-name { font-weight: 500; flex: 1; }
.att-row .att-inactive { font-size: .75rem; color: var(--text-sub); margin-left: .5rem; }
.att-row input[type="text"] { width: 180px; padding: .3rem .5rem; font-size: .8rem; }

/* ── Dashboard grid ───────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: .2rem .5rem; border-radius: 20px;
  font-size: .75rem; font-weight: 600;
}
.badge-green { background: #C6F6D5; color: #276749; }
.badge-gray  { background: #EDF2F7; color: #4A5568; }
.badge-warn  { background: #FEFCBF; color: #744210; }

/* ── Form ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: .35rem; font-size: .875rem; }
.form-control { width: 100%; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.msg { margin-top: .75rem; font-size: .875rem; }
.msg.success { color: var(--success); }
.msg.error   { color: var(--danger); }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 500; display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 540px; box-shadow: 0 20px 60px rgba(0,0,0,.2);
  display: flex; flex-direction: column; max-height: 90vh;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.1rem; }
.modal-close {
  background: none; border: none; font-size: 1.5rem; cursor: pointer;
  color: var(--text-sub); line-height: 1; padding: .25rem;
}
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: .75rem;
  padding: 1rem 1.5rem; border-top: 1px solid var(--border);
}

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 1000;
  background: var(--text); color: #fff; padding: .75rem 1.25rem;
  border-radius: 8px; font-size: .9rem; box-shadow: 0 4px 16px rgba(0,0,0,.2);
  animation: fadeInUp .2s ease; max-width: 340px;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Misc ─────────────────────────────────────────────────── */
.sub-text { color: var(--text-sub); font-size: .875rem; }
.empty-state { color: var(--text-sub); text-align: center; padding: 2rem; font-size: .95rem; }
.action-btns { display: flex; gap: .35rem; }
.rate-bar { display: flex; align-items: center; gap: .5rem; }
.rate-label { min-width: 36px; font-size: .8rem; color: var(--text-sub); text-align: right; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,.15);
  }
  .main-content {
    margin-left: 0; padding: 1rem; padding-top: 4rem;
    max-width: 100vw;
  }
  .menu-toggle { display: flex; }
  .dash-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .header-actions { width: 100%; }
  .data-table { font-size: .8rem; }
  .att-row input[type="text"] { width: 100px; }
  .sidebar-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 99;
    display: none;
  }
  .sidebar-overlay.show { display: block; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .att-event-filters { flex-direction: column; }
  .att-actions { justify-content: flex-end; }
}

/* ── Attendance status row colours ───────────────────────────────────────────*/
.att-row.present       { background: #F0FFF4; border-color: #9AE6B4; }
.att-row.communicated  { background: #EBF8FF; border-color: #90CDF4; }
.att-row.on-leave      { background: #FFFFF0; border-color: #F6E05E; }
.att-row.no-show       { background: #FFF5F5; border-color: #FEB2B2; }

/* ── Attendance status dropdown ──────────────────────────────────────────────*/
.att-status-select {
  font-size: .8rem;
  padding: .3rem .4rem;
  min-width: 170px;
  border-radius: 6px;
}

@media (max-width: 600px) {
  .att-status-select { min-width: 120px; font-size: .75rem; }
  .att-row { flex-wrap: wrap; gap: .4rem; }
}

/* ── New attendance row states ───────────────────────────────────────────────*/
.att-row.incomplete-modules { background: #FFFAF0; border-color: #F6AD55; }
.att-row.member-inactive    { background: #F7FAFC; border-color: #CBD5E0; opacity: .65; }

/* ── At-risk dashboard card ──────────────────────────────────────────────────*/
.atrisk-card { border-left: 4px solid var(--warn); margin-bottom: 1.25rem; }
