/* YSD Admin Panel — Dashboard / Registrations / Batches shell */

:root {
  --bg:      #f4f5f7;
  --panel:   #ffffff;
  --border:  #e2e5eb;
  --text:    #1a1d29;
  --text2:   #5b6072;
  --text3:   #9297a6;
  --brand:   #2563eb;
  --brand2:  #1d4ed8;
  --green:   #15803d;
  --amber:   #b45309;
  --red:     #b91c1c;
  --sidebar: #14172a;
  --sidebar-text: #c7cbe0;
  --radius:  10px;
}

* { 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);
  font-size: 14px;
}

a { color: inherit; text-decoration: none; }

.admin-shell { display: flex; min-height: 100vh; height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  font-size: .95rem;
  font-weight: 700;
  color: #fff;
  padding: 0 8px 18px;
}
.sidebar-brand small { display: block; font-weight: 400; color: var(--sidebar-text); font-size: .72rem; margin-top: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: .86rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 2px;
  color: var(--sidebar-text);
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-item .ic { width: 18px; text-align: center; }

/* ── Main column ─────────────────────────────────────────────────────── */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.02rem; margin: 0; font-weight: 700; }
.content { padding: 22px; flex: 1; overflow-y: auto; }
.page-section { display: none; }
.page-section.active { display: block; }

/* ── Cards / KPIs ────────────────────────────────────────────────────── */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.kpi-card .kpi-label { font-size: .74rem; color: var(--text3); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi-card .kpi-value { font-size: 1.55rem; font-weight: 800; margin-top: 4px; }
.kpi-card .kpi-sub   { font-size: .74rem; color: var(--text2); margin-top: 2px; }

.kpi-row-mini { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 0; }
.kpi-card-mini { padding: 10px 12px; }
.kpi-card-mini .kpi-label { font-size: .64rem; }
.kpi-card-mini .kpi-value { font-size: 1.15rem; margin-top: 2px; }
.kpi-card-mini .kpi-sub   { font-size: .64rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
}
.panel-title { font-size: .92rem; font-weight: 700; margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* ── Tables ──────────────────────────────────────────────────────────── */
table.data-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
table.data-table th, table.data-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
table.data-table th { font-size: .7rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text3); font-weight: 700; }
table.data-table tr:hover td { background: #fafbfd; }
table.data-table tr.row-selected td { background: #eef4ff; }

table.data-table mark { background: #fef3c7; color: var(--amber); border-radius: 3px; padding: 0 2px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .68rem; font-weight: 700; }
.pill-green  { background: #dcfce7; color: var(--green); }
.pill-amber  { background: #fef3c7; color: var(--amber); }
.pill-red    { background: #fee2e2; color: var(--red); }
.pill-gray   { background: #eceef3; color: var(--text2); }

.pref-remove {
  cursor: pointer; font-weight: 700; color: #c2410c; border-radius: 50%;
  width: 16px; height: 16px; display: inline-flex; align-items: center; justify-content: center;
  line-height: 1; transition: background .1s, color .1s;
}
.pref-remove:hover { background: #fee2e2; color: var(--red); }

/* ── Buttons / inputs ────────────────────────────────────────────────── */
.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 7px;
  padding: 7px 13px;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: #f5f6f9; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand2); }
.btn-danger  { background: #fff; border-color: #fca5a5; color: var(--red); }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 4px 9px; font-size: .74rem; }

input[type=text], input[type=search], input[type=date], input[type=number], select, textarea {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: .82rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

.search-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.search-bar input[type=search] { flex: 1; min-width: 180px; }

.admit-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.admit-form input[type=text] { min-width: 200px; }
.admit-form select { min-width: 260px; }

/* ── Merge suggestions ───────────────────────────────────────────────── */
.merge-pair { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.merge-pair-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.merge-rec-wrap { display: flex; flex-direction: column; gap: 8px; }
.merge-rec-wrap .btn { width: 100%; }
.merge-rec { font-size: .78rem; background: #fafbfd; border-radius: 6px; padding: 8px 10px; }
.merge-rec .mr-name { font-weight: 700; }
.merge-rec .mr-field { color: var(--text2); }
.mr-att-list { margin: 2px 0 0; padding-left: 16px; }
.merge-actions { display: flex; gap: 8px; }
.mr-course-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 3px; }
.mr-course-chip { display: inline-flex; align-items: center; gap: 6px; background: #eef1f8; border: 1px solid var(--border); border-radius: 999px; padding: 2px 6px 2px 10px; font-size: .74rem; }
.mr-course-del { border: none; background: none; color: var(--red, #dc2626); font-weight: 700; font-size: .8rem; cursor: pointer; line-height: 1; padding: 2px 4px; border-radius: 50%; }
.mr-course-del:hover { background: #fee2e2; }
.mr-course-del:disabled { opacity: .5; cursor: default; }
.merge-warn { background: #fef3c7; color: var(--amber); border: 1px solid #fde68a; border-radius: 8px; padding: 8px 12px; font-size: .78rem; font-weight: 600; margin-bottom: 8px; }

/* ── Feedback ─────────────────────────────────────────────────────────── */
.fb-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: #fafbfd; }
.fb-card-hd { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.fb-name { font-weight: 700; font-size: .88rem; }
.fb-meta { font-size: .74rem; color: var(--text3); margin-top: 2px; }
.fb-stars { color: #f59e0b; font-size: 1rem; white-space: nowrap; }
.fb-comment { font-size: .82rem; font-style: italic; color: var(--text); margin-top: 8px; }
.fb-notes { margin: 6px 0 0; padding-left: 18px; font-size: .78rem; color: var(--text2); }
.fb-submitted { font-size: .7rem; color: var(--text3); }
.fb-card-ft { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; flex-wrap: wrap; }

/* ── Batches editor ──────────────────────────────────────────────────── */
.week-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.week-card-hd { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.week-card-hd input { width: 90px; }
.week-card-hd input.wk-dates { width: 150px; }
.slot-row { display: grid; grid-template-columns: 110px 1fr 70px 90px 80px auto; gap: 8px; align-items: center; margin-bottom: 6px; }
.slot-row input, .slot-row select { width: 100%; }
.slot-advanced { display: none; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin: 4px 0 10px; padding: 8px; background: #fafbfd; border-radius: 6px; }
.slot-advanced.show { display: grid; }
.slot-advanced label { font-size: .68rem; color: var(--text3); display: block; margin-bottom: 2px; }
.slot-advanced input { width: 100%; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15,17,26,.45); display: none; align-items: center; justify-content: center; z-index: 50; }
.modal-backdrop.show { display: flex; }
.modal { background: #fff; border-radius: var(--radius); padding: 20px; width: 480px; max-width: 92vw; max-height: 85vh; overflow-y: auto; }
.modal.wide { width: 640px; }
.modal h3 { margin: 0 0 12px; font-size: 1rem; }
.modal-close { float: right; cursor: pointer; color: var(--text3); font-size: 1.1rem; }

#edit-student-form label, #add-student-form label {
  font-size: .72rem; font-weight: 600; color: var(--text3); display: block; margin-bottom: 3px;
}
#edit-student-form input, #edit-student-form select,
#add-student-form input, #add-student-form select { width: 100%; }

.edit-batch-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8faf8;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.edit-batch-current { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.edit-batch-name { font-weight: 600; font-size: .85rem; }
.edit-batch-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding-top: 8px; border-top: 1px dashed var(--border); }
.edit-batch-actions label { font-size: .72rem; color: var(--text3); margin-right: 2px; }
.edit-batch-row select.chg-batch-select { min-width: 220px; }

.edit-batch-add-section {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 12px;
  background: #fafbff;
}

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: .82rem; z-index: 100; opacity: 0; transform: translateY(8px); transition: all .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--red); }

.empty-note { color: var(--text3); font-size: .82rem; padding: 10px 0; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text2); }

/* ── Printable batch report ─────────────────────────────────────────── */
/* .pr-head (title block) and .pr-footer sit OUTSIDE the <table> and print exactly
   once each. Only the plain column-header row lives inside <thead>, so that's the
   only thing that repeats if a roster is long enough to spill onto a continuation
   page — see batchReportSectionHtml() in admin.js. */
#print-report { display: none; }
.pr-head { text-align: center; padding-bottom: 8px; page-break-inside: avoid; }
.pr-head h2 { margin: 0 0 3px; font-size: 1.1rem; }
.pr-head .pr-batch { font-size: .92rem; font-weight: 700; color: var(--brand2); margin-bottom: 5px; }
.pr-details { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; font-size: .74rem; color: var(--text2); }
.pr-table { width: 100%; border-collapse: collapse; font-size: .74rem; margin-bottom: 10px; }
.pr-table th, .pr-table td { border: 1px solid #333; padding: 3px 6px; text-align: left; }
.pr-table thead tr.pr-col-row th { background: #f0f0f0; }
.pr-footer { padding-top: 6px; border-top: 1px solid #333; display: flex; justify-content: space-between; font-size: .74rem; page-break-inside: avoid; }
.pr-footer a { color: inherit; }
/* No forced width/min-height on .pr-stats-page — the printable A4 area is already set
   by @page below (page size minus its 10mm margin). Forcing a full 297mm-tall block on
   top of that overflowed the printable area and pushed out a blank second page. A single
   page-break-before on the element that FOLLOWS a page (.pr-page-break) is enough to end
   it — adding page-break-after too would give the browser two conflicting break
   instructions at the same boundary. */
.pr-page-break { page-break-before: always; }

/* ── Messages (WhatsApp send) ───────────────────────────────────────── */
.msg-textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; font-size: .86rem; resize: vertical; }
.msg-textarea:focus { outline: none; border-color: var(--brand2); }
.msg-custom-list { max-height: 280px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
.msg-custom-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; font-size: .82rem; }
.msg-custom-row:hover { background: #f8faf8; }
.msg-custom-row .mcr-name { font-weight: 600; }
.msg-custom-row .mcr-detail { color: var(--text3); font-size: .74rem; }
#msg-preview { white-space: pre-wrap; background: #f8faf8; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: .84rem; }

@media print {
  body * { visibility: hidden; }
  #print-report, #print-report * { visibility: visible; }
  #print-report { display: block; position: absolute; top: 0; left: 0; width: 100%; padding: 12px; }
  .pr-table thead { display: table-header-group; }
  .pr-table tr { page-break-inside: avoid; }
  @page { margin: 10mm; }
}

.reg-thumb {
  width: 50px; height: 50px; border-radius: 6px; object-fit: cover;
  border: 1px solid var(--border); background: #f0f1f4; display: flex;
  align-items: center; justify-content: center; color: var(--text3); font-size: .7rem;
}
.reg-thumb-img { cursor: pointer; }

.doc-card { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: #fafbfd; min-width: 140px; }
.doc-card-label { font-weight: 700; font-size: .78rem; margin-bottom: 6px; }
.doc-card-img { width: 130px; max-height: 160px; object-fit: cover; border-radius: 6px; cursor: pointer; display: block; }

.img-lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.82); z-index: 500;
  display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 30px;
}
.img-lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }

@media (max-width: 760px) {
  .sidebar { width: 64px; padding: 14px 6px; }
  .sidebar-brand, .nav-item span.label { display: none; }
  .nav-item { justify-content: center; }
  .merge-pair-rows { grid-template-columns: 1fr; }
  .slot-row { grid-template-columns: 1fr 1fr; }
}
