:root {
  color-scheme: light;
  --bg: #f4f7f9;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #596a75;
  --line: #cbd5dc;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --soft: #eef6f5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

body:not(.is-logged-in) .app-content {
  display: none !important;
}

body.is-logged-in .login-screen {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.login-screen {
  min-height: calc(100vh - 48px);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(760px, 100%);
  padding: 30px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 55px rgba(23, 33, 43, .12);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 18px;
}

.login-logo {
  display: block;
  width: 86px;
  height: 86px;
}

.login-logo-official {
  width: 118px;
  height: 118px;
  margin: 0 auto 10px;
  object-fit: contain;
  border-radius: 999px;
}

.login-rrhh-logo {
  display: block;
  width: min(360px, 86%);
  height: auto;
  margin: 0 auto 18px;
  object-fit: contain;
}

.login-card h1 {
  margin-bottom: 8px;
  text-align: center;
}

.login-card .eyebrow {
  text-align: center;
}

.login-subtitle {
  max-width: 560px;
  margin: 0 auto 22px;
  color: var(--muted);
  line-height: 1.5;
  text-align: center;
}

.toolbar,
.panel,
.report-page {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  margin-bottom: 16px;
}

.toolbar-title {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  min-width: 260px;
}

.toolbar-brand {
  display: flex;
  gap: 8px;
  padding-top: 2px;
}

.toolbar-brand img {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 24px;
}

.panel h2 {
  margin-bottom: 12px;
  font-size: 16px;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  padding: 8px 12px;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.panel {
  padding: 16px;
  margin-bottom: 16px;
}

.metadata-grid,
.staff-form,
.import-box,
.access-grid,
.kpi-grid,
.admin-grid {
  display: grid;
  gap: 12px;
}

.access-grid {
  grid-template-columns: 1fr 1fr;
  align-items: end;
}

.access-grid button,
.access-grid #sessionInfo {
  grid-column: 1 / -1;
}

#userRoleWrap,
#userSchoolWrap {
  display: none;
}

body.show-internal-login #userRoleWrap {
  display: block;
}

.link-button {
  min-height: auto;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  justify-self: center;
  padding: 2px 0;
}

.link-button:hover {
  border-color: transparent;
  text-decoration: underline;
}

.role-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
}

.director-context {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.director-context strong {
  color: var(--ink);
  font-size: 18px;
}

.director-context span {
  display: block;
}

.director-context .is-saved {
  color: var(--accent);
  font-weight: 700;
}

.dashboard-panel[hidden],
#exportExcelBtn[hidden],
#printBtn[hidden],
#visadoBtn[hidden],
#submitBtn[hidden],
#printDocument[hidden] {
  display: none !important;
}

.kpi-grid {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  margin-bottom: 14px;
}

.kpi-grid article,
.admin-grid article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.kpi-grid strong {
  display: block;
  font-size: 24px;
}

.kpi-grid span,
.admin-grid span {
  color: var(--muted);
}

.admin-grid {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  margin-bottom: 14px;
}

.admin-actions {
  margin-bottom: 14px;
}

.conei-config {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto minmax(220px, 1fr);
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid #bddbd8;
  border-radius: 6px;
  background: var(--soft);
}

.conei-config span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  align-self: center;
}

.admin-grid strong {
  display: block;
  margin-bottom: 6px;
}

.dashboard-table {
  max-height: 360px;
}

#directorAccessTable,
#rrhhTable {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
  font-size: 12px;
}

#directorAccessTable th,
#directorAccessTable td,
#rrhhTable th,
#rrhhTable td {
  border: 1px solid var(--line);
  padding: 6px;
  text-align: left;
}

#directorAccessTable th,
#rrhhTable th {
  background: #e7edf1;
}

.metadata-grid {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}

.staff-form {
  grid-template-columns: 120px minmax(250px, 2fr) repeat(5, minmax(130px, 1fr));
  align-items: end;
}

.import-box {
  grid-template-columns: minmax(320px, 1fr) auto auto;
  align-items: end;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--soft);
  border: 1px solid #bddbd8;
  border-radius: 6px;
}

.import-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  align-self: center;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

label.wide {
  grid-column: span 2;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  padding: 8px 10px;
  text-transform: none;
}

.report-page {
  margin-bottom: 18px;
  padding: 24px;
}

.office-page {
  min-height: 980px;
}

.letterhead {
  display: grid;
  justify-items: center;
  gap: 4px;
  margin-bottom: 32px;
  text-align: center;
}

.letterhead p {
  margin-bottom: 10px;
  font-weight: 700;
}

.letterhead h2 {
  margin-bottom: 2px;
  font-size: 22px;
}

.letterhead span,
.recipient span,
.format-header span {
  display: block;
}

.office-date {
  margin-bottom: 24px;
  text-align: right;
}

.office-number {
  margin-bottom: 26px;
  font-weight: 700;
}

.recipient {
  display: grid;
  gap: 3px;
  margin-bottom: 22px;
}

.recipient p {
  margin-bottom: 0;
}

.subject {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 10px;
  margin-bottom: 20px;
  text-align: justify;
}

.office-body {
  max-width: 900px;
  line-height: 1.65;
  text-align: justify;
}

.signature-block {
  display: grid;
  justify-items: center;
  margin-top: 44px;
  page-break-inside: avoid;
}

.signature-box {
  width: 300px;
  height: 280px;
  display: grid;
  place-items: end center;
  border-bottom: 1px solid var(--ink);
  overflow: visible;
}

.signature-img {
  display: none;
  width: 340px;
  height: auto;
  max-width: 340px;
  max-height: 150px;
  object-fit: contain;
}

.signature-img[src] {
  display: block;
}

.signature-block p {
  margin: 8px 0 2px;
  font-weight: 700;
}

.signature-block span,
.report-footer {
  color: var(--muted);
}

.format-header {
  display: grid;
  justify-items: center;
  gap: 4px;
  margin-bottom: 10px;
  text-align: center;
}

.norm-title {
  max-width: 1180px;
  font-size: 11px;
  line-height: 1.25;
  text-align: center;
}

.format-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 80px;
  width: 100%;
  margin-top: 6px;
  text-align: left;
}

.format-meta span {
  border-bottom: 1px solid #222;
  padding-bottom: 2px;
}

.format-meta .wide {
  grid-column: 1 / -1;
}

.format-header p,
.format-header h2 {
  margin-bottom: 0;
  font-size: 15px;
}

.format-header h2 {
  font-size: 16px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
}

.attendance-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  font-size: 11px;
}

.annex04-table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  font-size: 10px;
}

.attendance-table th,
.attendance-table td,
.annex04-table th,
.annex04-table td {
  border: 1px solid var(--line);
  padding: 4px;
  text-align: center;
  vertical-align: middle;
  white-space: pre-line;
}

.attendance-table th,
.annex04-table th {
  background: #e7edf1;
  font-weight: 700;
}

.num-col {
  width: 30px;
}

.dni-col {
  width: 78px;
}

.name-col {
  min-width: 210px;
  text-align: left !important;
}

.role-col {
  min-width: 120px;
  text-align: left !important;
}

.condition-col,
.hours-col {
  width: 75px;
}

.note-col {
  color: #111827;
  font-weight: 700;
  text-align: left !important;
}

.attendance-table select {
  min-width: 34px;
  width: 34px;
  min-height: 28px;
  border-radius: 4px;
  padding: 2px;
  text-align: center;
}

.weekend {
  background: #f6efe3;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 12px;
  font-size: 12px;
}

.legend span {
  white-space: nowrap;
}

.legend b {
  color: var(--accent-dark);
}

.annex-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.report-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: flex-end;
  gap: 16px;
  margin-top: 22px;
  page-break-inside: avoid;
}

.footer-place-date {
  justify-self: start;
}

.visado-stamp {
  display: none;
  min-width: 118px;
  min-height: 74px;
  border: 3px double #0f766e;
  border-radius: 50%;
  color: #0f766e;
  text-align: center;
  transform: rotate(-8deg);
  padding: 11px 10px 8px;
  font-weight: 700;
  text-transform: uppercase;
  justify-self: end;
  grid-column: 3;
}

.visado-stamp.is-visible {
  display: grid;
  place-items: center;
}

.visado-stamp strong {
  font-size: 18px;
  line-height: 1;
}

.visado-stamp span,
.visado-stamp small {
  display: block;
  font-size: 10px;
}

.mini-signature {
  display: grid;
  justify-items: center;
  width: 260px;
  min-width: 260px;
  border-top: 1px solid var(--ink);
  padding-top: 4px;
  color: var(--ink);
  font-weight: 700;
  grid-column: 2;
  overflow: visible;
}

.mini-signature .signature-img[src] {
  margin-top: -132px;
  margin-bottom: 4px;
  width: 330px;
  height: auto;
  max-width: 330px;
  max-height: 124px;
}

.empty-report {
  color: var(--muted);
  min-height: 240px;
}

@media (max-width: 1100px) {
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-title {
    align-items: center;
  }

  .metadata-grid,
  .staff-form,
  .import-box,
  .access-grid,
  .conei-config,
  .kpi-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  label.wide {
    grid-column: auto;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 18px, 1500px);
    padding-top: 9px;
  }

  .login-card {
    padding: 22px 18px;
  }

  .login-logo {
    width: 70px;
    height: 70px;
  }

  .toolbar-title {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 9mm;
  }

  @page oficio {
    size: A4 portrait;
    margin: 18mm 18mm 14mm;
  }

  @page asistencia {
    size: A4 landscape;
    margin: 9mm;
  }

  body {
    background: #fff;
    color: #000;
  }

  .no-print {
    display: none !important;
  }

  .app-shell {
    width: auto;
    padding: 0;
  }

  .report-page {
    border: 0;
    border-radius: 0;
    margin: 0;
    min-height: 185mm;
    padding: 0;
    page-break-after: always;
  }

  .office-page {
    page: oficio;
    min-height: 260mm;
    padding: 0;
  }

  .attendance-page {
    page: asistencia;
  }

  .table-wrap {
    overflow: visible;
  }

  .annex04-table,
  .attendance-table {
    min-width: 0;
    font-size: 8px;
  }

  .attendance-table th,
  .attendance-table td,
  .annex04-table th,
  .annex04-table td {
    border-color: #777;
    padding: 2px;
  }

  .attendance-table select {
    appearance: none;
    border: 0;
    min-width: 16px;
    width: 16px;
    min-height: 16px;
    padding: 0;
    background: transparent;
    color: #000;
    text-align: center;
  }

  .name-col {
    min-width: 120px;
  }

  .role-col {
    min-width: 84px;
  }

  .format-header p,
  .format-header h2 {
    font-size: 10px;
  }

  .norm-title {
    font-size: 8px;
  }

  .format-meta {
    gap: 2px 40px;
    font-size: 8px;
  }

  .format-header span,
  .legend,
  .report-footer {
    font-size: 9px;
  }

  .compact .attendance-table {
    font-size: 7px;
  }

  .annex-note {
    font-size: 8px;
  }
}
