:root {
  color-scheme: light;
  --navy: #17375e;
  --navy-dark: #102a49;
  --blue-soft: #eaf0f8;
  --border: #cbd5e1;
  --border-dark: #9aaabd;
  --text: #172033;
  --muted: #5d6878;
  --background: #f5f7fa;
  --white: #ffffff;
  --success: #17603a;
  --success-bg: #e9f7ef;
  --danger: #a12626;
  --danger-bg: #fff0f0;
  --shadow: 0 8px 26px rgba(23, 55, 94, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: var(--background);
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

.page-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--navy);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 5px;
  font-size: clamp(1.65rem, 4vw, 2.35rem);
  line-height: 1.1;
}

h2 {
  margin-bottom: 4px;
  color: var(--navy-dark);
  font-size: 1.15rem;
}

.lead,
.muted,
.field-hint {
  color: var(--muted);
}

.lead {
  margin-bottom: 0;
}

.muted {
  margin-bottom: 0;
  font-size: 0.88rem;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--navy);
  border-radius: 7px;
  padding: 10px 17px;
  color: var(--white);
  background: var(--navy);
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.button:hover {
  background: var(--navy-dark);
}

.button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(42, 102, 173, 0.28);
  outline-offset: 2px;
}

.button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.button-secondary {
  color: var(--navy);
  background: var(--white);
}

.button-secondary:hover {
  color: var(--white);
}

.button-install {
  border-color: #23724a;
  background: #23724a;
}

.button-install:hover {
  border-color: #185738;
  background: #185738;
}

.button-small {
  min-height: 38px;
  padding: 8px 13px;
  font-size: 0.88rem;
}

.button-full {
  width: 100%;
}

.button-danger {
  border-color: #c43d3d;
  color: var(--danger);
  background: var(--white);
}

.button-danger:hover {
  color: var(--white);
  background: var(--danger);
}

.totals-line {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.public-totals {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.totals-line p {
  display: flex;
  min-height: 92px;
  align-items: flex-start;
  justify-content: center;
  flex-direction: column;
  gap: 7px;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-top: 4px solid var(--navy);
  border-radius: 10px;
  padding: 14px 17px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.totals-line p + p {
  border-left: 1px solid var(--border);
}

.totals-line span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.totals-line strong {
  color: var(--navy);
  font-size: 1.65rem;
  line-height: 1;
  white-space: nowrap;
}

.totals-line .total-days {
  border-top-color: #7651a8;
  background: linear-gradient(145deg, #ffffff 55%, #f2ecfa);
}

.totals-line .total-days strong {
  color: #5b3a9b;
}

.totals-line .total-load {
  border-top-color: var(--navy);
  background: linear-gradient(145deg, #ffffff 55%, #eaf0f8);
}

.totals-line .total-taught {
  border-top-color: #2b73b7;
  background: linear-gradient(145deg, #ffffff 55%, #e6f1fc);
}

.totals-line .total-taught strong {
  color: #1f5f9d;
}

.totals-line .total-remaining {
  border-top-color: #d17a18;
  background: linear-gradient(145deg, #ffffff 55%, #fff1dc);
}

.totals-line .total-remaining strong {
  color: #a45608;
}

.content-panel {
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 20px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.filters,
.header-actions,
.form-actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.status-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: -3px 0 15px;
  color: var(--muted);
  font-size: 0.77rem;
}

.status-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  display: inline-block;
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #7b8794;
}

.dot-progress {
  background: #2b73b7;
}

.dot-near {
  background: #d17a18;
}

.dot-complete {
  background: #298654;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  padding: 9px 11px;
  color: var(--text);
  background: var(--white);
}

.filters select {
  width: 180px;
}

.filters input,
#history-search {
  width: min(300px, 42vw);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-dark);
  border-radius: 6px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 10px 11px;
  vertical-align: middle;
  text-align: left;
}

.data-table th:last-child,
.data-table td:last-child {
  border-right: 0;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table thead th {
  color: var(--white);
  background: var(--navy);
  font-size: 0.77rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}

.data-table tbody tr:nth-child(even) {
  background: #f7f9fc;
}

.data-table tbody tr:hover {
  background: var(--blue-soft);
}

.data-table .number-cell {
  text-align: center;
  white-space: nowrap;
}

.data-table .remaining-zero {
  color: var(--success);
  font-weight: 800;
}

.public-table .status-not-started td:last-child {
  color: #526071;
  background: #edf1f5;
  font-weight: 800;
}

.public-table .status-progress td:last-child {
  color: #174f87;
  background: #e5f0fb;
  font-weight: 800;
}

.public-table .status-near td:last-child {
  color: #92500b;
  background: #fff1d7;
  font-weight: 800;
}

.public-table .status-complete td:last-child {
  color: #17603a;
  background: #e4f4ea;
  font-weight: 800;
}

.public-table {
  min-width: 920px;
}

.public-table th:nth-child(3),
.public-table td:nth-child(3) {
  min-width: 310px;
}

.message {
  margin: 12px 0;
  border: 1px solid #e7baba;
  border-radius: 6px;
  padding: 11px 13px;
  color: var(--danger);
  background: var(--danger-bg);
}

.message.success {
  border-color: #acd5bd;
  color: var(--success);
  background: var(--success-bg);
}

.login-panel {
  width: min(440px, 100%);
  margin: 64px auto 0;
}

.stack-form {
  display: grid;
  gap: 10px;
}

label {
  color: var(--navy-dark);
  font-size: 0.9rem;
  font-weight: 700;
}

.admin-totals {
  margin-top: 4px;
}

.launch-form {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 15px;
}

.field {
  display: grid;
  align-content: start;
  gap: 7px;
}

.field-wide {
  grid-column: 1 / -1;
}

.field-hint {
  min-height: 18px;
  font-size: 0.8rem;
}

.optional {
  color: var(--muted);
  font-weight: 500;
}

.history-table {
  min-width: 900px;
}

.history-table th:nth-child(3),
.history-table td:nth-child(3) {
  min-width: 270px;
}

.history-table th:nth-child(5),
.history-table td:nth-child(5) {
  min-width: 220px;
}

.row-actions .button {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 0.79rem;
}

.empty-cell {
  padding: 28px !important;
  color: var(--muted);
  text-align: center !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  .page-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 18px;
  }

  .page-header,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    flex-wrap: wrap;
  }

  .header-actions .button {
    flex: 1 1 150px;
  }

  .totals-line {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .totals-line p {
    min-height: 88px;
    padding: 13px;
  }

  .totals-line p + p {
    border-left: 1px solid var(--border);
  }

  .content-panel {
    padding: 15px;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    border-radius: 0;
  }

  .public-table,
  .history-table {
    display: block;
    min-width: 0;
  }

  .public-table thead,
  .history-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
  }

  .public-table tbody,
  .history-table tbody {
    display: grid;
    gap: 12px;
  }

  .public-table tbody tr,
  .history-table tbody tr {
    display: grid;
    overflow: hidden;
    border: 1px solid var(--border-dark);
    border-radius: 8px;
    background: var(--white);
  }

  .public-table tbody tr {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-left-width: 5px;
  }

  .public-table tbody tr.status-not-started {
    border-left-color: #7b8794;
  }

  .public-table tbody tr.status-progress {
    border-left-color: #2b73b7;
  }

  .public-table tbody tr.status-near {
    border-left-color: #d17a18;
  }

  .public-table tbody tr.status-complete {
    border-left-color: #298654;
  }

  .public-table th:nth-child(3),
  .public-table td:nth-child(3),
  .history-table th:nth-child(3),
  .history-table td:nth-child(3),
  .history-table th:nth-child(5),
  .history-table td:nth-child(5) {
    min-width: 0;
  }

  .public-table td,
  .history-table td {
    display: grid;
    min-width: 0;
    gap: 3px;
    overflow-wrap: anywhere;
    border-right: 0;
    border-bottom: 0;
    padding: 10px;
  }

  .public-table td:not(.empty-cell)::before,
  .history-table td:not(.empty-cell)::before {
    color: var(--muted);
    font-size: 0.67rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .public-table td:nth-child(1) {
    grid-column: 1;
    order: -2;
  }

  .public-table td:nth-child(1)::before {
    content: "Nº";
  }

  .public-table td:nth-child(2) {
    grid-column: 2 / 4;
    order: -2;
  }

  .public-table td:nth-child(2)::before {
    content: "Módulo";
  }

  .public-table td:nth-child(3) {
    grid-column: 1 / -1;
    order: -3;
    color: var(--navy-dark);
    background: var(--blue-soft);
    font-size: 0.98rem;
    font-weight: 800;
  }

  .public-table td:nth-child(3)::before {
    content: "Disciplina";
  }

  .public-table td:nth-child(4) {
    grid-column: 1 / -1;
    order: -1;
    border-top: 1px solid var(--border);
  }

  .public-table td:nth-child(4)::before {
    content: "Modalidade";
  }

  .public-table td:nth-child(5),
  .public-table td:nth-child(6),
  .public-table td:nth-child(7) {
    margin: 6px 3px 9px;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 9px 7px;
    text-align: left;
  }

  .public-table td:nth-child(5) {
    margin-left: 8px;
    background: #f2f5f9;
  }

  .public-table td:nth-child(6) {
    border-color: #b9d4ee;
    color: #174f87;
    background: #e8f2fc;
    font-weight: 800;
  }

  .public-table td:nth-child(7) {
    margin-right: 8px;
  }

  .public-table td:nth-child(5)::before {
    content: "Carga";
  }

  .public-table td:nth-child(6)::before {
    content: "Ministradas";
  }

  .public-table td:nth-child(7)::before {
    content: "Restantes";
  }

  .history-table tbody tr {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-table td:nth-child(1)::before {
    content: "Data";
  }

  .history-table td:nth-child(2)::before {
    content: "Módulo";
  }

  .history-table td:nth-child(3) {
    grid-column: 1 / -1;
    grid-row: 1;
    color: var(--navy-dark);
    background: var(--blue-soft);
    font-weight: 800;
  }

  .history-table td:nth-child(3)::before {
    content: "Disciplina";
  }

  .history-table td:nth-child(4)::before {
    content: "Aulas";
  }

  .history-table td:nth-child(5) {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border);
  }

  .history-table td:nth-child(5)::before {
    content: "Observação";
  }

  .history-table td:nth-child(6) {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border);
  }

  .history-table td:nth-child(6)::before {
    content: "Ações";
  }

  .empty-cell {
    grid-column: 1 / -1 !important;
  }

  .filters {
    align-items: stretch;
    flex-direction: column;
  }

  .filters select,
  .filters input,
  #history-search {
    width: 100%;
  }

  .launch-form {
    grid-template-columns: 1fr;
  }

  .field,
  .field-wide {
    grid-column: 1;
  }

  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-actions .button {
    width: 100%;
  }
}

@media print {
  body {
    background: #fff;
  }

  .page-shell {
    width: 100%;
    padding: 0;
  }

  .button,
  .filters {
    display: none !important;
  }

  .content-panel,
  .totals-line {
    box-shadow: none;
  }

  .table-wrap {
    overflow: visible;
  }

  .public-table {
    min-width: 0;
    font-size: 8pt;
  }
}
