/* Final UI refinements loaded after the main stylesheet. */

:root {
  --bg: #f4f7f3;
  --surface: #fffdf8;
  --surface-soft: #f2f7f4;
  --text: #24342f;
  --muted: #6a7771;
  --accent: #5f8f7a;
  --accent-dark: #466f5e;
  --border: #dbe5df;
  --border-strong: #cbd9d1;
  --danger: #b44e56;
  --success: #3f7a5a;
  --warning: #a8752e;
}

body {
  background:
    radial-gradient(circle at top left, rgba(211, 231, 221, 0.55), transparent 34%),
    linear-gradient(180deg, #f8faf6 0%, var(--bg) 100%);
}

.topbar {
  background: linear-gradient(135deg, rgba(241, 248, 244, 0.96), rgba(255, 248, 238, 0.96));
}

.tabs {
  background: rgba(255, 253, 248, 0.94);
}

.card,
.stat-card,
.student-card,
.list-item {
  border-color: var(--border);
}

.button {
  background: linear-gradient(135deg, #6e9f89, #5a8775);
}

.button:hover {
  background: linear-gradient(135deg, #5d8d79, #486f60);
}

.button-secondary {
  background: #fffdf8;
}

.student-card {
  padding: 1.2rem;
}

.student-card-body {
  gap: 0.85rem;
}

.student-card-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
}

.student-card-footer {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin: 0.15rem -1.2rem -1.2rem;
  padding: 1rem 1.2rem 1.2rem;
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  background: linear-gradient(180deg, #f4f8f5, #eef5f0);
}

.student-card-footer .button,
.student-card-footer a.button {
  width: 100%;
  min-height: 40px;
  padding: 0.7rem 0.9rem;
  text-align: center;
  text-decoration: none;
  line-height: 1.2;
}

.student-card-footer .checklist-button,
.student-card-footer a.button[href*="drive.google.com"] {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 42px;
}

.user-dropdown {
  padding: 1.25rem;
}

.user-dropdown .user-summary {
  display: grid;
  gap: 0.38rem;
  padding: 0.25rem 0.15rem 1rem;
}

.user-dropdown #signOutBtn {
  width: 100%;
  margin-top: 0.35rem;
}

#students > .card > .card-heading > div:first-child > p {
  display: none;
}

.student-toolbar {
  grid-template-columns: minmax(180px, 1.35fr) minmax(165px, 0.8fr) minmax(130px, 0.65fr) auto;
}

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

.teacher-filter {
  min-width: 165px;
}

#studentFetchResult {
  transition: opacity 0.25s ease;
}

#studentFetchResult.is-fading {
  opacity: 0;
}

body.modal-open {
  overflow: hidden;
}

.student-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  width: 100vw;
  min-height: 100dvh;
  padding: clamp(0.75rem, 3vw, 2rem);
  margin: 0;
  background: rgba(32, 48, 42, 0.5);
  backdrop-filter: blur(4px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.student-modal-overlay.hidden {
  display: none;
}

.student-modal-card {
  position: relative;
  top: auto;
  width: min(720px, calc(100vw - 1.5rem));
  max-width: 100%;
  max-height: calc(100dvh - 1.5rem);
  margin: auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0;
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(29, 45, 39, 0.28);
  isolation: isolate;
}

.student-modal-enter .student-modal-card {
  animation: studentModalIn 0.38s cubic-bezier(.2,.8,.2,1);
}

@keyframes studentModalIn {
  from { opacity: 0; transform: translateY(18px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.student-modal-card > .card-heading {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0;
  padding: 1.2rem 1.25rem;
  background: linear-gradient(135deg, #deefe6, #fff0da);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255,255,255,0.85), 0 8px 18px rgba(29,45,39,0.08);
}

/* iPad/Safari can paint scrolling descendants above a translucent sticky header.
   Keep the header fully opaque and give it its own paint layer. */
.student-modal-card > .card-heading::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(135deg, #deefe6, #fff0da);
}

.student-editor-header {
  align-items: center;
}

.student-editor-header > div:first-child {
  flex: 0 1 auto;
}

.student-editor-delete {
  background: #fff6f6;
  color: var(--danger);
  border-color: #ebc9cd;
}

.student-editor-delete:hover {
  background: #fdebed;
}

.student-edit-tabs {
  display: flex;
  flex: 1 1 auto;
  justify-content: center;
  gap: 0.35rem;
  min-width: 0;
  margin: 0 0.5rem;
  padding: 0;
  background: transparent;
  border: 0;
}

.student-edit-tab {
  appearance: none;
  flex: 0 1 auto;
  padding: 0.7rem 0.75rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}

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

.student-edit-panel {
  position: relative;
  z-index: 1;
  padding: 1.2rem 1.25rem 0;
  animation: studentPanelIn 0.26s ease;
}

.student-edit-panel.hidden {
  display: none;
}

@keyframes studentPanelIn {
  from { opacity: 0; transform: translateX(10px); }
  to { opacity: 1; transform: translateX(0); }
}

.student-name-active-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: end;
}

.student-name-active-row > label:first-child {
  margin-bottom: 0.85rem;
}

.student-active-inline {
  align-self: center;
  margin: 1.35rem 0 0;
  white-space: nowrap;
}

.student-modal-card > .form-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin: 1.1rem 0 0;
  padding: 1rem 1.25rem 1.2rem;
  background: rgba(255, 253, 248, 0.97);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.student-editor-danger-actions {
  margin-left: auto;
}

.student-editor-danger-actions .button {
  white-space: nowrap;
}

.student-modal-card,
.student-modal-card *,
.student-modal-card input,
.student-modal-card select,
.student-modal-card textarea,
.student-modal-card label,
.student-modal-card .form-row,
.student-modal-card .form-row > * {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.student-modal-card input,
.student-modal-card select,
.student-modal-card textarea {
  width: 100%;
}

.student-modal-card input[type="time"] {
  width: min(100%, 190px);
  justify-self: start;
}

.statistics-disclosure {
  padding: 0;
  overflow: hidden;
}

.statistics-disclosure summary {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem 1.2rem;
  cursor: pointer;
  list-style: none;
  font-weight: 700;
  color: var(--accent-dark);
  background: linear-gradient(135deg, #edf6f1, #fff7e9);
}

.statistics-disclosure summary::-webkit-details-marker {
  display: none;
}

.statistics-summary-hint {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}

.statistics-content {
  padding: 1rem 1.2rem 1.2rem;
}

.statistics-content .stats-grid {
  margin-bottom: 1rem;
}

.statistics-content > .card {
  margin-bottom: 0;
}

.invoice-controls {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 0.9fr) minmax(220px, 1.2fr) auto;
  gap: 0.75rem;
  align-items: end;
  min-width: 0;
}

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

.invoice-controls label {
  margin-bottom: 0;
}

.invoice-controls .button {
  width: auto;
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .student-card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .student-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .student-toolbar {
    grid-template-columns: minmax(0, 1fr) minmax(165px, 0.75fr) minmax(120px, 0.6fr);
  }

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

  .student-editor-header {
    flex-wrap: wrap;
  }

  .student-editor-header > div:first-child {
    flex: 1 1 auto;
  }

  .student-edit-tabs {
    order: 3;
    flex: 1 0 100%;
    justify-content: flex-start;
    overflow-x: auto;
    margin: 0.35rem 0 0;
    scrollbar-width: none;
  }

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

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

  .invoice-controls label:nth-child(3),
  .invoice-controls .button {
    grid-column: 1 / -1;
  }

  .invoice-controls .button {
    width: 100%;
  }
}

@media (max-width: 620px) {
  .student-toolbar,
  .student-card-grid,
  .invoice-controls {
    grid-template-columns: 1fr;
  }

  .teacher-filter {
    min-width: 0;
  }

  .student-toolbar-actions {
    grid-column: 1;
    width: 100%;
  }

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

  .student-modal-overlay {
    place-items: stretch;
    padding: 0.5rem;
  }

  .student-modal-card {
    width: 100%;
    max-height: calc(100dvh - 1rem);
  }

  .student-edit-tabs {
    gap: 0.15rem;
  }

  .student-edit-tab {
    flex: 1 0 auto;
    padding-left: 0.45rem;
    padding-right: 0.45rem;
  }

  .student-edit-panel {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .student-modal-card .form-row,
  .student-name-active-row {
    grid-template-columns: 1fr;
  }

  .student-active-inline {
    margin-top: -0.2rem;
  }

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

  .student-card-footer .checklist-button,
  .student-card-footer a.button[href*="drive.google.com"] {
    grid-column: 1;
  }

  .invoice-controls label:nth-child(3),
  .invoice-controls .button {
    grid-column: 1;
  }

  .student-editor-danger-actions {
    width: 100%;
    margin-left: 0;
  }

  .student-editor-danger-actions .button {
    width: 100%;
  }
}
