:root {
  --ink: #102b42;
  --navy: #062541;
  --teal: #087f89;
  --teal-soft: #e3f4f1;
  --sun: #ffbf52;
  --muted: #59707e;
  --line: #d9e4e5;
  --paper: #fff;
  --page: #f4f8f7;
  font-family: "DM Sans", sans-serif;
  color: var(--ink);
  background: var(--page);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }

.portal-site-header {
  height: 78px;
  padding: 0 max(4vw, 20px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.portal-brand { display: block; flex: 0 0 auto; }
.portal-brand img { display: block; width: 170px; height: 55px; object-fit: contain; }
.portal-site-header nav { display: flex; align-items: center; gap: 24px; font-size: 14px; font-weight: 700; }
.portal-site-header nav a:hover { color: var(--teal); }
.portal-site-header nav .header-enquire { padding: 9px 13px; border-radius: 6px; background: var(--navy); color: #fff; }
.portal-site-header nav .header-enquire:hover { background: #154465; color: #fff; }

.overline { display: block; margin-bottom: 9px; color: var(--teal); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: Manrope, sans-serif; letter-spacing: 0; }

.auth-view {
  width: min(1050px, calc(100% - 40px));
  min-height: calc(100vh - 78px);
  margin: 0 auto;
  padding: 64px 0;
  display: grid;
  grid-template-columns: 1fr minmax(340px, 410px);
  gap: min(10vw, 100px);
  align-items: center;
}
.auth-intro h1 { max-width: 540px; margin-bottom: 20px; font-size: clamp(38px, 5vw, 58px); line-height: 1.08; }
.auth-intro p { max-width: 500px; color: var(--muted); font-size: 17px; line-height: 1.65; }
.auth-intro a { display: inline-block; margin-top: 15px; color: var(--teal); font-weight: 800; }
.auth-intro a:hover { text-decoration: underline; }
.auth-form { padding: 32px; display: grid; gap: 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); box-shadow: 0 20px 45px rgba(9, 42, 61, .07); }
.auth-form h2 { margin-bottom: -14px; font-size: 26px; }
.auth-form > p:not(.form-feedback) { margin: 0; color: var(--muted); font-size: 13px; }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 800; }
input, textarea, select { width: 100%; min-width: 0; padding: 11px 12px; border: 1px solid #bbcdd1; border-radius: 6px; background: #fff; color: var(--ink); font-size: 14px; font-weight: 500; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: var(--teal); outline: 3px solid rgba(8, 127, 137, .16); }
input:disabled, select:disabled { background: #eef2f2; color: #62717a; }
.portal-button { min-height: 40px; padding: 9px 15px; display: inline-flex; justify-content: center; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: 6px; font-size: 13px; font-weight: 800; line-height: 1.2; white-space: normal; text-align: center; }
.portal-button:disabled { cursor: wait; opacity: .6; }
.portal-button.primary { background: var(--navy); color: #fff; }
.portal-button.primary:hover:not(:disabled) { background: #174867; }
.portal-button.secondary { border-color: #bccdd1; background: #fff; color: var(--ink); }
.portal-button.secondary:hover:not(:disabled) { border-color: var(--teal); color: var(--teal); }
.portal-button.danger { border-color: #d9b5b2; background: #fff; color: #a5332b; }
.portal-button.danger:hover:not(:disabled) { background: #fff0ee; }
.plain-action { width: max-content; padding: 3px 0; border: 0; background: transparent; color: var(--teal); font-size: 13px; font-weight: 800; }
.plain-action:hover { text-decoration: underline; }
.form-feedback { min-height: 0; margin: 0; color: #a5332b; font-size: 13px; font-weight: 600; line-height: 1.4; }
.form-feedback:empty { display: none; }

.access-view { width: min(740px, calc(100% - 40px)); margin: 100px auto; }
.access-view h1 { font-size: 42px; }
.access-view p { color: var(--muted); font-size: 16px; }
.access-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.portal-app { width: min(1320px, calc(100% - 40px)); margin: 0 auto; padding: 36px 0 75px; }
.portal-app-head { display: flex; justify-content: space-between; align-items: end; gap: 20px; padding-bottom: 28px; }
.portal-app-head h1 { margin-bottom: 4px; font-size: clamp(27px, 3vw, 36px); line-height: 1.2; }
.portal-app-head p { margin: 0; color: var(--muted); font-size: 14px; }
.account-actions { display: flex; align-items: center; gap: 16px; }
.account-actions span { max-width: 230px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.portal-workspace { display: grid; grid-template-columns: 178px minmax(0, 1fr); gap: 34px; align-items: start; }
.portal-tabs { display: grid; gap: 3px; padding-top: 7px; }
.tab-button { width: 100%; min-height: 41px; padding: 10px 13px; border: 0; border-left: 3px solid transparent; background: transparent; color: var(--muted); font-size: 14px; font-weight: 800; text-align: left; }
.tab-button:hover { background: #eaf2f0; color: var(--ink); }
.tab-button.active { border-left-color: var(--teal); background: var(--teal-soft); color: var(--navy); }
.portal-panel { min-width: 0; }
.panel-heading { min-height: 70px; margin-bottom: 19px; display: flex; justify-content: space-between; align-items: start; gap: 15px; }
.panel-heading h2 { margin-bottom: 2px; font-size: 22px; }
.panel-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.filter-bar { display: flex; gap: 11px; flex-wrap: wrap; padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.filter-bar label { min-width: 145px; gap: 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.filter-bar select { min-height: 37px; padding: 7px 28px 7px 10px; font-size: 13px; text-transform: none; }
.material-list, .student-list { display: grid; gap: 8px; padding-top: 13px; }
.material-item, .student-item { display: grid; gap: 14px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.material-item { grid-template-columns: 72px minmax(0, 1fr) auto; align-items: start; padding: 18px 19px; }
.material-kind { min-width: 62px; padding: 5px 7px; border-radius: 4px; background: var(--teal-soft); color: #09646d; font-size: 11px; font-weight: 800; text-align: center; }
.material-kind.video { background: #fff1d5; color: #815700; }
.material-kind.link { background: #eaf0f9; color: #2c5782; }
.material-kind.text { background: #f0ecf7; color: #665287; }
.item-main { min-width: 0; }
.item-main h3 { margin: 0 0 5px; font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.item-main > p { margin: 0 0 7px; color: var(--muted); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.item-meta { color: #667b86; font-size: 11px; font-weight: 700; }
.item-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: end; }
.item-actions .portal-button { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.material-note { margin-top: 12px; padding: 14px; border-left: 3px solid var(--teal); background: #f3f9f8; color: var(--ink); font-size: 13px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.student-item { grid-template-columns: minmax(0, 1fr) auto; align-items: center; padding: 17px 19px; }
.student-item h3 { margin: 0 0 3px; font-size: 15px; }
.student-item p { margin: 0 0 6px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.student-item small { color: #506a74; font-size: 11px; font-weight: 800; }
.student-item.inactive { background: #f7f8f8; }
.empty-list { padding: 50px 20px; text-align: center; color: var(--muted); }
.empty-list h3 { margin-bottom: 7px; color: var(--ink); font-size: 17px; }
.empty-list p { margin: 0; font-size: 13px; }

.portal-dialog { width: min(500px, calc(100vw - 28px)); max-height: min(90vh, 820px); padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); box-shadow: 0 28px 80px rgba(5, 27, 43, .25); }
.portal-dialog::backdrop { background: rgba(4, 26, 42, .5); backdrop-filter: blur(3px); }
.portal-dialog form { padding: 23px; display: grid; gap: 15px; }
.portal-dialog .dialog-heading { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.portal-dialog .dialog-heading h2 { margin: 0; font-size: 21px; }
.portal-dialog .dialog-heading .overline { margin-bottom: 3px; }
.close-button { width: 34px; height: 34px; flex: 0 0 34px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: var(--ink); font-size: 25px; line-height: 1; }
.close-button:hover { background: #edf4f3; }
.dialog-actions { display: flex; justify-content: end; gap: 8px; margin-top: 3px; }
.subject-options { display: flex; gap: 8px; flex-wrap: wrap; margin: 0; padding: 0; border: 0; }
.subject-options legend { margin-bottom: 7px; padding: 0; font-size: 13px; font-weight: 800; }
.subject-options label { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px; font-size: 12px; }
.subject-options input { width: auto; margin: 0; accent-color: var(--teal); }
.material-dialog { width: min(600px, calc(100vw - 28px)); }
.form-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.optional, .field-hint { color: var(--muted); font-size: 11px; font-weight: 500; }
.field-hint:empty { display: none; }
.preview-dialog { width: min(880px, calc(100vw - 28px)); padding: 20px; }
.preview-dialog .dialog-heading { margin-bottom: 12px; }
.preview-dialog video { display: block; width: 100%; max-height: 70vh; background: #071b2a; }
.portal-toast { position: fixed; z-index: 50; right: 18px; bottom: 18px; max-width: min(390px, calc(100vw - 36px)); padding: 12px 15px; border-radius: 6px; background: var(--navy); color: #fff; box-shadow: 0 12px 32px rgba(4, 28, 47, .2); font-size: 13px; font-weight: 700; opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .2s, transform .2s; }
.portal-toast.visible { opacity: 1; transform: none; }
.portal-toast.error { background: #9c342d; }

.analytics-controls { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 18px; }
.analytics-controls label { width: min(210px, 100%); color: var(--muted); font-size: 11px; text-transform: uppercase; }
.analytics-controls select { min-height: 39px; color: var(--ink); font-size: 13px; text-transform: none; }
.analytics-controls .button { min-height: 39px; padding: 9px 15px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font-size: 13px; font-weight: 800; }
.analytics-controls .button:hover { border-color: var(--teal); color: var(--teal); }
.analytics-results { display: grid; gap: 25px; }
.analytics-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; }
.analytics-metric { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.analytics-metric strong { display: block; margin-bottom: 5px; font: 800 25px/1.2 Manrope, sans-serif; overflow-wrap: anywhere; }
.analytics-metric span { color: var(--muted); font-size: 11px; font-weight: 700; }
.analytics-section { min-width: 0; }
.analytics-section h3 { margin-bottom: 12px; font-size: 17px; }
.analytics-note { margin: 0 0 12px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.analytics-table-wrap { max-width: 100%; margin: 9px 0 16px; overflow-x: auto; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.analytics-table { width: 100%; border-collapse: collapse; font-size: 12px; text-align: left; }
.analytics-table th, .analytics-table td { min-width: 90px; padding: 10px 12px; border-bottom: 1px solid #edf1f1; vertical-align: top; overflow-wrap: anywhere; }
.analytics-table th { background: #eff5f4; color: #3a5965; font-size: 11px; white-space: nowrap; }
.analytics-table tr:last-child td { border-bottom: 0; }
.analytics-empty { margin: 0 0 15px; padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--muted); font-size: 13px; }

@media (max-width: 850px) {
  .auth-view { gap: 40px; grid-template-columns: 1fr 1fr; }
  .portal-workspace { grid-template-columns: 1fr; gap: 22px; }
  .portal-tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); }
  .tab-button { width: auto; min-width: 110px; border-left: 0; border-bottom: 3px solid transparent; text-align: center; }
  .tab-button.active { border-left: 0; border-bottom-color: var(--teal); }
  .analytics-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 650px) {
  .portal-site-header { height: auto; min-height: 70px; flex-wrap: wrap; justify-content: center; padding: 8px 14px; }
  .portal-brand img { width: 145px; height: 43px; }
  .portal-site-header nav { width: 100%; justify-content: center; gap: 7px; flex-wrap: wrap; font-size: 12px; }
  .portal-site-header nav a { padding: 5px; }
  .portal-site-header nav .header-enquire { padding: 6px 8px; }
  .auth-view { width: min(480px, calc(100% - 32px)); min-height: auto; padding: 42px 0 65px; grid-template-columns: 1fr; gap: 25px; }
  .auth-intro h1 { font-size: 39px; }
  .auth-intro p { font-size: 15px; }
  .auth-form { padding: 23px; }
  .portal-app { width: calc(100% - 28px); padding-top: 27px; }
  .portal-app-head { align-items: start; flex-direction: column; }
  .account-actions { width: 100%; justify-content: space-between; }
  .panel-heading { align-items: stretch; flex-direction: column; }
  .filter-bar label { flex: 1 1 135px; }
  .material-item { grid-template-columns: 1fr; gap: 9px; padding: 15px; }
  .material-kind { justify-self: start; }
  .item-actions { justify-content: start; }
  .student-item { grid-template-columns: 1fr; }
  .student-item .item-actions { justify-content: start; }
  .form-pair { grid-template-columns: 1fr; }
  .analytics-metrics { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .portal-toast { transition: none; }
}
