/* Absent list styles */
.absent-list {
  list-style: none;
  padding-left: 0;
  margin: 6px 0 0 0;
  min-height: 24px;
  border: 1px dashed var(--border);
  border-radius: 6px;
}
.absent-list.drag-over {
  background: rgba(0,0,0,0.03);
}
.absent-list .student {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.absent-list .student:last-child {
  border-bottom: none;
}
.absent-list .actions .tag {
  margin-right: 6px;
}
:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --error: #dc2626;
  --border: #e2e8f0;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, "Helvetica Neue", Arial;
}

.container { max-width: 1100px; margin: 32px auto; padding: 0 16px; }
h1, h2, h3 { margin: 0 0 12px; }
a { color: var(--accent); text-decoration: none; }

.row { display: flex; gap: 16px; align-items: center; }
.space-between { justify-content: space-between; }
.gap { gap: 8px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin: 16px 0;
  box-shadow: 0 1px 2px rgba(16,24,40,0.06), 0 1px 3px rgba(16,24,40,0.1);
}

label { display: block; margin: 8px 0 6px; color: var(--muted); }
input[type="file"], input[type="number"], button { width: 100%; }
input, button, select {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
/* Consistent focus style across inputs */
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
/* Narrower width specifically for the group size field */
#group_size { width: 100px; }
#class-name { width: 140px; }

textarea {
  width: 100%;
  min-height: 140px;
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  transition: all 0.2s ease;
}

textarea.drag-over {
  border-color: var(--accent);
  background: #f0f9ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
select { width: 100%; }
/* Improve theme dropdown appearance */
/* Ensure cross-browser appearance reset */
#theme {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: #ffffff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M6 8l4 4 4-4' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px 16px;
  padding-right: 36px; /* room for arrow */
  height: 40px;
  line-height: 1.2;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  cursor: pointer;
}
#theme:hover { border-color: #cbd5e1; }
/* Hide number input spinners/arrows */
/* Chrome, Safari, Edge, Opera */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
/* Firefox */
input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}
button { cursor: pointer; background: var(--accent); color: #fff; border-color: transparent; }
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(20%);
}

.flash { list-style: none; padding: 0; margin: 0 0 16px; }
.flash li { padding: 8px 12px; border-radius: 6px; }
.flash .error { background: #fee2e2; border: 1px solid #fecaca; color: #7f1d1d; }
.flash-bump { animation: flashBump 300ms ease-in-out; }
.flash-fade { animation: flashFade 600ms ease-in-out forwards; }
@keyframes flashBump {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}
@keyframes flashFade {
  from { opacity: 1; }
  to { opacity: 0; }
}

.dashboard { display: grid; grid-template-columns: 280px 1fr; gap: 16px; }
.sidebar { position: sticky; top: 16px; height: fit-content; }
.groups-shell { display: flex; flex-direction: column; }
.groups-shell .groups-toolbar { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 8px; }
.size-field { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.size-field .stepper { display: inline-flex; gap: 6px; }
.size-field .stepper button { width: 36px; height: 28px; border-radius: 8px; padding: 0; }
.groups-area { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); column-gap: 12px; row-gap: 8px; align-items: start; }
.placeholder { grid-column: 1 / -1; text-align: center; padding: 24px; color: var(--muted); }
.group { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin: 0; align-self: start; }
.group header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.group header h2 { font-size: 16px; }

.group-warning {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 12px;
  color: #92400e;
  display: flex;
  align-items: center;
  gap: 6px;
}

.warning-icon {
  font-size: 14px;
}

.student-list { list-style: none; padding: 0; margin: 0; min-height: 12px; }
.student-list.drag-over { outline: 2px dashed var(--accent); border-radius: 8px; }
.student { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; margin: 6px 0; background: #ffffff; border: 1px solid var(--border); border-radius: 8px; }
.student.dragging { opacity: 0.6; }
.student .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.student .tag { 
  font-size: 12px; 
  color: #ffffff; 
  border: none; 
  padding: 3px 8px; 
  border-radius: 999px; 
  margin-left: 8px; 
  background: #f8fafc; 
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.student .actions { display: inline-flex; align-items: center; gap: 6px; }
.student.is-locked { outline: 2px dashed var(--accent); background: #eef2ff; }
.lock-btn { 
  background: #fff; 
  color: var(--text); 
  border: 1px solid var(--border); 
  padding: 4px 8px; 
  border-radius: 6px; 
  min-width: 32px;
  width: 32px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.lock-btn:hover { border-color: var(--accent); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 999px; background: var(--muted); margin-right: 6px; }
.dot.locked { background: var(--accent); }

pre { background: #f8fafc; border: 1px solid var(--border); padding: 8px; border-radius: 8px; overflow-x: auto; }

/* Saved classes styles */
.saved-classes {
  margin: 12px 0;
}

.saved-classes label {
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text);
}

/* Class list styles */
.class-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.class-item {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
}

.class-content {
  flex: 1;
  cursor: pointer;
}

.class-item:hover {
  background: #e0f2fe;
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.example-class {
  background: #f0f9ff;
  border-color: #7dd3fc;
}

.example-class:hover {
  background: #e0f2fe;
  border-color: #0ea5e9;
}

.class-name {
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

.class-meta {
  font-size: 12px;
  color: var(--muted);
}

.more-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.2s;
  width: 100%;
}

.more-btn:hover {
  background: #1d4ed8;
}

.delete-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 14px;
  transition: all 0.2s ease;
  margin-left: 8px;
  min-width: 24px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.delete-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* Modal styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.close-btn {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  width: auto;
  line-height: 1;
}

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

.modal-content {
  max-height: 60vh;
  overflow-y: auto;
  padding: 0;
}

.file-item {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background-color 0.2s;
}

.file-content {
  flex: 1;
  cursor: pointer;
}

.file-item:hover {
  background: #f8fafc;
}

.file-item:last-child {
  border-bottom: none;
}

.file-name {
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

.file-meta {
  font-size: 12px;
  color: var(--muted);
}

/* Credits footer */
.credits {
  margin-top: 32px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
  text-align: center;
}

.credits p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.credits a {
  color: var(--accent);
  text-decoration: none;
}

.credits a:hover {
  text-decoration: underline;
}

@media print {
  @page {
    margin: 1.5cm;
    size: auto;
  }

  body {
    background: #fff;
    color: #000;
    font-family: "Cambria", "Times New Roman", "Times", serif;
    font-size: 11pt;
    line-height: 1.3;
  }

  /* Hide UI elements */
  .sidebar, .groups-toolbar, .credits, #save-class, #load-file-link, .student-view-btn, 
  .upsell, .site-header, .warning-icon, .group-warning, h1 {
    display: none !important;
  }
  
  /* Retain h1 if it's the main title, but user might want a custom header? 
     Let's keep h1 but ensure it looks professional */
  header h1 {
    display: block !important;
    text-align: center;
    font-size: 18pt;
    margin-bottom: 0.5cm;
    font-weight: bold;
    color: #000;
  }

  .container {
    max-width: none;
    margin: 0;
    padding: 0;
    width: 100%;
  }

  .dashboard {
    display: block;
    grid-template-columns: none;
  }

  .groups-shell {
    display: block;
  }
  
  /* Grid layout for groups */
  #groups.groups-area {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 columns looks good on A4 */
    column-gap: 1cm;
    row-gap: 0.5cm;
    display: block; /* Fallback */
    columns: 2 auto; /* Multi-column layout handles breaks better than grid sometimes */
  }

  .group {
    break-inside: avoid;
    page-break-inside: avoid;
    background: transparent;
    border: 1px solid #000;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    margin-bottom: 0.5cm;
    display: inline-block; /* For columns */
    width: 100%;
  }

  .group header {
    background: #f0f0f0; /* Light grey header like a table header */
    border-bottom: 1px solid #000;
    padding: 4px 8px;
    margin: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .group header h2 {
    font-family: "Cambria", "Times New Roman", serif;
    font-size: 12pt;
    font-weight: bold;
    margin: 0;
    text-transform: none; /* or uppercase for LaTeX table feel? */
  }

  .group header small {
    display: none; /* Hide count */
  }

  .student-list {
    margin: 0;
    padding: 0;
  }

  .student {
    border: none;
    border-bottom: 1px solid #ddd;
    border-radius: 0;
    margin: 0;
    padding: 4px 8px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 10pt;
  }

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

  .student .name {
    font-weight: normal;
  }

  .student .actions {
    display: flex;
    gap: 4px;
    align-items: center;
  }

  /* Hide buttons */
  .lock-btn, .absent-btn, .present-btn, .close-btn {
    display: none !important;
  }
  
  /* Style the tag */
  .student .tag {
    background: transparent !important;
    color: #444 !important;
    padding: 0;
    margin: 0;
    font-size: 9pt;
    font-style: italic;
    border-radius: 0;
    font-weight: normal;
    text-shadow: none;
  }
  
  /* Format tag as (Program) */
  .student .tag::before { content: "("; }
  .student .tag::after { content: ")"; }

  /* Locked styles needed? No, print the result */
  .student.is-locked {
    background: transparent;
    outline: none;
  }
}