/* FIF@SoM app UI — layout & components on top of tokens.css */

/* ---- App shell -------------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  gap: .9rem;
  padding: .65rem clamp(.9rem, 3vw, 1.6rem);
  border-top: 3px solid var(--c-brand-orange);
}
.app-header .brand {
  font-family: var(--fif-font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: .01em;
  text-decoration: none;
  color: #fff;
  white-space: nowrap;
}
.app-header .brand span { color: #b9b4ac; font-weight: 500; }
.app-header form.search { flex: 1 1 240px; max-width: 340px; margin: 0; }
.app-header form.search input {
  width: 100%;
  min-height: 0;
  padding: .38rem .7rem;
  font-family: var(--fif-font-body);
  font-size: .82rem;
  color: #e7e2da;
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
}
.app-header form.search input::placeholder { color: #b9b4ac; }
.app-header .spacer { flex: 1 1 auto; }
.app-header .who {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-size: .82rem;
  color: #e7e2da;
}
.app-header .who .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--c-brand-orange);
  color: #fff;
  font-family: var(--fif-font-display);
  font-weight: 600;
  font-size: .78rem;
}
.app-header .who form { margin: 0; }
.app-header .adminlink {
  color: #fff;
  text-decoration: none;
  font-family: var(--fif-font-display);
  font-size: .78rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 999px;
  padding: .2rem .6rem;
}
.app-header .adminlink:hover { background: rgba(255, 255, 255, .12); }
.app-header .who button.signout {
  background: none;
  border: 0;
  color: #b9b4ac;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}
.pill {
  font-family: var(--fif-font-display);
  font-size: .62rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, .16);
  padding: .12rem .45rem;
  border-radius: 999px;
}
@media (max-width: 620px) {
  .app-header form.search { order: 3; flex-basis: 100%; max-width: none; }
  .app-header .who .name { display: none; }
}

.page {
  max-width: 900px;
  margin: 0 auto;
  padding: clamp(1.25rem, 4vw, 2.5rem) clamp(1rem, 4vw, 1.5rem) 4rem;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  font-size: .8rem;
  color: var(--c-text-muted);
  margin-bottom: .9rem;
}
.crumbs a { color: var(--c-text-muted); text-decoration: none; }
.crumbs a:hover { color: var(--c-action); }
.crumbs .sep { color: var(--c-border-strong); }
.crumbs .here { color: var(--c-ink); font-weight: 500; }

.page > h1 {
  font-family: var(--fif-font-display);
  font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2rem);
  margin: 0 0 .2rem;
}
.page .lede { color: var(--c-text-muted); margin: 0 0 1.6rem; font-size: .95rem; }

/* ---- Programme / department grid ---------------------------------- */
.prog-label {
  font-family: var(--fif-font-display);
  font-weight: 500;
  font-size: .74rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--c-text-muted);
  margin: 1.6rem 0 .6rem;
}
.prog-label:first-of-type { margin-top: 0; }
.dept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: .8rem;
}
.dept-card {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  padding: 1rem 1.1rem;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  text-decoration: none;
  color: inherit;
}
.dept-card:hover { border-color: var(--c-action); }
.dept-card .name { font-family: var(--fif-font-display); font-weight: 600; font-size: 1.05rem; }
.dept-card .count { font-size: .82rem; color: var(--c-text-muted); }
.dept-card .roll { font-size: .76rem; color: var(--c-warning); }
.dept-card .roll.done { color: var(--c-success); }

/* ---- Course list --------------------------------------------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  margin-bottom: 1rem;
}
.toolbar .filter {
  font-family: var(--fif-font-display);
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .35rem .7rem;
  border-radius: 999px;
  border: 1px solid var(--c-border-strong);
  background: var(--c-surface);
  color: var(--c-text-muted);
  text-decoration: none;
}
.toolbar .filter.on { background: var(--c-action); color: var(--c-text-on-brand); border-color: var(--c-action); }

.course-list { border: 1px solid var(--c-border); border-radius: var(--radius-lg); overflow: hidden; }
.course-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr auto;
  gap: .3rem 1rem;
  align-items: center;
  padding: .7rem .95rem;
  border-bottom: 1px solid var(--c-border);
  text-decoration: none;
  color: inherit;
}
.course-row:last-child { border-bottom: 0; }
.course-row:hover { background: var(--c-surface-alt); }
.course-row .code { font-family: var(--fif-font-body); font-weight: 500; color: var(--c-action); }
.course-row .title { font-weight: 500; }
.course-row .coord { grid-column: 2; font-size: .8rem; color: var(--c-text-muted); }
.course-row .status { grid-row: span 2; text-align: right; }
.course-row .missing { grid-column: 2; font-size: .74rem; color: var(--c-text-muted); }
@media (max-width: 560px) {
  .course-row { grid-template-columns: 1fr auto; }
  .course-row .code { grid-column: 1; }
  .course-row .coord, .course-row .missing { grid-column: 1; }
  .course-row .status { grid-row: 1 / span 3; }
}

/* ---- Course detail ----------------------------------------------- */
.course-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: .8rem; }
.course-head .grow { flex: 1 1 260px; }
.course-head .metaline { color: var(--c-text-muted); font-size: .86rem; margin-top: .2rem; }
.course-head .metaline strong { color: var(--c-ink); font-weight: 500; }

.coverage-strip {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .8rem;
  margin: .9rem 0 .2rem;
}
.coverage-strip .fs {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-family: var(--fif-font-display);
  font-weight: 500;
  font-size: .74rem;
  color: var(--c-text-muted);
}
.coverage-strip .fs::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: .62rem;
  line-height: 1;
  flex: none;
}
.coverage-strip .fs.done { color: var(--c-ink); }
.coverage-strip .fs.done::before {
  content: "\2713";
  background: var(--c-success-bg);
  color: var(--c-success);
  border: 1px solid var(--c-success);
}
.coverage-strip .fs.todo::before { border: 1px dashed var(--c-text-muted); }

.tabs {
  display: flex;
  gap: .1rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  border-bottom: 1px solid var(--c-border);
  margin: 1.1rem 0 1rem;
}
.tab {
  font-family: var(--fif-font-display);
  font-weight: 500;
  font-size: .82rem;
  letter-spacing: .02em;
  padding: .5rem .8rem;
  border: 0;
  background: none;
  color: var(--c-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--c-action); border-bottom-color: var(--c-action); }
.tab .n { font-family: var(--fif-font-body); font-size: .72rem; color: var(--c-text-muted); }
.tab.empty { color: var(--c-text-muted); }
.tab.empty .n { font-style: italic; }

.panel { display: none; }
.panel.active { display: block; }

.filehdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  margin-bottom: .7rem;
}
.filehdr .lbl { font-family: var(--fif-font-display); font-weight: 500; font-size: .98rem; }

.file-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.file-table th {
  font-family: var(--fif-font-display);
  font-weight: 500;
  font-size: .68rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--c-text-muted);
  text-align: left;
  padding: .5rem .5rem;
  border-bottom: 1px solid var(--c-border);
}
.file-table td { padding: .55rem .5rem; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.file-table tr:last-child td { border-bottom: 0; }
.file-table .actions { display: inline-flex; gap: .5rem; align-items: center; white-space: nowrap; }
.file-table form { display: inline; margin: 0; }
.linkbtn {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--c-action);
  cursor: pointer;
  text-decoration: underline;
}
.linkbtn.danger { color: var(--c-danger); }

.empty-state {
  padding: 1.3rem 1rem;
  text-align: center;
  color: var(--c-text-muted);
  background: var(--c-surface-alt);
  border: 1px dashed var(--c-border-strong);
  border-radius: var(--radius);
  font-size: .9rem;
}

.history { margin-top: .6rem; }
.history summary { cursor: pointer; color: var(--c-text-muted); font-size: .82rem; }

.uploader {
  margin-top: .9rem;
  padding-top: .8rem;
  border-top: 1px dashed var(--c-border);
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}
.uploader input[type="file"] { font-size: .82rem; }
.uploader input[type="text"] { flex: 1 1 12rem; min-height: 0; padding: .4rem .6rem; }

/* ---- Forms ------------------------------------------------------- */
.form-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 1.2rem 1.3rem;
  box-shadow: var(--shadow-1);
}
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
@media (max-width: 560px) { .field-grid { grid-template-columns: 1fr; } }
.form-row { display: flex; flex-direction: column; gap: .3rem; }
.form-row .errorlist { margin: .1rem 0 0; padding-left: 1rem; color: var(--c-danger); font-size: .8rem; }
.form-actions { display: flex; gap: .6rem; margin-top: 1.1rem; }

/* ---- Dialog / preview ------------------------------------------- */
dialog.preview {
  width: min(880px, 94vw);
  max-height: 90vh;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
}
dialog.preview::backdrop { background: rgba(20, 18, 15, .5); }
dialog.preview .bar {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--c-border);
}
dialog.preview .bar .name { font-family: var(--fif-font-display); font-weight: 600; font-size: .95rem; }
dialog.preview .bar .spacer { flex: 1 1 auto; }
dialog.preview .body { padding: 0; }
dialog.preview iframe,
dialog.preview img { display: block; width: 100%; height: 70vh; border: 0; object-fit: contain; background: var(--c-surface-alt); }
dialog.preview .fallback { padding: 3rem 1.5rem; text-align: center; color: var(--c-text-muted); }

/* ---- Form dialog (upload / replace / new folder) ---------------- */
dialog.sheet {
  width: min(460px, 94vw);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
  box-shadow: var(--shadow-2);
}
dialog.sheet::backdrop { background: rgba(20, 18, 15, .5); }
dialog.sheet .bar {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .8rem 1.1rem;
  border-bottom: 1px solid var(--c-border);
}
dialog.sheet .bar h2 { font-family: var(--fif-font-display); font-size: 1.05rem; margin: 0; }
dialog.sheet .bar .spacer { flex: 1 1 auto; }
dialog.sheet form { margin: 0; padding: 1.1rem; display: flex; flex-direction: column; gap: .85rem; }
dialog.sheet .row { display: flex; flex-direction: column; gap: .3rem; }
dialog.sheet label {
  font-family: var(--fif-font-display);
  font-weight: 500;
  font-size: .72rem;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--c-text-muted);
}
dialog.sheet input[type="text"],
dialog.sheet input[type="file"] { width: 100%; }
dialog.sheet .hint { font-size: .8rem; color: var(--c-text-muted); margin: 0; }
dialog.sheet .foot { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .2rem; }

.folder-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---- Messages / toast ------------------------------------------ */
.messages { position: fixed; top: 1rem; right: 1rem; z-index: 50; display: flex; flex-direction: column; gap: .5rem; max-width: 340px; }
.messages li {
  list-style: none;
  padding: .65rem .9rem;
  border-radius: var(--radius);
  background: var(--c-ink);
  color: #fff;
  font-size: .86rem;
  box-shadow: var(--shadow-2);
  animation: toastin .2s ease;
}
.messages li.msg-error { background: var(--c-danger); }
.messages li.msg-success { background: var(--c-success); }
@keyframes toastin { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .messages li { animation: none; } }

/* ---- Search results ------------------------------------------- */
.result-group { margin-bottom: 1.5rem; }
.result-group h2 { font-family: var(--fif-font-display); font-size: 1rem; margin: 0 0 .5rem; }
