:root{
  --brand-blue:#2563eb;
  --brand-green:#02b10b;
  --danger:#ef4444;
  --muted:#6b7280;
  --bg:#f7f9fc;
  --card:#fff;
  --shadow: 0 6px 20px rgba(2,6,23,0.06);
  --radius: 10px;
  --gap:12px;
  --max-width:980px;
  --form-font: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}

* { box-sizing: border-box; }
html,body { height:100%; }
body {
  font-family: var(--form-font);
  background: var(--bg);
  margin:0;
  padding:16px;
  color:#0f172a;
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
  line-height:1.4;
  font-size:15px;
}

#adminLogo img {
  height: 80px;
  display: block;
  margin: 0 auto 20px auto;
}

#signOutBtn { background: var(--danger); color:#fff; }
#signOutBtn:hover { background: var(--brand-blue); color:#fff; }

/* Container */
.container {
  max-width: var(--max-width);
  margin: 18px auto;
  padding: 20px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

/* Headings */
h1,h2 { text-align:center; color: #1e3a8a; margin:0 0 12px 0; }
h3 { margin:0 0 8px 0; font-size:1rem; color:#0f172a; }

/* School header / logos */
.school-header { display:flex; align-items:center; gap:16px; justify-content:space-between; margin-bottom:18px; }
.school-header .logo-left,
.school-header .logo-right { flex:0 0 84px; display:flex; align-items:center; justify-content:center; }
.school-header .center { flex:1; text-align:center; padding:0 12px; }
.school-header img { max-height:80px; width:auto; display:block; }

/* Forms */
form label { display:block; margin-top:14px; font-weight:600; color: #374151; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"],
select, textarea {
  width:100%;
  padding:12px 14px;
  margin-top:6px;
  border:1px solid #e6e9ef;
  border-radius:8px;
  background:#fff;
  font-size:15px;
  transition: box-shadow .18s ease, border-color .18s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-blue);
  box-shadow: 0 6px 18px rgba(37,99,235,0.12);
  background: #fff;
}

/* Calendar icon visibility (webkit) */
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(25%) sepia(45%) saturate(350%) hue-rotate(200deg);
  cursor:pointer;
}

/* Row layout for larger screens */
.form-row { display:flex; gap:var(--gap); }
.form-row .col { flex:1; }

/* Buttons */
button {
  padding:11px 16px;
  border-radius:8px;
  border: none;
  font-weight:600;
  cursor:pointer;
  font-size:15px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}
button:focus { outline: 3px solid rgba(37,99,235,0.14); outline-offset:2px; }

/* Theme buttons */
.btn-primary { background: var(--brand-green); color:#fff; }
.btn-secondary { background: var(--brand-blue); color:#fff; }
.btn-danger { background: var(--danger); color:#fff; }
.btn-warning { background:#f59e0b; color:#fff; }

/* Small helpers */
.small { font-size:0.9rem; color:var(--muted); }
.notice { padding:10px; border-radius:8px; background:#eef2ff; color:#3730a3; }

/* Table */
.table { width:100%; border-collapse:collapse; margin-top:8px; }
.table th, .table td { padding:10px 12px; border-bottom:1px solid #f1f5f9; text-align:left; vertical-align:middle; }
.table thead th { text-transform:uppercase; font-size:12px; color:var(--muted); letter-spacing:0.02em; }

/* Make table horizontally scroll on small screens */
.table-wrapper { width:100%; overflow:auto; -webkit-overflow-scrolling:touch; }

/* Modal (responsive) */
.modal { display:none; position:fixed; inset:0; z-index:1000; align-items:center; justify-content:center; }
.modal[aria-hidden="false"] { display:flex; }
.modal-overlay { position:absolute; inset:0; background:rgba(2,6,23,0.45); }
.modal-panel { position:relative; background:#fff; width:92%; max-width:920px; margin:auto; border-radius:12px; box-shadow:0 20px 50px rgba(2,6,23,0.2); z-index:1001; padding:0; outline:none; display:flex; flex-direction:column; max-height:90vh; overflow:auto; }
.modal-header { display:flex; align-items:center; justify-content:space-between; padding:12px 16px; border-bottom:1px solid #f1f5f9; background:#fafafa; border-top-left-radius:12px; border-top-right-radius:12px; }
.modal-header h2 { margin:0; font-size:1.05rem; }
.modal-close { background:transparent; border:none; font-size:20px; cursor:pointer; line-height:1; padding:8px; border-radius:6px; }
.modal-close:focus { outline: 3px solid rgba(37,99,235,0.14); }
.modal-body { padding:16px; }
.modal-section { margin-bottom:12px; }
.modal-section h3 { margin-bottom:8px; }
.modal-footer { display:flex; align-items:center; gap:12px; padding:12px 16px; border-top:1px solid #f1f5f9; background:#fff; border-bottom-left-radius:12px; border-bottom-right-radius:12px; }

/* Footer */
#footer { text-align:center; padding: 18px 8px; width:100%; color:var(--muted); }
a { text-decoration:none; color:var(--muted); font-size:0.9rem; }

/* Loading Overlay Styles */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6); /* Semi-transparent black background */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999; /* Ensure it's on top of everything */
    visibility: hidden; /* Hidden by default */
    opacity: 0;
    transition: visibility 0s, opacity 0.3s ease-in-out;
}

.loading-overlay.show {
    visibility: visible;
    opacity: 1;
}

.loading-content {
    background-color: #fff;
    padding: 30px 40px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.spinner {
    border: 5px solid #f3f3f3; /* Light grey */
    border-top: 5px solid #3498db; /* Blue */
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loadingMessage {
    font-size: 1.1rem;
    color: #333;
    font-weight: bold;
}

/* Responsive breakpoints */

/* Small devices (phones) */
@media (max-width: 740px) {

  /* container padding and logo sizing */
  .container { padding: 12px; margin: 10px auto; }
  #adminLogo { text-align:center; margin-bottom:8px; }
  #adminLogo img { max-height:64px; width:auto; display:inline-block; }

  /* hide the thead (we will show labels via CSS pseudo elements) */
  #appsTable thead { display: none; }

  #adminLogo img {
    height: 80px;
    display: block;
    margin: 0 auto 20px auto;
  }

  /* make each row a card */
  #appsTable tbody tr {
    display: block;
    border: 1px solid #eef2f6;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    background: #fff;
    box-shadow: none;
  }

  /* tds become full-width blocks and wrap text */
  #appsTable tbody tr td {
    display: block;
    padding: 6px 8px;
    border: none;
    white-space: normal;      /* allow wrapping */
    word-break: break-word;   /* break long tokens */
    font-size: 14px;
  }

  /* Inject column labels using nth-child so no HTML change is required */
  #appsTable tbody tr td:nth-child(1)::before { content: "Applicant"; display:block; font-weight:700; color:#374151; margin-bottom:6px; }
  #appsTable tbody tr td:nth-child(2)::before { content: "Class"; display:block; font-weight:700; color:#374151; margin-bottom:6px; }
  #appsTable tbody tr td:nth-child(3)::before { content: "Submitted"; display:block; font-weight:700; color:#374151; margin-bottom:6px; }
  #appsTable tbody tr td:nth-child(4)::before { content: "Status"; display:block; font-weight:700; color:#374151; margin-bottom:6px; }
  #appsTable tbody tr td:nth-child(5)::before { content: "Actions"; display:block; font-weight:700; color:#374151; margin-bottom:6px; }

  /* Make actions (View/other buttons) stack and fill width for easy tapping */
  #appsTable tbody tr td:nth-child(5) .view,
  #appsTable tbody tr td:nth-child(5) button {
    width: 100% !important;
    display: block;
    box-sizing: border-box;
    margin: 6px 0;
    padding: 10px 12px;
  }

  /* reduce header sizes inside container */
  h1, h3 { font-size: 1.05rem; }

  /* modal full screen + internal scroll on mobile */
  .modal-panel {
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    border-radius: 0 !important;
    margin: 0;
    display:flex;
    flex-direction:column;
    max-height:100vh;
  }
  .modal-body {
    overflow:auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    font-size: 14px;
  }
  .modal-footer {
    flex-direction: column;
    gap: 8px;
    padding: 12px;
  }
  .modal-footer button { width:100%; padding:10px; }

  /* loading overlay and footer adjust */
  #loadingOverlay .loading-content { padding: 14px; }
  footer#footer { font-size: 13px; padding: 12px 6px; }

  /* avoid horizontal overflow in general */
  html, body, .container, .modal-panel { overflow-x: hidden; }

  /* tighten up table cell spacing */
  .table th, .table td { padding: 8px; }
}

/* medium screens: slightly larger touch targets */
@media (min-width: 741px) and (max-width: 1024px) {
  .container { padding: 16px; }
  #adminLogo img { max-height:72px; }
  #appsTable tbody tr td { font-size: 14px; padding: 8px; }
  .modal-panel { max-width: 720px; }
  .modal-footer button { padding: 10px 12px; }
  #adminLogo img {
    height: 80px;
    display: block;
    margin: 0 auto 20px auto;
  }
}

/* Desktop: ensure table wrapper scrolls if needed (prevents page overflow) */
@media (min-width: 1025px) {
  .table-wrapper, #appsTable { max-width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
  #adminLogo img {
    height: 80px;
    display: block;
    margin: 0 auto 20px auto;
  }
}

/* Extra safety: make long text in cells truncate on very narrow screens (but still wrap) */
@media (max-width:430px) {
  #appsTable tbody tr td { font-size:13px; padding:7px; }
  #appsTable tbody tr td span.small { display:block; color:#6b7280; font-size:12px; margin-top:6px; }
  #adminLogo img {
    height: 80px;
    display: block;
    margin: 0 auto 20px auto;
  }
  .school-header .logo-left,
  .school-header .logo-right {
    display: none;           /* hide logo containers on small devices */
  }

  /* center the remaining content */
  .school-header {
    justify-content: center !important;
    gap: 8px;
    text-align: center;
    padding: 6px 8px;
  }

  /* make sure the center column uses full width */
  .school-header > .center,
  .school-header > div[style*="flex:1"] { /* fallback if center doesn't have class */
    flex: 1 1 100%;
    padding: 0 8px;
  }

  /* reduce logo image footprint if any visible elsewhere */
  #schoolLogo, #stateLogo, .school-header img {
    max-height: 56px;
    width: auto;
    display: block;
    margin: 0 auto;
  }
}

/* small visual tune: make modal close button fingertip-friendly */
.modal-close { padding:8px; border-radius:6px; }

/* keep buttons touch friendly everywhere */
button { min-height:40px; }

/* keep the app content centered on very narrow screens */
@media (max-width:360px) {
  .container { padding:10px; border-radius:6px; }
  #adminLogo img {
    height: 80px;
    display: block;
    margin: 0 auto 20px auto;
  }
  .school-header .logo-left,
  .school-header .logo-right {
    display: none;           /* hide logo containers on small devices */
  }

  /* center the remaining content */
  .school-header {
    justify-content: center !important;
    gap: 8px;
    text-align: center;
    padding: 6px 8px;
  }

  /* make sure the center column uses full width */
  .school-header > .center,
  .school-header > div[style*="flex:1"] { /* fallback if center doesn't have class */
    flex: 1 1 100%;
    padding: 0 8px;
  }

  /* reduce logo image footprint if any visible elsewhere */
  #schoolLogo, #stateLogo, .school-header img {
    max-height: 56px;
    width: auto;
    display: block;
    margin: 0 auto;
  }
}

/* Print: keep existing behavior but hide controls */
@media print {
  .modal-close, button, .no-print, #loadingOverlay { display:none !important; }
}
