/* ==========================================================================
   LLA Design System — Components
   ========================================================================== */

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
  white-space: nowrap;
  line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: var(--white); }
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }

.btn-outline { background: var(--white); border-color: var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); }

.btn-danger { background: var(--color-danger); border-color: var(--color-danger); color: var(--white); }
.btn-danger:hover { background: #B91C1C; border-color: #B91C1C; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); }

.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ---- Cards ---- */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-body { padding: 20px; }
.card-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  /* A header carrying a title plus a row of actions has to wrap on a phone,
     or the widest action pushes the whole card past the viewport. */
  flex-wrap: wrap;
}
.card-header > * { min-width: 0; }
.card-header h3 { flex: 1 1 auto; }
.card-header h3 { margin: 0; font-size: 15.5px; display: flex; align-items: center; gap: 8px; }
.card-header h3 i { color: var(--blue-600, var(--color-primary)); font-size: 15px; }
.card-header .link { font-size: 12.5px; font-weight: 600; }

/* Stat card */
.stat-card { display: flex; align-items: center; gap: 14px; padding: 18px; }
.stat-icon {
  width: 48px; height: 48px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: var(--white); font-size: 20px;
}
.stat-card .stat-label { font-size: 12.5px; color: var(--text-muted); margin-bottom: 2px; }
.stat-card .stat-value { font-size: 22px; font-weight: 700; color: var(--text-heading); }
.stat-card .stat-trend { font-size: 11.5px; margin-top: 2px; }
.stat-trend.up { color: var(--green-600); }
.stat-trend.down { color: var(--red-600); }

.bg-blue { background: var(--blue-600); }
.bg-purple { background: var(--purple-500); }
.bg-amber { background: var(--amber-500); }
.bg-green { background: var(--green-600); }
.bg-red { background: var(--red-500); }
.bg-navy { background: var(--navy-900); }

/* ---- Badges / Status pills ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.6;
}
.badge-green { background: var(--green-100); color: var(--green-700); }
.badge-amber { background: var(--amber-100); color: var(--amber-600); }
.badge-red { background: var(--red-100); color: var(--red-600); }
.badge-blue { background: var(--blue-50); color: var(--blue-700); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-purple { background: var(--purple-100); color: var(--purple-600); }

/* ---- Alerts ---- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  border: 1px solid transparent;
  margin-bottom: 16px;
}
.alert-error { background: var(--red-100); border-color: #F6B9C4; color: #9A1B32; }
.alert-success { background: var(--green-100); border-color: #A8E4C7; color: var(--green-700); }
.alert-info { background: var(--blue-50); border-color: var(--blue-100); color: var(--blue-700); }

/* ---- Forms ---- */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--gray-700);
  margin-bottom: 6px;
}
.form-label .req { color: var(--color-danger); }
.form-control {
  width: 100%;
  padding: 11px 14px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--gray-800);
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus {
  outline: none;
  border-color: var(--blue-600);
  box-shadow: 0 0 0 3px var(--blue-50);
}
.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }
.form-error { font-size: 11.5px; color: var(--color-danger); margin-top: 5px; }
.input-group { position: relative; }
.input-group .form-control { padding-left: 40px; }
.input-group .input-icon {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--gray-400); font-size: 15px;
}
.input-group .input-toggle {
  position: absolute; right: 13px; top: 50%; transform: translateY(-50%);
  color: var(--gray-400); cursor: pointer; background: none; border: none; font-size: 13px;
}

/* ---- Tables ---- */
.table-wrap { border: 1px solid var(--border-default); border-radius: var(--radius-lg); overflow: hidden; background: var(--white); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 560px; }
.data-table thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--gray-500);
  background: var(--gray-50);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:nth-child(even) { background: var(--gray-50); }
.data-table tbody tr:hover { background: var(--blue-50, #EFF6FF); }

/* ---- Avatar ----
   People are shown as squares, not circles, so a face is not cropped at the
   chin and the ears. Width drives the size; the height follows. */
.avatar {
  width: 32px; height: auto; aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  object-fit: cover; object-position: center top;
  background: var(--gray-200); flex-shrink: 0;
}
.avatar-sm { width: 26px; }
.avatar-lg { width: 52px; }
.avatar-xl {
  width: 92px; border: 3px solid rgba(255,255,255,.85);
  box-shadow: 0 4px 14px rgba(0,0,0,.25); font-size: 30px;
}
.avatar-fallback {
  display: flex; align-items: center; justify-content: center;
  background: var(--blue-100); color: var(--blue-700); font-weight: 700; font-size: 13px;
}

/* A taller frame where a layout wants a passport shape. */
.avatar-portrait { aspect-ratio: 2 / 3; }

/* The signed-in user in the header stays compact. */
.topbar .avatar { width: 30px; }

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .icon {
  width: 56px; height: 56px; margin: 0 auto 14px; border-radius: var(--radius-full);
  background: var(--blue-50); color: var(--blue-600);
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.empty-state h4 { color: var(--gray-700); margin-bottom: 4px; }
.empty-state p { font-size: 12.5px; margin-bottom: 16px; }

/* ---- Quote / banner strip ---- */
.quote-strip {
  background: var(--blue-50);
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--navy-900);
  font-style: italic;
  flex-wrap: wrap;
}

/* ---- Dropdown menu ---- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 200px;
  background: var(--white);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 60;
  display: none;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left; background: none; border: none;
  padding: 9px 10px; font-size: 13px; color: var(--gray-700);
  border-radius: var(--radius-sm); cursor: pointer;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--gray-100); text-decoration: none; }
.dropdown-menu .danger { color: var(--color-danger); }
.dropdown-menu hr { border: none; border-top: 1px solid var(--gray-100); margin: 6px 0; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  display: none; align-items: center; justify-content: center;
  padding: 16px; z-index: 100;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--white); border-radius: var(--radius-lg);
  width: 100%; max-width: 420px; box-shadow: var(--shadow-lg);
  max-height: 90vh; overflow-y: auto;
}
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--border-default); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border-default); display: flex; justify-content: flex-end; gap: 10px; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-default); overflow-x: auto; }
.tab-link {
  padding: 11px 16px; font-size: 13px; font-weight: 600; color: var(--gray-500);
  border-bottom: 2px solid transparent; white-space: nowrap; cursor: pointer; background: none; border-left: none; border-right: none; border-top: none;
}
.tab-link.active { color: var(--blue-700); border-bottom-color: var(--blue-600); }

/* ---- Pagination ---- */
.pagination { display: flex; align-items: center; gap: 4px; }
.pagination a, .pagination span {
  min-width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); font-size: 12.5px; color: var(--gray-600);
}
.pagination a:hover { background: var(--gray-100); text-decoration: none; }
.pagination .active { background: var(--blue-600); color: var(--white); font-weight: 700; }

/* ---- List rows (used in dashboard "recent" widgets, Messages, School Calendar) ---- */
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--gray-100);
}
.list-row:last-child { border-bottom: none; }
/* Inside a .card-body the parent already supplies horizontal padding — don't double it up. */
.card-body .list-row { padding-left: 0; padding-right: 0; }
.list-row .list-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--white);
}
.list-row .list-title { font-size: 13px; font-weight: 600; color: var(--gray-800); }
.list-row .list-sub { font-size: 11.5px; color: var(--text-muted); }
.list-row .list-meta { margin-left: auto; font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* ---- Pay Into: the school's bank accounts on fee pages and invoices ---- */
.pay-into-card { margin-bottom: 20px; border-left: 4px solid var(--blue-600); }
.pay-into-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.pay-into-box {
  background: var(--blue-50, #F0F6FF);
  border: 1px solid var(--blue-100, #D6E6FF);
  border-radius: 10px;
  padding: 14px 16px;
}
.pay-into-field { display: flex; flex-direction: column; gap: 1px; margin-bottom: 9px; }
.pay-into-field:last-child { margin-bottom: 0; }
.pay-into-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--gray-600, #64748B);
  font-weight: 600;
}
.pay-into-value { font-size: 15.5px; font-weight: 700; color: var(--navy-900, #002E6D); line-height: 1.35; overflow-wrap: anywhere; }
.pay-into-number { font-size: 19px; letter-spacing: 1.2px; font-variant-numeric: tabular-nums; }
.pay-into-note { margin: 8px 0 0; font-size: 12.5px; color: var(--gray-600, #64748B); }

/* Flat variant for printed invoices. */
.pay-into-print { margin: 16px 0 4px; padding: 10px 12px; border: 1px solid #CBD5E1; border-radius: 6px; }
.pay-into-print .pay-into-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: #475569; font-weight: 700; margin-bottom: 5px;
}
.pay-into-print .pay-into-row { display: flex; flex-wrap: wrap; gap: 4px 20px; font-size: 13px; line-height: 1.6; }
.pay-into-print .pay-into-note { margin: 2px 0 0; font-size: 11.5px; }

@media (max-width: 480px) {
  .pay-into-grid { grid-template-columns: 1fr; }
  .pay-into-number { font-size: 17px; }
}

/* Five headline figures (invoice: fees, discounts, payable, paid, balance).
   Narrower minimum than the default stat grid so all five sit on one row once
   there is room, and wrap tidily in pairs below that. */
@media (min-width: 640px) {
  .stat-grid-5 { grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }
}

/* ---- Fee totals strip under a pupil's fee list ---- */
.fee-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  padding: 14px 16px;
  margin-top: 2px;
  background: var(--gray-50, #F8FAFC);
  border-top: 1px solid var(--border-default, #E2E8F0);
  border-radius: 0 0 10px 10px;
}
.fee-total { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fee-total-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--gray-600, #64748B); font-weight: 600;
}
.fee-total-value { font-size: 18px; font-weight: 700; color: var(--navy-900, #002E6D); line-height: 1.3; }
.fee-total-line { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.fee-total-line .icon-btn { width: 30px; height: 30px; color: var(--blue-600); }

@media (max-width: 420px) {
  .fee-totals { grid-template-columns: 1fr; }
}

/* A label/value list rendered as a table (a profile record, not tabular data).
   It drops .data-table's 560px min-width, which is there so real data tables
   stay readable inside .scroll-x, and lets long values wrap instead — a phone
   should not scroll sideways to read someone's address. */
table.data-table.kv-table {
  min-width: 0;
  table-layout: fixed;
}
.kv-table tbody td { word-break: break-word; overflow-wrap: anywhere; }
.kv-table tbody td:first-child { width: 42%; }

@media (max-width: 420px) {
  .kv-table tbody td:first-child { width: 46%; }
  .kv-table { font-size: 12.5px; }
}

/* Visible only to screen readers — a label a sighted user gets from the
   placeholder, but which a screen reader still needs. */
.u-sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* The quiet spinner inside a live search box while results are being fetched. */
.search-spinner {
  position: absolute;
  right: 10px; top: 50%;
  width: 14px; height: 14px;
  margin-top: -7px;
  border: 2px solid var(--blue-100, #D6E6FF);
  border-top-color: var(--blue-600, #0475D3);
  border-radius: 50%;
  animation: search-spin .6s linear infinite;
  pointer-events: none;
}
.search-spinner[hidden] { display: none; }

@keyframes search-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .search-spinner { animation-duration: 2s; }
}

/* An either/or scope choice (a fee covering the whole school, or named classes). */
.scope-choice { display: flex; flex-direction: column; gap: 8px; }
.scope-choice .pick-row { align-items: flex-start; }

@media (min-width: 560px) {
  .scope-choice { flex-direction: row; gap: 14px; }
  .scope-choice .pick-row { flex: 1; }
}

/* A list row holding a long filename plus an action: let it stack on a phone
   rather than pushing the button past the edge of the screen. */
.list-row-wrap { flex-wrap: wrap; }
.list-row-wrap > :first-child { flex: 1 1 100%; min-width: 0; }
.list-row-wrap .list-title { overflow-wrap: anywhere; }

@media (min-width: 480px) {
  .list-row-wrap > :first-child { flex: 1 1 auto; }
}

/* The day a teacher is actually looking at, on their periods list. */
.card-today { border-left: 4px solid var(--green-600, #16A34A); }

/* Click-to-sort table headers (item 49). The existing .sortable style is for
   server-side sorted listings; this is the client-side variant used where the
   whole list is already on the page. */
.data-table th.is-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.data-table th.is-sortable:hover { color: var(--color-primary, #0475D3); }
.data-table th.is-sortable:focus-visible { outline: 2px solid var(--blue-600); outline-offset: -2px; }
.data-table th .sort-ind { margin-left: 5px; opacity: .4; font-size: 10px; }
.data-table th .sort-ind.is-active { opacity: 1; color: var(--color-primary, #0475D3); }

/* The checkbox column stays narrow and does not wrap. */
.data-table .col-check { width: 38px; text-align: center; }

/* A plain horizontal bar chart — no chart library for a handful of averages. */
.bar-chart { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 52px; gap: 10px; align-items: center; }
.bar-label {
  font-size: 12.5px; font-weight: 600; color: var(--navy-900, #002E6D);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar-track { height: 18px; background: var(--gray-100, #F1F5F9); border-radius: var(--radius-full, 999px); overflow: hidden; }
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue-600, #0475D3), var(--blue-500, #3B9BE8));
  border-radius: var(--radius-full, 999px);
  min-width: 2px;
  transition: width .3s ease;
}
.bar-value { font-size: 12.5px; font-weight: 700; text-align: right; color: var(--navy-900, #002E6D); }

@media (max-width: 560px) {
  .bar-row { grid-template-columns: 1fr 44px; grid-template-areas: "label label" "track value"; }
  .bar-label { grid-area: label; white-space: normal; }
  .bar-track { grid-area: track; }
  .bar-value { grid-area: value; }
}

@media print {
  .no-print, .sidebar, .topbar { display: none !important; }
}

/* The room/venue on a timetable cell — one shape across every panel, so the
   admin, teacher, student and parent views read identically (item 61). */
.tt-room {
  font-size: 10.5px;
  color: var(--text-muted, #64748B);
  margin-top: 2px;
  overflow-wrap: anywhere;
}
.tt-room .bi { font-size: 10px; }

/* ---- Rich text editor (item 58) ---- */
.rte { border: 1px solid var(--border-default, #E2E8F0); border-radius: var(--radius-md, 10px); overflow: hidden; }
.rte-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
  padding: 6px 8px;
  background: var(--gray-50, #F8FAFC);
  border-bottom: 1px solid var(--border-default, #E2E8F0);
}
.rte-btn {
  border: none; background: none; cursor: pointer;
  width: 30px; height: 30px; border-radius: var(--radius-sm, 6px);
  color: var(--gray-600, #475569); font-size: 14px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.rte-btn:hover { background: var(--blue-50, #EFF6FF); color: var(--navy-900, #002E6D); }
.rte-btn:focus-visible { outline: 2px solid var(--blue-600); outline-offset: -2px; }
.rte-sep { width: 1px; height: 18px; background: var(--border-default, #E2E8F0); margin: 0 4px; }

.rte-surface {
  min-height: 320px; max-height: 60vh; overflow-y: auto;
  border: none; border-radius: 0; background: var(--surface-card, #fff);
  padding: 14px 16px; font-size: 14px; line-height: 1.65;
}
.rte-surface:focus { outline: none; box-shadow: none; }
.rte-surface h2 { font-size: 20px; margin: 18px 0 8px; color: var(--navy-900, #002E6D); }
.rte-surface h3 { font-size: 17px; margin: 16px 0 8px; color: var(--navy-900, #002E6D); }
.rte-surface p { margin: 0 0 10px; }
.rte-surface ul, .rte-surface ol { margin: 0 0 10px; padding-left: 22px; }
.rte-surface blockquote {
  margin: 0 0 10px; padding: 6px 14px;
  border-left: 3px solid var(--blue-600, #0475D3);
  color: var(--gray-600, #475569);
}
.rte-surface img { max-width: 100%; height: auto; border-radius: var(--radius-sm, 6px); }
.rte-surface:empty::before { content: attr(data-placeholder); color: var(--text-muted, #94A3B8); }

/* The textarea stays in the form so the value still posts, but is not shown. */
.rte-source { display: none; }
