/* ======================================================
   THEME VARIABLES
====================================================== */
:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --primary: #1e40af;
  --primary-dark: #1e3a8a;
  --accent: #2563eb;
  --muted: #6b7280;
  --border: #e5e7eb;
  --success-bg: #dcfce7;
  --danger-bg: #fee2e2;
  --info-bg: #eef2ff;
  --radius: 12px;
}

/* ======================================================
   AUTO SCREEN ADJUST (GLOBAL)
====================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: clamp(13px, 1.2vw, 16px);
}

body {
  background: var(--bg);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  color: #111827;
  padding: 12px;
  overflow-x: hidden;
  min-height: 100vh;
}

/* ======================================================
   CONTAINER
====================================================== */
.container {
  width: 100%;
  max-width: min(820px, 96vw);
  margin: 14px auto;
  background: var(--card);
  padding: clamp(16px, 3vw, 32px);
  border-radius: var(--radius);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.08);
}

/* ======================================================
   TOP BAR
====================================================== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.topbar h2 {
  font-size: clamp(17px, 2.5vw, 22px);
  font-weight: 700;
  color: var(--primary-dark);
}

/* ======================================================
   PAGE HEADING
====================================================== */
h2 {
  font-size: clamp(16px, 2.2vw, 21px);
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 18px;
}

/* ======================================================
   ADMIN BUTTON (FIXED)
====================================================== */
.admin-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  z-index: 9999;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.admin-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.4);
}

/* ======================================================
   BUTTONS
====================================================== */
button,
.college-btn,
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: inline-block;
}

button:hover,
.college-btn:hover,
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.35);
}

button.secondary,
.btn-grey {
  background: #6b7280;
  color: #fff;
}

button.secondary:hover,
.btn-grey:hover {
  background: #4b5563;
  transform: translateY(-1px);
}

/* ======================================================
   FLASH MESSAGES
====================================================== */
.flash {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 16px;
  line-height: 1.5;
}

.flash.success {
  background: var(--success-bg);
  color: #065f46;
  border-left: 4px solid #16a34a;
}

.flash.error {
  background: var(--danger-bg);
  color: #991b1b;
  border-left: 4px solid #dc2626;
}

.flash.info {
  background: var(--info-bg);
  color: #1e40af;
  border-left: 4px solid var(--primary);
}

/* ======================================================
   FORMS
====================================================== */
form {
  width: 100%;
}

/* Responsive 2-col grid for step 1 */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
}

.form-grid .full-width {
  grid-column: 1 / -1;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 5px;
  margin-top: 14px;
}

label small {
  font-weight: 400;
  color: var(--muted);
  font-size: 11px;
}

/* INPUTS */
input[type="text"],
input[type="email"],
input[type="date"],
input[type="number"],
input[type="tel"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  background: #fff;
  color: #111827;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

input[type="file"] {
  padding: 8px 10px;
  cursor: pointer;
}

textarea {
  resize: vertical;
  min-height: 75px;
}

small.muted {
  font-size: 12px;
  color: var(--muted);
  display: block;
  margin-top: 3px;
}

/* ======================================================
   VALIDATION STATES
====================================================== */
.input-error {
  border: 2px solid #dc2626 !important;
  background: #fff5f5 !important;
}

.error-text {
  font-size: 12px;
  color: #dc2626;
  margin-top: 4px;
  display: block;
}

/* ======================================================
   ACTIONS ROW
====================================================== */
.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ======================================================
   PROGRESS BAR
====================================================== */
.progress-wrap {
  margin: 12px 0 22px;
}

.progress {
  height: 8px;
  background: #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.4s ease;
  border-radius: 6px;
}

.progress-steps {
  display: flex;
  justify-content: space-between;
  margin-top: 7px;
}

.step-label {
  font-size: 13px;
  color: var(--muted);
}

.step-label.active {
  color: var(--primary);
  font-weight: 600;
}

/* ======================================================
   STEP VISIBILITY
====================================================== */
.step {
  display: none !important;
}

.step.active {
  display: block !important;
}

/* ======================================================
   CONDITIONAL SECTIONS (KEA / MANAGEMENT)
====================================================== */
.hidden {
  display: none !important;
}

#kea_section,
#management_section,
#kea_doc,
#management_doc {
  display: none;
}

#kea_section:not(.hidden),
#management_section:not(.hidden),
#kea_doc:not(.hidden),
#management_doc:not(.hidden) {
  display: block !important;
}

/* ======================================================
   PREVIEW MODAL
====================================================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: 16px;
}

.modal.hidden {
  display: none !important;
}

.modal-content {
  background: #fff;
  width: 95%;
  max-width: 600px;
  max-height: 88vh;
  overflow-y: auto;
  padding: clamp(16px, 3vw, 28px);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18);
}

.modal-content h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 16px;
}

#previewContent p {
  font-size: 13.5px;
  margin-bottom: 7px;
  color: #374151;
  line-height: 1.5;
}

/* ======================================================
   ERROR POPUP MODAL
====================================================== */
#errorModal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 99999;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#errorModal.show {
  display: flex;
}

#errorBox {
  background: #fff;
  border-radius: 12px;
  padding: 28px 26px 22px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

#errorBox h3 {
  margin: 0 0 14px;
  color: #dc2626;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

#errorBox ul {
  margin: 0 0 18px;
  padding-left: 20px;
  color: #374151;
  font-size: 13.5px;
  line-height: 1.8;
}

#errorBox .close-err {
  display: block;
  width: 100%;
  padding: 10px;
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  transition: background 0.15s ease;
}

#errorBox .close-err:hover {
  background: #b91c1c;
}

/* ======================================================
   UPLOAD OVERLAY
====================================================== */
.upload-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99998;
}

.upload-overlay.hidden {
  display: none !important;
}

.upload-overlay.active {
  display: flex !important;
}

.upload-box {
  text-align: center;
  background: #ffffff;
  padding: clamp(20px, 4vw, 36px) clamp(24px, 5vw, 48px);
  border-radius: var(--radius);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.14);
}

.upload-box p {
  margin-top: 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  line-height: 1.6;
}

/* Spinner */
.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid #e5e7eb;
  border-top: 5px solid var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Blur form while uploading */
.form-blur {
  filter: blur(2px);
  pointer-events: none;
}

/* ======================================================
   TABLES (ADMIN)
====================================================== */
.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
  font-size: 14px;
}

.table th {
  background: #f1f5f9;
  padding: 12px 14px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  font-weight: 700;
  color: #1e293b;
  white-space: nowrap;
}

.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: #374151;
}

.table tr:hover td {
  background: #f9fafb;
}

.center {
  text-align: center;
  color: var(--muted);
}

/* ======================================================
   DOWNLOAD BUTTON
====================================================== */
.download-btn {
  display: inline-block;
  margin-top: 20px;
  padding: 12px 24px;
  background: linear-gradient(135deg, #16a34a, #22c55e);
  color: #fff;
  font-weight: 700;
  border-radius: 10px;
  text-decoration: none;
  font-size: 14px;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.download-btn:hover {
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.38);
  transform: translateY(-1px);
}

/* ======================================================
   RESPONSIVE BREAKPOINTS
====================================================== */

/* Tablets */
@media (max-width: 1024px) {
  .topbar h2 {
    font-size: 19px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .full-width {
    grid-column: 1;
  }

  .table {
    font-size: 13px;
  }

  .table th,
  .table td {
    padding: 9px 10px;
  }

  .actions {
    flex-direction: column;
  }

  button,
  .college-btn,
  .btn-primary,
  .btn-grey {
    width: 100%;
    text-align: center;
  }

  .modal-content {
    padding: 16px;
  }
}

/* Small Mobile */
@media (max-width: 420px) {
  html {
    font-size: 13px;
  }

  .container {
    padding: 14px;
  }

  label {
    font-size: 12px;
  }

  .progress-steps {
    font-size: 11px;
  }
}

/* ======================================================
   STEP 2 — UPLOAD CARDS
====================================================== */
.upload-intro {
  font-size: 13.5px;
  color: var(--muted);
  margin-bottom: 18px;
}

.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 600px) {
  .upload-grid { grid-template-columns: 1fr; }
}

.upload-card {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 16px 14px 14px;
  background: #fafbff;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}

.upload-card:hover {
  border-color: var(--accent);
  background: #f0f5ff;
  box-shadow: 0 4px 14px rgba(37,99,235,0.08);
}

.upload-card--done {
  border-color: #16a34a !important;
  border-style: solid !important;
  background: #f0fdf4 !important;
}

.upload-card--error {
  border-color: #dc2626 !important;
  border-style: solid !important;
  background: #fff5f5 !important;
}

/* Icon */
.upload-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #e0e7ff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.upload-icon-wrap.pdf-icon {
  background: #fee2e2;
}

.upload-icon-wrap.pdf-icon .upload-icon-svg {
  stroke: #dc2626;
}

.upload-icon-svg {
  width: 20px;
  height: 20px;
  stroke: var(--primary);
}

/* Label group */
.upload-label-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.upload-title {
  font-size: 13.5px;
  font-weight: 700;
  color: #1e293b;
}

.upload-title .req {
  color: #dc2626;
  font-size: 13px;
}

.upload-hint {
  font-size: 11.5px;
  color: var(--muted);
}

/* Choose file button */
.upload-btn-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
  align-self: flex-start;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
  user-select: none;
}

.upload-btn-label:hover {
  box-shadow: 0 4px 12px rgba(37,99,235,0.3);
  transform: translateY(-1px);
}

.upload-card--done .upload-btn-label {
  background: #16a34a;
}

/* Hide the native input */
.upload-hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* File preview area */
.file-preview {
  margin-top: 2px;
}

.fp-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

/* Image thumbnail */
.fp-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

/* PDF badge */
.fp-pdf-badge {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: #fee2e2;
  color: #dc2626;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

/* File info */
.fp-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.fp-name {
  font-size: 12.5px;
  font-weight: 600;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
  display: block;
}

.fp-size {
  font-size: 11px;
  color: var(--muted);
}

/* Remove button */
.fp-remove {
  background: #fee2e2;
  color: #dc2626;
  border: none;
  border-radius: 6px;
  width: 26px;
  height: 26px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s ease;
}

.fp-remove:hover {
  background: #fca5a5;
}

/* ── UPLOAD SUMMARY BAR ── */
.upload-summary {
  margin-top: 18px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
}

.upload-summary-bar {
  flex: 1;
  height: 6px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
}

.upload-summary-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #22c55e);
  border-radius: 4px;
  width: 0%;
  transition: width 0.4s ease;
}