:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17233b;
  background: #f3f6fb;
  font-synthesis: none;
  --blue: #1746a2;
  --blue-soft: #eaf1ff;
  --teal: #0f8f87;
  --green: #12864b;
  --red: #c43d3d;
  --amber: #b86708;
  --border: #dce3ed;
  --muted: #68758b;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(340px, 42%) 1fr; background: #fff; }
.login-brand { display: flex; align-items: flex-start; gap: 14px; padding: 56px; color: #fff; background: #173d89; }
.login-brand > div:last-child { display: grid; }
.login-brand strong { font-size: 20px; }
.login-brand span { margin-top: 3px; color: #cbdcff; font-size: 13px; }
.brand-mark { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 8px; background: #fff; color: #1746a2; font-weight: 900; border: 1px solid rgba(255,255,255,.45); }
.brand-mark.small { width: 38px; height: 38px; font-size: 13px; }
.login-panel { display: grid; place-items: center; padding: 40px; }
.login-form { width: min(420px, 100%); }
.eyebrow { margin: 0 0 12px; color: var(--teal); font-size: 12px; font-weight: 800; }
.login-form h1 { margin: 0 0 34px; font-size: 34px; letter-spacing: 0; }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #cbd5e1; border-radius: 6px; padding: 0 12px; color: #17233b; background: #fff; outline: none; }
input, select { height: 42px; }
textarea { min-height: 76px; padding-top: 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #2764df; box-shadow: 0 0 0 3px rgba(39,100,223,.12); }
.form-error { min-height: 22px; margin: 9px 0; color: var(--red); font-size: 12px; }
.primary, .secondary, .danger, .text-button { min-height: 38px; border-radius: 6px; padding: 0 15px; border: 1px solid transparent; font-weight: 750; }
.primary { background: #2458d3; color: #fff; }
.secondary { background: #fff; border-color: #cbd5e1; color: #26344d; }
.danger { background: #fff; border-color: #f0a3a3; color: #b42323; }
.text-button { min-height: 32px; padding: 0 10px; background: transparent; color: #1746a2; }
button:disabled { cursor: not-allowed; opacity: .55; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 12px; background: #102f70; color: #fff; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 3px 6px 25px; }
.sidebar-brand > span { display: grid; }
.sidebar-brand small { margin-top: 2px; color: #bdd0f8; font-size: 10px; text-transform: uppercase; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav button, .logout-button { height: 42px; display: flex; align-items: center; gap: 11px; border: 0; border-radius: 6px; padding: 0 13px; background: transparent; color: #d9e5ff; text-align: left; font-weight: 700; }
.sidebar nav button.active, .sidebar nav button:hover { background: #fff; color: #1746a2; }
.nav-symbol { width: 18px; text-align: center; font-size: 16px; }
.logout-button { margin-top: auto; }
.app-main { min-width: 0; }
.topbar { position: sticky; z-index: 20; top: 0; height: 68px; display: flex; align-items: center; gap: 12px; padding: 0 26px; background: rgba(255,255,255,.97); border-bottom: 1px solid var(--border); }
.topbar > div { display: grid; }
.topbar > div span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.topbar #refresh-button { margin-left: auto; }
.icon-button { width: auto; min-width: 38px; height: 38px; display: grid; place-items: center; padding: 0 11px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: #34435c; font-size: 12px; font-weight: 700; }
#menu-button { display: none; }
.content { padding: 24px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 9px; }
.toolbar input { width: 250px; }
.toolbar select { width: 150px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(150px,1fr)); gap: 12px; margin-bottom: 18px; }
.metric { min-height: 105px; padding: 17px; background: #fff; border: 1px solid var(--border); border-radius: 7px; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 10px; font-size: 27px; }
.metric small { display: block; margin-top: 7px; color: var(--muted); }
.metric.alert strong { color: var(--red); }

.panel { background: #fff; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.panel + .panel { margin-top: 16px; }
.panel-header { min-height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel-header > div { display: grid; }
.panel-header h2 { margin: 0; font-size: 15px; }
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { height: 42px; padding: 0 12px; background: #f8fafc; color: #566277; text-align: left; white-space: nowrap; }
td { min-height: 48px; padding: 11px 12px; border-top: 1px solid #edf1f6; vertical-align: middle; }
tbody tr.clickable:hover { background: #f6f9ff; cursor: pointer; }
.cell-main { display: grid; gap: 3px; }
.cell-main strong { font-size: 13px; }
.cell-main small { color: var(--muted); }
.badge { display: inline-flex; align-items: center; width: max-content; padding: 3px 7px; border-radius: 4px; font-size: 10px; font-weight: 800; border: 1px solid #cbd5e1; color: #475569; background: #f8fafc; }
.badge.active, .badge.completed, .badge.sent, .badge.delivered, .badge.read { color: #08753c; border-color: #8bd5ad; background: #edfff5; }
.badge.failed, .badge.suspended, .badge.revoked { color: #ae2929; border-color: #f0a3a3; background: #fff1f1; }
.badge.inactive, .badge.processing, .badge.pending { color: #98570a; border-color: #efc07d; background: #fff8e8; }
.empty { min-height: 150px; display: grid; place-content: center; color: var(--muted); text-align: center; }

.section-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 16px; }
.detail-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.detail-heading h1 { margin: 5px 0 4px; font-size: 24px; }
.detail-heading p { margin: 0; color: var(--muted); }
.detail-actions { display: flex; align-items: center; gap: 8px; }
.detail-actions select { width: 135px; }
.entity-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 1px; background: var(--border); }
.entity-grid div { min-height: 72px; padding: 14px; background: #fff; }
.entity-grid span { display: block; color: var(--muted); font-size: 11px; }
.entity-grid strong { display: block; margin-top: 7px; font-size: 19px; }
.school-profile { margin-bottom: 16px; }
.profile-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 1px; background: var(--border); }
.profile-grid div { min-height: 68px; padding: 13px 15px; background: #fff; }
.profile-grid span { display: block; color: var(--muted); font-size: 11px; }
.profile-grid strong { display: block; margin-top: 6px; font-size: 13px; overflow-wrap: anywhere; }
.feature-grid { display: flex; flex-wrap: wrap; gap: 9px; padding: 13px 15px; border-top: 1px solid var(--border); }
.feature-badge { min-width: 140px; display: grid; gap: 2px; padding: 8px 11px; border: 1px solid; border-radius: 6px; }
.feature-badge b { font-size: 12px; }
.feature-badge small { font-size: 10px; }
.feature-badge.enabled { color: #08753c; border-color: #8bd5ad; background: #edfff5; }
.feature-badge.disabled { color: #98570a; border-color: #efc07d; background: #fff8e8; }
.error-text { max-width: 280px; color: var(--red); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.modal-backdrop { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(13,28,57,.55); }
.modal { width: min(680px,100%); max-height: calc(100vh - 40px); overflow: auto; background: #fff; border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,.22); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 17px 20px; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-close { width: 34px; height: 34px; border: 0; background: transparent; font-size: 20px; color: var(--muted); }
.modal-body { padding: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid [hidden] { display: none !important; }
.feature-options { display: flex; flex-wrap: wrap; gap: 18px; margin: 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: 6px; }
.feature-options legend { padding: 0 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.feature-options label { display: flex; align-items: center; gap: 7px; }
.feature-options input { width: 17px; height: 17px; padding: 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 20px; border-top: 1px solid var(--border); }
.credential-box { padding: 13px; border: 1px solid #b8cef7; border-radius: 6px; background: #f1f6ff; word-break: break-all; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.credential-row { margin-bottom: 13px; }
.credential-row label { margin-bottom: 6px; color: var(--muted); font-size: 11px; }
.credential-warning { margin-bottom: 15px; padding: 11px 13px; border: 1px solid #efc07d; border-radius: 6px; color: #7c4708; background: #fff8e8; font-size: 12px; font-weight: 700; }
.form-note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.toast { position: fixed; z-index: 150; right: 22px; bottom: 22px; max-width: 360px; padding: 12px 15px; border-radius: 6px; background: #18315f; color: #fff; opacity: 0; pointer-events: none; transform: translateY(8px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .metric-grid { grid-template-columns: repeat(2,1fr); }
  .section-grid { grid-template-columns: 1fr; }
  .entity-grid { grid-template-columns: repeat(2,1fr); }
  .profile-grid { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 720px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { min-height: 120px; padding: 28px; }
  .login-panel { padding: 28px 20px; place-items: start stretch; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 60; left: -240px; width: 224px; transition: left .2s ease; box-shadow: 8px 0 25px rgba(0,0,0,.18); }
  .sidebar.open { left: 0; }
  #menu-button { display: grid; }
  .topbar { padding: 0 14px; }
  .content { padding: 15px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-left, .toolbar-right { width: 100%; }
  .toolbar input { width: 100%; }
  .toolbar select { width: 135px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .metric { min-height: 88px; padding: 13px; }
  .metric strong { font-size: 22px; }
  .detail-heading { flex-direction: column; }
  .detail-actions { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .profile-grid { grid-template-columns: 1fr; }
}
