/* ============================================================
   Homeworks — Homework submission platform
   Style: minimalist, light, single accent color
   Class contract defined in PLAN.md §6
   ============================================================ */

/* ---------- 1. Variables ---------- */
:root {
  /* Palette */
  --bg:            #f7f7f5;
  --surface:       #ffffff;
  --text:          #1c1c1e;
  --muted:         #6e7268;
  --border:        #e4e2dc;
  --accent:        #27476e;   /* navy */
  --accent-hover:  #1b3554;
  --accent-soft:   #eaf0f7;
  --ok:            #2e7d4f;
  --ok-soft:       #e7f4ec;
  --warn:          #9a6a00;
  --warn-soft:     #fdf3dc;
  --danger:        #b3372e;
  --danger-soft:   #fbe9e7;

  /* Shape */
  --radius:        10px;
  --radius-sm:     7px;
  --shadow:        0 1px 2px rgba(28, 28, 30, .05), 0 4px 14px rgba(28, 28, 30, .05);
  --shadow-hover:  0 2px 4px rgba(28, 28, 30, .07), 0 8px 22px rgba(28, 28, 30, .09);

  /* Typography */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Spacing */
  --space: 1rem;
  --max-width: 880px;
}

/* ---------- 2. Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img, video { max-width: 100%; display: block; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }

p { margin: 0 0 1rem; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- 3. Layout ---------- */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.25rem;
}

main.container { flex: 1; padding-top: 2rem; padding-bottom: 3rem; }

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .9rem 0;
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
}
.site-title:hover { text-decoration: none; }

/* Breadcrumb: class › task context */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: .85rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { opacity: .5; }
.breadcrumb [aria-current] { color: var(--text); font-weight: 600; }

.footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 0;
  font-size: .8rem;
  color: var(--muted);
  text-align: center;
}

.page-head { margin-bottom: 1.75rem; }
.page-head .muted { margin-top: -.25rem; }

/* ---------- 4. Cards (optional) ---------- */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem;
  color: var(--text);
  transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}
a.card:hover {
  text-decoration: none;
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
  border-color: #d3d0c8;
}

.card-title { font-size: 1.05rem; font-weight: 650; margin: 0 0 .3rem; }
.card-meta  { font-size: .85rem; color: var(--muted); margin: 0; }
.card-badges { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .7rem; }

/* ---------- 5. Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1;
  padding: .32rem .55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.badge--info   { background: var(--accent-soft); color: var(--accent); }
.badge--ok     { background: var(--ok-soft);     color: var(--ok); }
.badge--warn   { background: var(--warn-soft);   color: var(--warn); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- 6. Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  font: inherit;
  font-size: .95rem;
  font-weight: 600;
  padding: .62rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.btn:hover { text-decoration: none; }

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }

.btn--ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--border);
}
.btn--ghost:hover { background: var(--accent-soft); border-color: var(--accent); }

.btn--danger { background: var(--danger-soft); color: var(--danger); }
.btn--danger:hover { background: #f5d6d2; }

.btn--block { width: 100%; }

.btn--sm { padding: .3rem .6rem; font-size: .8rem; }

.btn[disabled], .btn[aria-disabled="true"] {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---------- 7. Forms ---------- */
.form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  display: grid;
  gap: 1.15rem;
}

.field { display: grid; gap: .35rem; }

.label { font-size: .9rem; font-weight: 600; }
.label .req { color: var(--danger); margin-left: .15rem; }

.input, select.input, textarea.input {
  font: inherit;
  font-size: .95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .55rem .7rem;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[aria-invalid="true"] { border-color: var(--danger); }

/* Student-name field inside the admin table (needs a readable desktop width) */
.input--name { min-width: 140px; }

.hint { font-size: .8rem; color: var(--muted); margin: 0; }
.error-text { font-size: .8rem; color: var(--danger); margin: 0; display: none; }
.field.has-error .error-text { display: block; }

/* Student ID group (individual / pairs / group) */
.student-ids {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .75rem;
}

/* Vertical stack of related inputs (e.g. PPT Group topics) */
.stack {
  display: grid;
  gap: .5rem;
}

/* Upload zone: <label class="dropzone"> containing <input type="file"> */
.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .45rem;
  text-align: center;
  padding: 1.6rem 1rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--muted);
  font-size: .9rem;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone:focus-within {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.dropzone input[type="file"] {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  overflow: hidden;
}
.dropzone .dropzone-title { font-weight: 600; color: var(--text); }
.dropzone .dropzone-file  { font-weight: 600; color: var(--ok); word-break: break-all; }

/* ---------- 8. Alerts ---------- */
.alert {
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  padding: .8rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  border: 1px solid transparent;
  margin-bottom: 1.25rem;
}
.alert p { margin: 0; }
.alert--error   { background: var(--danger-soft); color: var(--danger); border-color: #eec5c0; }
.alert--success { background: var(--ok-soft);     color: var(--ok);     border-color: #c6e2d1; }
.alert--warn    { background: var(--warn-soft);   color: var(--warn);   border-color: #eedcaa; }

/* ---------- 9. Confirmation ---------- */
.summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .95rem;
}
.summary-row:last-child { border-bottom: 0; }
.summary-key   { color: var(--muted); flex-shrink: 0; }
.summary-value { font-weight: 600; text-align: right; word-break: break-word; }

/* ---------- 10. Admin / dashboard ---------- */
.admin-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.filters {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.filters .field { min-width: 200px; }

.counters {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.counter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .55rem .9rem;
  font-size: .85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
}
.counter .num { font-size: 1.05rem; }

/* Draw calendar (admin) */
.calendar {
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: .75rem;
}
.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem .75rem;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
}
.cal-head strong { font-size: 1rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-dow, .cal-day, .cal-blank {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.cal-grid > :nth-child(7n) { border-right: 0; }
.cal-dow {
  padding: .4rem 0;
  text-align: center;
  font-size: .7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  background: var(--bg);
}
.cal-blank { background: var(--bg); }
.cal-day {
  font: inherit;
  font-size: .95rem;
  height: 3rem;
  padding: 0;
  background: var(--surface);
  border-top: 0;
  border-left: 0;
  border-radius: 0;
  cursor: pointer;
}
.cal-day.is-weekend { background: var(--bg); color: var(--muted); }
.cal-day.is-today { font-weight: 700; color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent-soft); }
.cal-day:hover { background: var(--accent-soft); }
.cal-day.is-on, .cal-day.is-on:hover { background: var(--accent); color: #fff; font-weight: 700; }
.cal-picked { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: .5rem; min-height: 1.9rem; }
.cal-picked .badge { cursor: pointer; }

/* Draw topics (admin, drag and drop) */
.topic-list { display: flex; flex-direction: column; gap: .5rem; }
.topic-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .55rem .75rem;
  cursor: grab;
}
.topic-row.is-over { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent-soft); }
.topic-row.is-excluded { opacity: .55; }
.topic-row.is-excluded .topic-name { text-decoration: line-through; }
.topic-main { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.topic-grip { color: var(--muted); user-select: none; }
.topic-name { flex: 1; min-width: 12rem; }
.topic-excl { font-size: .8rem; color: var(--muted); white-space: nowrap; cursor: pointer; }
.topic-chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .45rem; padding-left: 1.4rem; }
.topic-chip {
  font-size: .8rem;
  padding: .15rem .55rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
}
.topic-chip.is-merged { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); cursor: grab; }
.topic-x { font: inherit; border: 0; background: none; color: inherit; cursor: pointer; padding: 0 .1rem; }
.topic-sim { font-size: .78rem; margin-top: .3rem; padding-left: 1.4rem; }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.table th, .table td {
  text-align: left;
  padding: .65rem .9rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  background: var(--bg);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafaf8; }

/* Long file names / topic lists wrap instead of stretching the table */
.table td[data-label="Details"] { white-space: normal; overflow-wrap: anywhere; }

.status {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .8rem;
  font-weight: 600;
}
.status::before { content: ""; width: .55rem; height: .55rem; border-radius: 50%; background: currentColor; }
.status--ok      { color: var(--ok); }
.status--late    { color: var(--warn); }
.status--missing { color: var(--danger); }

/* ---------- 11. Utilities ---------- */
.muted { color: var(--muted); }
.text-center { text-align: center; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.actions-row {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

/* ---------- 12. Responsive ---------- */
@media (max-width: 560px) {
  h1 { font-size: 1.3rem; }
  .form { padding: 1.15rem; }
  .summary-row { flex-direction: column; gap: .1rem; }
  .summary-value { text-align: left; }
  .grid-cards { grid-template-columns: 1fr; }
  .dropzone { padding: 1.25rem .75rem; }
}

/* iOS/Android auto-zoom: form controls under 16px trigger a focus zoom.
   Applies to touch devices and to narrow viewports (older browsers). */
@media (pointer: coarse), (max-width: 560px) {
  .input, select.input, textarea.input { font-size: 16px; }

  /* Comfortable touch targets (~40px) without changing the desktop look */
  .btn--sm { padding: .5rem .85rem; font-size: .875rem; }
}

/* Tables → stacked cards on phones/tablets.
   Column labels come from each <td data-label="…">. */
@media (max-width: 700px) {
  .table-wrap {
    background: transparent;
    border: 0;
    box-shadow: none;
    overflow-x: visible;
  }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { display: none; }

  .table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: .75rem;
    padding: .2rem .95rem;
  }
  .table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .35rem .75rem;
    white-space: normal;
    padding: .6rem 0;
    border-bottom: 1px solid var(--border);
  }
  /* Each <tr> is its own card → only its last cell drops the divider */
  .table tr td:last-child { border-bottom: 0; }

  .table td[data-label]::before {
    content: attr(data-label);
    font-size: .72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
  }
  /* Cells without a label (actions, empty state) stand alone */
  .table td:not([data-label]) { justify-content: flex-end; }
  .table td[colspan] { display: block; text-align: center; padding: .75rem 0; }

  /* Inline forms inside cells: let them use the full remaining width */
  .table td form { flex: 1 1 auto; min-width: 0; }
  .table td form .input { flex: 1 1 auto; min-width: 0; }
  /* …but action-only cells keep their button aligned to the right */
  .table td:not([data-label]) form { flex: 0 1 auto; margin-left: auto; }
}

/* ---------- 13. Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
