:root {
  --portal-bg: #eef3f8;
  --portal-surface: #ffffff;
  --portal-text: #0f172a;
  --portal-muted: #64748b;
  --portal-primary: #1268b3;
  --portal-accent: #0f8b6f;
  --portal-border: #dbe4ee;
  --portal-shadow: 0 18px 42px rgba(15, 23, 42, .10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--portal-bg);
  color: var(--portal-text);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

.portal-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.portal-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  background: #162033;
  color: #fff;
  overflow: auto;
}

.portal-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px 20px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eaf6ff;
  color: var(--portal-primary);
  font-size: 22px;
  font-weight: 950;
}

.portal-brand strong,
.portal-brand small {
  display: block;
}

.portal-brand small {
  color: #b7c5d7;
  margin-top: 2px;
}

.portal-nav {
  display: grid;
  gap: 8px;
}

.portal-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #e6eef8;
  text-decoration: none;
  font-weight: 850;
  transition: background .15s ease, transform .15s ease;
}

.portal-link:hover,
.portal-link.active {
  background: #eaf6ff;
  color: #0b4f8a;
  transform: translateX(-2px);
}

.portal-link i {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, .10);
}

.portal-link.active i,
.portal-link:hover i {
  background: #d7ebff;
}

.portal-main {
  padding: 18px;
}

.portal-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  margin-bottom: 14px;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  background: var(--portal-surface);
  box-shadow: var(--portal-shadow);
}

.portal-topbar h1 {
  margin: 2px 0 0;
  font-size: 24px;
  font-weight: 950;
}

.eyebrow {
  color: var(--portal-accent);
  font-size: 12px;
  font-weight: 950;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #eef7f4;
  color: #0b6b58;
  font-weight: 850;
}

.portal-hero {
  min-height: 170px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 100px;
  gap: 16px;
  align-items: center;
  padding: 22px;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(18, 104, 179, .12), rgba(15, 139, 111, .08)), #fff;
  box-shadow: var(--portal-shadow);
}

.portal-hero h2 {
  margin: 6px 0;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.18;
  font-weight: 950;
}

.portal-hero p {
  margin: 0;
  color: var(--portal-muted);
  line-height: 1.8;
}

.portal-hero-icon {
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eef6ff;
  color: var(--portal-primary);
  font-size: 38px;
}

.portal-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.portal-card {
  grid-column: span 4;
  min-height: 132px;
  padding: 16px;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--portal-shadow);
}

.portal-card.wide {
  grid-column: span 8;
}

.portal-card.full {
  grid-column: span 12;
}

.portal-card h3,
.portal-card h4 {
  margin: 0 0 12px;
  font-weight: 950;
}

.portal-entry {
  color: var(--portal-text);
  text-decoration: none;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}

.portal-entry:hover {
  transform: translateY(-2px);
  border-color: rgba(18, 104, 179, .35);
  box-shadow: 0 22px 48px rgba(15, 23, 42, .14);
}

.portal-entry > i {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin-bottom: 12px;
  border-radius: 8px;
  background: #eef6ff;
  color: var(--portal-primary);
  font-size: 24px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  min-height: 92px;
  padding: 12px;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  background: #f8fbff;
}

.metric span,
.empty-state {
  color: var(--portal-muted);
  font-weight: 750;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  font-weight: 950;
}

.portal-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.portal-tab {
  border: 1px solid var(--portal-border);
  background: #fff;
  color: var(--portal-text);
  border-radius: 8px;
  min-height: 40px;
  padding: 8px 12px;
  font-weight: 850;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
}

.portal-tab.active {
  border-color: rgba(18, 104, 179, .35);
  background: #eaf6ff;
  color: var(--portal-primary);
}

.portal-tab i {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(18, 104, 179, .08);
  color: var(--portal-primary);
}

.portal-action-panel {
  padding: 14px;
  border: 1px solid rgba(18, 104, 179, .18);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(18, 104, 179, .08), rgba(15, 139, 111, .06)), #fff;
}

.portal-action-panel h4 {
  margin-bottom: 10px;
}

.portal-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  align-items: end;
}

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

.health-excuse-children,
.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.health-child-chip,
.attachment-list a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  padding: 9px 12px;
  background: #fff;
  color: #152033;
  text-decoration: none;
}

.health-child-chip.active {
  border-color: var(--portal-accent);
  background: rgba(15, 139, 111, .10);
  color: #064f48;
}

.health-child-chip input {
  margin: 0;
}

.portal-hero-icon.small {
  width: 42px;
  height: 42px;
  font-size: 24px;
}

.portal-form-grid .btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 850;
}

.portal-bulk-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.portal-bulk-toolbar .btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 850;
}

.portal-bulk-table {
  margin-bottom: 12px;
  overflow: auto;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  background: #fff;
}

.portal-bulk-table table {
  min-width: 780px;
  margin: 0;
}

.portal-bulk-table th {
  background: #eaf2fb;
  color: #152033;
  font-weight: 950;
  white-space: nowrap;
}

.portal-bulk-table td {
  vertical-align: middle;
}

.portal-bulk-table .form-control-sm {
  min-height: 34px;
  border-radius: 8px;
}

.portal-table {
  overflow: hidden;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
}

.portal-table table {
  width: 100%;
  table-layout: fixed;
  margin: 0;
}

.portal-table th {
  background: #1f2d42;
  color: #fff;
  white-space: normal;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.portal-table td {
  white-space: normal;
  line-height: 1.55;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.portal-tabs {
  position: sticky;
  top: 10px;
  z-index: 5;
  padding: 8px;
  border: 1px solid var(--portal-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(10px);
}

.portal-tab {
  min-width: 0;
}

.portal-tab span,
.portal-tab strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 850;
}

.btn-primary,
.btn-outline-primary,
.btn-outline-danger {
  border-radius: 8px;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.btn-primary:hover,
.btn-outline-primary:hover,
.btn-outline-danger:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, .12);
}

.profile-stack {
  display: grid;
  gap: 6px;
}

.profile-stack strong {
  font-size: 20px;
  font-weight: 950;
}

.profile-stack span {
  color: var(--portal-muted);
  font-weight: 750;
}

.learning-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.learning-card {
  min-height: 150px;
  display: grid;
  align-content: start;
  gap: 7px;
  padding: 14px;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  background: #f8fbff;
}

.learning-card-alert {
  border-color: rgba(180, 35, 24, .36);
  background: #fff7f5;
}

.learning-card-warning {
  border-color: rgba(181, 71, 8, .36);
  background: #fffbeb;
}

.learning-card-done {
  border-color: rgba(15, 139, 111, .30);
  background: #f1fbf7;
}

.learning-card strong {
  font-size: 17px;
  font-weight: 950;
}

.learning-card small {
  color: var(--portal-muted);
  font-weight: 750;
}

.learning-type {
  width: fit-content;
  padding: 5px 9px;
  border-radius: 999px;
  background: #eaf6ff;
  color: var(--portal-primary);
  font-size: 12px;
  font-weight: 950;
}

.learning-state {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(15, 139, 111, .12);
  color: var(--portal-accent);
}

.portal-upload-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(180px, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px dashed rgba(18, 104, 179, .35);
  border-radius: 8px;
  background: #f8fbff;
}

.uploaded-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.uploaded-files a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--portal-border);
  border-radius: 999px;
  background: #fff;
  color: var(--portal-primary);
  text-decoration: none;
  font-weight: 850;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 2px;
  padding: 4px 8px;
  border: 1px solid var(--portal-border);
  border-radius: 999px;
  background: #fff;
  color: var(--portal-primary);
  text-decoration: none;
  font-weight: 850;
  white-space: nowrap;
}

.metric-row.single {
  grid-template-columns: 1fr;
}

.form-control,
.btn {
  border-radius: 8px;
}

@media (max-width: 1000px) {
  .portal-shell {
    grid-template-columns: 1fr;
  }

  .portal-sidebar {
    position: static;
    height: auto;
  }

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

  .portal-card,
  .portal-card.wide,
  .portal-card.full {
    grid-column: span 2;
  }

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

  .portal-upload-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .portal-main {
    padding: 10px;
  }

  .portal-topbar,
  .portal-hero {
    display: block;
  }

  .topbar-actions {
    margin-top: 12px;
    flex-wrap: wrap;
  }

  .portal-grid,
  .metric-row {
    grid-template-columns: 1fr;
  }

  .portal-card,
  .portal-card.wide,
  .portal-card.full {
    grid-column: span 1;
  }

  .portal-hero-icon {
    margin-top: 14px;
  }
}

/* RTL table/tab and print safety pass. */
.portal-table {
  max-width: 100%;
  overflow-x: auto;
}

.portal-table table {
  direction: rtl;
  text-align: start;
  min-width: min(760px, 100%);
}

.portal-tabs {
  align-items: stretch;
}

.portal-tab {
  flex: 1 1 150px;
  justify-content: center;
  text-align: start;
}

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

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

  .portal-sidebar,
  .portal-topbar,
  .portal-tabs,
  .portal-action-panel,
  .portal-upload-panel,
  .topbar-actions,
  .btn {
    display: none !important;
  }

  .portal-shell {
    display: block !important;
  }

  .portal-main {
    padding: 0 !important;
  }

  .portal-card,
  .portal-table {
    box-shadow: none !important;
    border: 0 !important;
    overflow: visible !important;
  }

  .portal-table table {
    min-width: 0 !important;
    width: 100% !important;
    table-layout: auto !important;
    border-collapse: collapse !important;
    font-size: 10px;
  }

  .portal-table th,
  .portal-table td {
    background: #fff !important;
    color: #000 !important;
    border: 1px solid #999 !important;
    padding: 5px 6px !important;
    overflow-wrap: anywhere;
  }
}

/* Portal UX polish: clearer hierarchy, safer RTL wrapping, and visible health workflows. */
:root {
  --portal-primary-dark: #07558e;
  --portal-accent-dark: #066854;
  --portal-shadow-soft: 0 10px 26px rgba(15, 23, 42, .08);
}

:where(.portal-link, .portal-tab, .btn, .form-control, .form-select, .health-child-chip, .attachment-list a):focus-visible {
  outline: 3px solid rgba(18, 104, 179, .24);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(18, 104, 179, .10);
}

.portal-sidebar {
  background: linear-gradient(180deg, #102036, #172942);
  box-shadow: 14px 0 34px rgba(15, 23, 42, .14);
}

.portal-brand {
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  margin-bottom: 12px;
}

.brand-mark {
  border-radius: 10px;
  background: linear-gradient(135deg, #eaf6ff, #e8f7f3);
}

.portal-topbar,
.portal-hero,
.portal-card,
.portal-action-panel,
.portal-table,
.portal-bulk-table {
  border-radius: 12px;
  box-shadow: var(--portal-shadow-soft);
}

.portal-hero {
  min-height: 154px;
  background: linear-gradient(135deg, #ffffff, #f2f8fd 58%, #edf8f5);
}

.portal-hero h2 {
  letter-spacing: 0;
}

.portal-card {
  border-color: #d6e3ee;
}

.portal-card h3,
.portal-card h4 {
  color: #081827;
}

.metric {
  border-color: #d8e6f0;
  background: linear-gradient(180deg, #fff, #f7fbff);
}

.metric strong {
  color: #081827;
}

.portal-tabs {
  gap: 10px;
  border-color: #d6e3ee;
}

.portal-tab {
  min-height: 44px;
  border-color: #d6e3ee;
  background: #fbfdff;
  transition: transform .15s ease, border-color .15s ease, background .15s ease, color .15s ease;
}

.portal-tab:hover {
  border-color: rgba(18, 104, 179, .35);
  background: #eef7ff;
  transform: translateY(-1px);
}

.portal-tab.active {
  border-color: rgba(15, 139, 111, .45);
  background: #e8f7f3;
  color: var(--portal-accent-dark);
  box-shadow: inset 0 -3px 0 var(--portal-accent);
}

.portal-tab.active i {
  background: #d7f4ec;
  color: var(--portal-accent-dark);
}

.portal-action-panel {
  border-color: rgba(15, 139, 111, .24);
  background: linear-gradient(135deg, #ffffff, #f4fbf8);
}

.portal-action-panel:has(.health-excuse-children) {
  border-color: rgba(15, 139, 111, .34);
  background: linear-gradient(135deg, #ffffff, #f2fbf8 62%, #eef7ff);
}

.portal-action-panel:has(.health-excuse-children) .portal-hero-icon.small {
  background: #e1f6ef;
  color: var(--portal-accent-dark);
  box-shadow: inset 0 0 0 1px rgba(15, 139, 111, .18);
}

.health-excuse-children {
  padding: 10px;
  border: 1px dashed rgba(15, 139, 111, .28);
  border-radius: 12px;
  background: rgba(255, 255, 255, .62);
}

.health-child-chip {
  min-height: 42px;
  border-radius: 999px;
  font-weight: 850;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}

.health-child-chip:hover {
  transform: translateY(-1px);
  border-color: rgba(15, 139, 111, .42);
}

.health-child-chip.active {
  border-color: rgba(15, 139, 111, .52);
  background: #e8f7f3;
  color: var(--portal-accent-dark);
  box-shadow: inset 0 0 0 1px rgba(15, 139, 111, .12);
}

.portal-table {
  border-color: #d6e3ee;
}

.portal-table th {
  background: #17283d;
}

.portal-table td,
.portal-table th {
  padding: 11px 12px;
  vertical-align: middle;
}

.portal-table tbody tr:hover {
  background: #eef7ff;
}

.portal-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 4px 10px;
  border: 1px solid rgba(18, 104, 179, .18);
  border-radius: 999px;
  background: #edf7ff;
  color: var(--portal-primary-dark);
  font-size: 12px;
  font-weight: 950;
  line-height: 1.2;
}

.portal-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
  opacity: .78;
}

.learning-card {
  border-radius: 12px;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.learning-card:hover {
  transform: translateY(-2px);
  border-color: rgba(18, 104, 179, .30);
  box-shadow: 0 14px 28px rgba(15, 23, 42, .08);
}

.attachment-list a,
.uploaded-files a,
.attachment-chip {
  border-color: #d6e3ee;
}

.portal-upload-panel {
  border-radius: 12px;
}

@media (max-width: 680px) {
  .portal-tab {
    flex-basis: 100%;
    justify-content: flex-start;
  }

  .portal-table td,
  .portal-table th {
    padding: 9px 10px;
  }

  .health-excuse-children {
    display: grid;
  }
}
