:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-soft: #eef0f3;
  --ink: #171719;
  --muted: #68707a;
  --line: #dde1e6;
  --teal: #c9182b;
  --teal-strong: #a60f20;
  --teal-soft: #fee2e7;
  --blue: #343941;
  --blue-soft: #e5e7eb;
  --amber: #a44417;
  --amber-soft: #fff1df;
  --red: #c9182b;
  --red-soft: #fee2e7;
  --green: #15803d;
  --green-soft: #dcfce7;
  --brand-black: #101113;
  --brand-charcoal: #202124;
  --shadow: 0 12px 30px rgba(16, 17, 19, 0.09);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px clamp(16px, 3vw, 32px);
  color: #ffffff;
  background: var(--brand-black);
  border-bottom: 1px solid #2b2c31;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  padding: 0;
  flex: 0 0 auto;
  place-items: center;
  color: var(--surface);
  background: #050505;
  border: 2px solid var(--red);
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.brand-mark:hover {
  border-color: #ff4054;
}

.brand-mark:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.34);
  outline-offset: 3px;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

[data-icon] svg {
  width: 1.1em;
  height: 1.1em;
  fill: currentColor;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.65rem);
  line-height: 1.15;
}

.brand p {
  margin: 4px 0 0;
  color: #d4d7dc;
  font-size: 0.92rem;
}

.topbar .ghost-button {
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.06);
  border-color: #3a3b41;
}

.topbar .ghost-button:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: #585a62;
}

.topbar .primary-button {
  background: var(--red);
  border-color: var(--red);
}

.topbar .primary-button:hover {
  background: var(--teal-strong);
}

.top-actions,
.toolbar,
.filters,
.inline-actions,
.modal-actions,
.chip-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 12px clamp(16px, 3vw, 32px);
  background: var(--brand-charcoal);
  border-bottom: 1px solid #2f3035;
  overflow-x: auto;
}

.tab,
.ghost-button,
.primary-button,
.danger-button,
.icon-button,
.month-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition:
    background 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease;
}

.tab {
  min-width: 132px;
  padding: 0 14px;
  color: #cbd0d7;
  background: transparent;
  border-color: #3a3b41;
}

.tab.is-active {
  color: #ffffff;
  background: rgba(201, 24, 43, 0.25);
  border-color: var(--red);
}

.ghost-button {
  padding: 0 13px;
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.ghost-button:hover,
.tab:hover {
  border-color: #aeb5bf;
}

.primary-button {
  padding: 0 15px;
  color: var(--surface);
  background: var(--teal);
  border-color: var(--teal);
}

.primary-button:hover {
  background: var(--teal-strong);
}

.danger-button {
  padding: 0 13px;
  color: #8f1020;
  background: var(--red-soft);
  border-color: #f5a3ae;
}

.icon-button {
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
}

.icon-button:hover {
  color: var(--ink);
  background: var(--surface-soft);
}

.content {
  width: min(100%, 1480px);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 32px) 44px;
}

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.view-header h2,
.modal-header h2,
.panel h3 {
  margin: 0;
}

.view-header h2 {
  font-size: clamp(1.25rem, 2vw, 1.8rem);
}

.view-header p {
  margin: 5px 0 0;
  color: var(--muted);
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 18px;
}

.filters {
  align-items: flex-end;
}

label,
.field-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 0 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(201, 24, 43, 0.14);
}

a {
  color: var(--red);
  text-decoration-color: rgba(201, 24, 43, 0.32);
  text-underline-offset: 2px;
}

.search-field {
  min-width: min(320px, 100%);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  min-height: 118px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.kpi-card strong {
  color: var(--red);
}

.kpi-card span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.kpi-card strong {
  display: block;
  margin-top: 12px;
  font-size: 1.85rem;
  line-height: 1;
}

.kpi-card small {
  display: block;
  margin-top: 9px;
  color: var(--muted);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
  gap: 16px;
  margin-bottom: 18px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-body {
  padding: 16px;
}

.month-chart {
  display: grid;
  grid-template-columns: repeat(12, minmax(42px, 1fr));
  align-items: end;
  gap: 9px;
  min-height: 230px;
}

.chart-column {
  display: grid;
  grid-template-rows: 1fr auto;
  min-width: 42px;
  gap: 8px;
}

.bar-track {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  height: 170px;
  overflow: hidden;
  background: #edf1f5;
  border: 1px solid #dfe6ec;
  border-radius: 6px;
}

.bar-paid,
.bar-pending {
  width: 100%;
}

.bar-paid {
  background: var(--green);
}

.bar-pending {
  background: var(--red);
}

.chart-label {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.legend {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend .paid-dot {
  background: var(--green);
}

.legend .pending-dot {
  background: var(--red);
}

.summary-list {
  display: grid;
  gap: 10px;
}

.summary-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.summary-row strong,
.student-name-cell strong {
  display: block;
  overflow-wrap: anywhere;
}

.summary-row small,
.student-name-cell small,
.muted {
  color: var(--muted);
}

.table-shell {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.data-table {
  table-layout: auto;
}

.students-table {
  min-width: 1120px;
}

.payments-table {
  min-width: 900px;
}

.dashboard-table {
  min-width: 1320px;
}

.history-table {
  min-width: 780px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  text-align: left;
  word-break: normal;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: #415164;
  background: #eef2f4;
  font-size: 0.78rem;
  letter-spacing: 0;
  white-space: nowrap;
}

tbody tr:hover td {
  background: #fbfdfe;
}

.sticky-col {
  position: sticky;
  left: 0;
  z-index: 1;
  background: inherit;
}

th.sticky-col {
  z-index: 3;
  background: #eef2f4;
}

.code-col {
  width: 96px;
  min-width: 96px;
}

.name-col {
  width: 310px;
  min-width: 250px;
}

.month-col {
  width: 96px;
  min-width: 96px;
  text-align: center;
}

.action-col {
  width: 118px;
  min-width: 118px;
}

.status-pill,
.month-chip,
.tag {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
}

.month-chip {
  width: 74px;
  color: var(--muted);
  background: var(--surface-soft);
  border-color: var(--line);
}

.month-chip.paid {
  color: #166534;
  background: var(--green-soft);
  border-color: #86efac;
}

.month-chip.pending {
  color: #8f1020;
  background: var(--red-soft);
  border-color: #f5a3ae;
}

.month-chip.future {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: #93c5fd;
}

.status-good {
  color: #166534;
  background: var(--green-soft);
}

.status-bad {
  color: #9a3412;
  background: var(--red-soft);
}

.status-neutral {
  color: #334155;
  background: var(--surface-soft);
}

.amount {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.empty-state {
  display: grid;
  min-height: 180px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.modal {
  width: min(720px, calc(100vw - 28px));
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(23, 33, 43, 0.28);
}

.modal::backdrop {
  background: rgba(23, 33, 43, 0.42);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 18px;
  border-bottom: 1px solid var(--line);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.wide-field {
  grid-column: 1 / -1;
}

.modal-actions {
  justify-content: flex-end;
  padding: 16px 18px 18px;
  border-top: 1px solid var(--line);
}

.inline-alert {
  margin: 0 18px 14px;
  padding: 10px 12px;
  color: #9a3412;
  background: var(--red-soft);
  border: 1px solid #fdba74;
  border-radius: var(--radius);
  font-weight: 700;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.history-panel {
  grid-column: 1 / -1;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #334155;
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.tag button {
  width: 22px;
  height: 22px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(440px, calc(100vw - 36px));
  padding: 12px 14px;
  color: var(--surface);
  background: #17212b;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1080px) {
  .topbar,
  .view-header,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  body {
    overflow-x: hidden;
  }

  .content {
    padding-inline: 10px;
  }

  .topbar {
    padding-inline: 12px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
  }

  .brand h1 {
    font-size: 1rem;
    line-height: 1.2;
  }

  .brand p {
    font-size: 0.78rem;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .top-actions > button {
    min-width: 0;
  }

  .tabs {
    padding-inline: 12px;
  }

  .tab {
    min-width: 118px;
  }

  .filters,
  .filters label,
  .filters button {
    width: 100%;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .month-chart {
    grid-template-columns: repeat(6, minmax(42px, 1fr));
  }

  .table-shell {
    overflow: visible;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .mobile-card-table {
    display: block;
    min-width: 0;
    width: 100%;
  }

  .mobile-card-table thead {
    display: none;
  }

  .mobile-card-table tbody {
    display: grid;
    gap: 12px;
  }

  .mobile-card-table tr {
    display: block;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }

  .mobile-card-table tbody tr:hover td {
    background: transparent;
  }

  .mobile-card-table td {
    display: grid;
    grid-template-columns: minmax(96px, 0.42fr) minmax(0, 1fr);
    align-items: start;
    gap: 12px;
    width: 100%;
    min-height: 0;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
  }

  .mobile-card-table td:last-child {
    border-bottom: 0;
  }

  .mobile-card-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
  }

  .mobile-card-table td[colspan] {
    display: block;
  }

  .mobile-card-table td[colspan]::before {
    content: none;
  }

  .mobile-card-table .sticky-col,
  .mobile-card-table .code-col,
  .mobile-card-table .name-col,
  .mobile-card-table .month-col,
  .mobile-card-table .action-col {
    position: static;
    width: auto;
    min-width: 0;
    text-align: left;
  }

  .mobile-card-table .student-name-cell strong {
    overflow-wrap: anywhere;
  }

  .mobile-card-table .month-chip {
    width: 100%;
    max-width: 132px;
  }

  .mobile-card-table .actions-cell .inline-actions {
    justify-content: flex-end;
  }

  .mobile-card-table a {
    overflow-wrap: anywhere;
  }
}
