/* ==========================================
   CSS VARIABLES & THEMING
   ========================================== */
:root {
  /* Brand Colors */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --warning-text: #b45309;
  --danger: #dc2626;

  /* UI Colors */
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --overlay: rgba(15, 23, 42, 0.6);

  /* Typography Colors */
  --text-main: #0f172a;
  --text-muted: #64748b;

  /* Geometry */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  /* Layout */
  --max-width: 600px;
}

/* ==========================================
   RESET & BASE
   ========================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent; /* Removes blue tap highlight on mobile */
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  /* Support for iPhone notch/home bar */
  padding-bottom: env(safe-area-inset-bottom);
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px;
}

.hidden {
  display: none !important;
}

/* ==========================================
   TYPOGRAPHY & ICONS
   ========================================== */
h1, h2, h3 {
  font-weight: 600;
  color: var(--text-main);
}

svg.icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex-shrink: 0;
}

.success-icon {
  width: 56px;
  height: 56px;
  color: var(--success);
  margin-bottom: 12px;
}

/* ==========================================
   HEADER
   ========================================== */
.header {
  background: var(--primary);
  color: white;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: var(--max-width);
  margin: 0 auto;
}

.header h1 {
  font-size: 1.25rem;
  color: white;
  margin: 0;
}

/* ==========================================
   CARDS & PROGRESS BAR
   ========================================== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border: 1px solid var(--border);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.progress-header h2 {
  font-size: 1.1rem;
}

#progressText {
  font-weight: 600;
  color: var(--primary);
}

.progress-bar-container {
  background: var(--border);
  border-radius: var(--radius-full);
  height: 12px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-bar {
  background: var(--success);
  height: 100%;
  width: 0%;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-percent {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: right;
  font-weight: 500;
}

/* ==========================================
   INPUTS & FORMS
   ========================================== */
.teacher-input-wrapper {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  background: var(--card-bg);
  padding: 4px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.teacher-input {
  flex: 1;
  padding: 12px 0;
  border: none;
  background: transparent;
  font-size: 1rem;
  color: var(--text-main);
  outline: none;
}

.search-wrapper {
  position: relative;
  margin-bottom: 16px;
}

.search-wrapper svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-input {
  width: 100%;
  padding: 14px 14px 14px 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 1rem;
  background: var(--bg-color);
  transition: border-color 0.2s;
  outline: none;
}

.search-input:focus {
  border-color: var(--primary);
  background: var(--card-bg);
}

/* ==========================================
   BUTTONS
   ========================================== */
button {
  cursor: pointer;
  outline: none;
}

button:disabled {
  opacity: 0.5;
  pointer-events: none;
}

button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  transition: background-color 0.2s, transform 0.1s;
  display: block;
  width: 100%;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-large {
  padding: 16px;
  font-size: 1.125rem;
}

.btn-upload {
  padding: 14px;
  margin-top: 16px;
}

.btn-secondary {
  background: var(--bg-color);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: block;
  text-align: center;
  text-decoration: none;
  font-weight: 500;
  margin-top: 12px;
  transition: background-color 0.2s;
}

.btn-secondary:active {
  background: var(--border);
}

.icon-btn {
  background: transparent;
  border: none;
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: var(--radius-full);
  transition: background-color 0.2s;
}

.icon-btn:active {
  background: rgba(0, 0, 0, 0.1);
}

.header .icon-btn:active {
  background: rgba(255, 255, 255, 0.2);
}

.btn-icon-text {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

/* ==========================================
   STUDENT STATUS DISPLAY
   ========================================== */
.student-name-display {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
  word-break: break-word;
  line-height: 1.2;
}

.status-container {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.status-label {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 500;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 600;
}

.status-badge.pending {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.status-badge.uploaded {
  background: var(--success-bg);
  color: var(--success-text);
}

/* Success Output Area */
.success-msg {
  color: var(--success);
  font-weight: 700;
  font-size: 1.15rem;
  margin-bottom: 8px;
}

.filename-display {
  font-size: 0.875rem;
  color: var(--text-main);
  background: var(--bg-color);
  padding: 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  word-break: break-all;
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* ==========================================
   MODALS & BOTTOM SHEETS
   ========================================== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  /* Animation for overlay */
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-content.bottom-sheet {
  background: var(--card-bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 20px max(20px, env(safe-area-inset-bottom)) 20px;
  height: 85vh;
  max-height: 800px;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-content.full-screen-content {
  background: var(--card-bg);
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  animation: slideUp 0.25s ease-out;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h2 {
  font-size: 1.25rem;
}

/* ==========================================
   STUDENT LIST (Inside Modal)
   ========================================== */
.student-list {
  overflow-y: auto;
  flex: 1;
  /* Smooth scrolling for iOS */
  -webkit-overflow-scrolling: touch;
  margin: 0 -20px;
  padding: 0 20px;
}

.student-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 0.2s;
}

.student-row:last-child {
  border-bottom: none;
}

.student-row:active {
  background: var(--bg-color);
}

.student-row span:first-child {
  font-weight: 500;
  font-size: 1.05rem;
}

/* ==========================================
   CROPPER & PREVIEW SCREENS
   ========================================== */
.crop-container, .preview-container {
  flex: 1;
  min-height: 0;
  background: #000; /* Dark background for cropping focus */
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

#previewImage {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.preview-info {
  padding: 20px;
  background: var(--card-bg);
}

.warning-text {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.warning-text::before {
  content: "⚠️";
}

.modal-footer {
  padding: 16px 20px max(16px, env(safe-area-inset-bottom)) 20px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
}

/* ==========================================
   LOADING OVERLAY & SPINNER
   ========================================== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: var(--radius-full);
  animation: spin 1s cubic-bezier(0.5, 0.1, 0.4, 0.9) infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==========================================
   SCROLLBAR STYLING (For desktop viewing)
   ========================================== */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}