@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --text: #17202b;
  --muted: #6b7280;
  --accent: #3978f6;
  --accent-dark: #2f66d8;
  --border: #e4e7ec;
  --border-strong: #d6dae1;
  --danger: #b74343;
  --success: #2f7450;
  --warning: #936511;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.07);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  min-width: 0;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea {
  max-width: 100%;
  min-width: 0;
  font: inherit;
}

button {
  touch-action: manipulation;
}

h1, h2, h3, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 3vw, 2.15rem);
  line-height: 1.12;
  letter-spacing: -0.035em;
}

h2 {
  margin-bottom: 0.3rem;
  font-size: 1.08rem;
  letter-spacing: -0.015em;
}

h3 {
  margin-bottom: 0.25rem;
  letter-spacing: -0.012em;
}

p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem clamp(1rem, 4vw, 3.5rem);
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid rgba(228, 231, 236, 0.9);
  backdrop-filter: blur(16px);
}

.eyebrow {
  margin: 0 0 0.28rem;
  color: #c48a46;
  font-size: 0.67rem;
  font-weight: 700;
  letter-spacing: 0.19em;
  text-transform: uppercase;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  padding: 0.5rem clamp(1rem, 4vw, 3.5rem) 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 0 0 auto;
  padding: 0.75rem 0.85rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.91rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
}

.container {
  width: min(1240px, calc(100% - 2rem));
  min-width: 0;
  margin: 1.5rem auto 3rem;
}

.panel {
  display: none;
  min-width: 0;
}

.panel.active {
  display: block;
}

.card,
.stat-card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card {
  padding: clamp(1rem, 2vw, 1.35rem);
  margin-bottom: 1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.stat-card {
  padding: 1.1rem;
}

.stat-card span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.stat-card strong {
  display: block;
  color: var(--text);
  font-size: 1.55rem;
  letter-spacing: -0.035em;
  overflow-wrap: anywhere;
}

.stat-card small {
  display: block;
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  min-width: 0;
  margin-bottom: 1rem;
}

.card-heading > * {
  min-width: 0;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.form-card {
  position: sticky;
  top: 6rem;
}

.student-form-wrapper {
  margin-top: 1rem;
}

.student-form-wrapper .form-card {
  width: min(760px, 100%);
  max-width: 100%;
}

label {
  display: grid;
  gap: 0.38rem;
  min-width: 0;
  margin-bottom: 0.85rem;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
}

input,
select,
textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.78rem;
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 1px 1px rgba(15, 23, 42, 0.02);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input,
select {
  min-height: 42px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(57, 120, 246, 0.12);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  min-width: 0;
}

.form-row > * {
  min-width: 0;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: fit-content;
}

.checkbox-label input {
  width: 18px;
  min-width: 18px;
  min-height: 18px;
  margin: 0;
}

.header-actions,
.form-actions,
.invoice-actions,
.item-actions,
.student-card-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0.62rem 0.9rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
  box-shadow: none;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.button-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.button-secondary:hover {
  background: var(--surface-soft);
  border-color: #c9ced7;
}

.button-danger {
  background: #fff;
  color: var(--danger);
  border-color: #ead0d0;
}

.button-danger:hover {
  background: #fff6f6;
  border-color: #dcbbbb;
}

.button-small {
  min-height: 36px;
  padding: 0.52rem 0.72rem;
  font-size: 0.82rem;
}

.student-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 320px) minmax(140px, 180px) auto;
  gap: 0.6rem;
  align-items: center;
  min-width: 0;
}

.student-toolbar .search,
.teacher-filter {
  width: 100%;
  min-width: 0;
  max-width: none;
}

.student-toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  min-width: 0;
}

.search {
  max-width: 100%;
}

.compact-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-width: 0;
}

.compact-filters select {
  min-width: 0;
  width: auto;
  max-width: 100%;
}

.student-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 0.85rem;
  min-width: 0;
}

.student-card {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-width: 0;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.student-card:hover {
  border-color: #d5dae3;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.student-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
}

.student-card-top > div {
  min-width: 0;
}

.student-card-kicker {
  margin-bottom: 0.24rem;
  color: var(--accent-dark);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.student-card h3 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 1.08rem;
}

.student-card-body {
  display: grid;
  gap: 0.75rem;
  min-width: 0;
}

.student-detail,
.student-detail-row {
  min-width: 0;
}

.student-detail-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.student-detail {
  display: grid;
  gap: 0.18rem;
}

.student-detail-label {
  color: var(--muted);
  font-size: 0.69rem;
  font-weight: 650;
  letter-spacing: 0.045em;
  text-transform: uppercase;
}

.student-detail-value {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 0.89rem;
  line-height: 1.4;
}

.student-card-footer {
  margin-top: auto;
  padding-top: 0.15rem;
}

.student-card-footer .button {
  flex: 1 1 90px;
}

.list {
  display: grid;
  gap: 0.65rem;
  min-width: 0;
}

.list-item {
  min-width: 0;
  padding: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.list-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
}

.list-item-top > div:first-child {
  min-width: 0;
}

.list-item h3 {
  margin: 0 0 0.2rem;
  font-size: 0.96rem;
}

.item-actions button {
  min-height: 34px;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
}

.item-actions .delete {
  color: var(--danger);
}

.meta {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  padding: 0.22rem 0.48rem;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.69rem;
  font-weight: 650;
}

.badge.success {
  background: #e7f4eb;
  color: var(--success);
}

.badge.warning {
  background: #fff3d8;
  color: var(--warning);
}

.badge.muted {
  background: #eef0f3;
  color: #69717d;
}

.empty-state {
  min-width: 0;
  padding: 1.5rem 1rem;
  color: var(--muted);
  text-align: center;
  background: var(--surface-soft);
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
}

.invoice-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 0.7rem;
  align-items: end;
  min-width: 0;
}

.invoice-controls > * {
  min-width: 0;
}

.invoice-controls label {
  margin: 0;
}

.invoice-customer {
  min-width: 0;
  overflow: hidden;
  margin-bottom: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.invoice-customer-header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
  padding: 0.9rem;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
}

.invoice-customer-header > * {
  min-width: 0;
}

.invoice-customer-header h3 {
  margin: 0 0 0.15rem;
}

.invoice-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
}

.invoice-customer {
  overflow-x: auto;
}

.invoice-table th,
.invoice-table td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.invoice-table th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.invoice-total {
  padding: 0.85rem;
  font-weight: 700;
  text-align: right;
}

.login-menu {
  position: relative;
  flex: 0 0 auto;
}

.login-dropdown {
  position: absolute;
  top: calc(100% + 0.6rem);
  right: 0;
  z-index: 40;
  width: min(340px, calc(100vw - 2rem));
  max-width: calc(100vw - 2rem);
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.login-dropdown label {
  display: grid;
}

.hidden {
  display: none !important;
}

dialog {
  width: min(420px, calc(100% - 2rem));
  max-width: calc(100% - 2rem);
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.22);
}

dialog::backdrop {
  background: rgba(20, 25, 35, 0.38);
}

dialog form {
  min-width: 0;
  padding: 1.2rem;
}

@media (max-width: 980px) {
  .student-toolbar {
    grid-template-columns: minmax(0, 1fr) minmax(135px, 170px);
  }

  .student-toolbar-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .split-layout {
    grid-template-columns: 1fr;
  }

  .form-card {
    position: static;
  }

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

@media (max-width: 700px) {
  .topbar {
    align-items: flex-start;
  }

  .container {
    width: min(100% - 1rem, 1240px);
    margin-top: 0.75rem;
  }

  .card,
  .stat-card {
    border-radius: 14px;
  }

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

  .card-heading,
  .list-item-top,
  .invoice-customer-header {
    flex-direction: column;
  }

  .student-toolbar {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .student-toolbar-actions {
    grid-column: auto;
    width: 100%;
    justify-content: stretch;
  }

  .student-toolbar-actions .button {
    flex: 1 1 0;
  }

  .form-row,
  .invoice-controls,
  .student-detail-row {
    grid-template-columns: 1fr;
  }

  .compact-filters {
    width: 100%;
  }

  .compact-filters select {
    width: 100%;
  }

  .student-card-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 460px) {
  .topbar {
    padding: 0.9rem 0.75rem;
  }

  .tabs {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .card {
    padding: 0.9rem;
  }

  .form-actions,
  .invoice-actions {
    width: 100%;
  }

  .form-actions .button,
  .invoice-actions .button {
    flex: 1 1 100%;
  }
}
