:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --ink: #1d2b27;
  --muted: #62736e;
  --line: #dde4e1;
  --brand: #1f6f5c;
  --brand-dark: #165244;
  --brand-soft: #e3f1ec;
  --warn: #b45309;
  --warn-soft: #fdf1dc;
  --info: #1d5fa8;
  --info-soft: #e2eefb;
  --danger: #b3261e;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Tahoma, "Segoe UI", "Noto Naskh Arabic", "Geeza Pro", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

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

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.3; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 1rem; }
main.wrap { padding-top: 1.25rem; padding-bottom: 3rem; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
bdi { unicode-bidi: isolate; }

/* header */
.top { background: var(--brand); color: #fff; }
.top .bar { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; padding-block: .6rem; }
.top a { color: #fff; }
.brand { font-weight: 700; font-size: 1.1rem; }
.brand small { font-weight: 400; opacity: .8; margin-inline-start: .4rem; }
.top nav { display: flex; gap: 1rem; flex: 1; }
.top nav a { opacity: .9; padding: .15rem .1rem; border-bottom: 2px solid transparent; }
.top nav a:hover, .top nav a.active { opacity: 1; border-bottom-color: #fff; text-decoration: none; }
.who { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }

/* controls */
button, .btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: .45rem .9rem;
  border-radius: 8px;
  display: inline-block;
  line-height: 1.4;
}
button:hover, .btn:hover { border-color: var(--brand); text-decoration: none; }
button:disabled { opacity: .6; cursor: not-allowed; }
.btn.primary, button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover, button.primary:hover { background: var(--brand-dark); }
button.danger { color: var(--danger); }
button.link { background: none; border: none; color: inherit; padding: 0; text-decoration: underline; }
.top button.link { color: #fff; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: .5rem .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus, button:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
textarea { min-height: 90px; resize: vertical; }
label { display: block; margin-bottom: .85rem; font-weight: 600; font-size: .95rem; }
label > input, label > select, label > textarea { margin-top: .3rem; font-weight: 400; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
label.check input { width: auto; margin: 0; }

.error { color: var(--danger); margin: .25rem 0 .75rem; }

/* cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .card { width: 100%; max-width: 380px; margin: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .85rem; }
.class-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  color: var(--ink);
}
.class-card:hover { border-color: var(--brand); text-decoration: none; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.class-card .title { font-weight: 700; font-size: 1.05rem; }
.class-card .meta { color: var(--muted); font-size: .875rem; margin-top: .25rem; }

/* chips */
.chip {
  display: inline-block;
  padding: .1rem .6rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  background: var(--brand-soft);
  color: var(--brand-dark);
  white-space: nowrap;
}
.chip.retry_requested { background: var(--warn-soft); color: var(--warn); }
.chip.resubmitted { background: var(--info-soft); color: var(--info); }
.chip.none { background: #eceeed; color: var(--muted); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .85rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.2; }

/* yearly overview */
.ov-row { display: flex; align-items: flex-start; gap: .75rem; padding: .5rem 0; border-top: 1px solid var(--line); }
.ov-row:first-child { border-top: 0; }
.ov-grade { width: 6.5rem; font-weight: 700; padding-top: .35rem; flex-shrink: 0; }
.ov-cells { display: flex; flex-wrap: wrap; gap: .5rem; }
.ycell {
  display: flex; flex-direction: column; gap: .15rem; min-width: 118px;
  padding: .4rem .65rem; border: 1px solid var(--line); border-radius: 10px;
  color: var(--ink); background: #fafbfa; font-size: .85rem;
}
.ycell:hover { border-color: var(--brand); text-decoration: none; }
.ycell b { font-size: .95rem; }

/* lists */
.alert { background: var(--warn-soft); border: 1px solid #efd29c; border-radius: var(--radius); padding: .9rem 1.1rem; margin-bottom: 1.25rem; }
.alert h2 { color: var(--warn); }
.row-link { display: block; padding: .5rem 0; border-top: 1px solid rgba(0,0,0,.08); color: var(--ink); }
.row-link:first-of-type { border-top: 0; }
.row-link:hover { text-decoration: none; }
.row-link:hover strong { text-decoration: underline; }

.tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.tabs a {
  padding: .4rem .9rem; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--line); color: var(--ink); font-size: .95rem;
}
.tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tabs a:hover { text-decoration: none; border-color: var(--brand); }
.tabs .count { opacity: .75; font-size: .8rem; margin-inline-start: .25rem; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }

.doc {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem 1rem; margin-bottom: .6rem;
}
.doc-main { flex: 1 1 260px; min-width: 0; }
.doc-main strong { overflow-wrap: anywhere; }
.doc-side { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }

.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* dialog */
dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 1.5rem));
  max-height: calc(100vh - 2rem); color: var(--ink); background: var(--surface);
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(10, 25, 20, .5); }
.dlg-head { display: flex; align-items: flex-start; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.dlg-head h2 { flex: 1; margin: 0; overflow-wrap: anywhere; }
.dlg-body { padding: 1rem 1.25rem 1.25rem; overflow-y: auto; max-height: calc(100vh - 8rem); }
.dlg-foot { display: flex; gap: .5rem; justify-content: flex-start; margin-top: .5rem; }

.version { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .45rem 0; border-top: 1px solid var(--line); }
.version:first-of-type { border-top: 0; }
.version .grow { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }

.comment { padding: .6rem .8rem; border-radius: 10px; background: #f3f6f5; margin-bottom: .5rem; }
.comment.coordinator { background: var(--brand-soft); }
.comment.retry { background: var(--warn-soft); }
.comment .who2 { font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }
.comment p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

#toast {
  position: fixed; inset-inline: 0; bottom: 1.25rem; margin-inline: auto; width: fit-content; max-width: 90vw;
  background: #1d2b27; color: #fff; padding: .6rem 1.1rem; border-radius: 10px; z-index: 1000;
}
#toast.err { background: var(--danger); }

table.simple { width: 100%; border-collapse: collapse; }
table.simple td, table.simple th { text-align: start; padding: .5rem .4rem; border-top: 1px solid var(--line); }

@media (max-width: 560px) {
  .ov-row { flex-direction: column; gap: .25rem; }
  .ov-grade { width: auto; padding-top: 0; }
  .top nav { order: 3; flex-basis: 100%; }
}
