:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --surface-strong: #e4ecf7;
  --text: #1f2a44;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #406cb0;
  --primary-dark: #345a96;
  --primary-deep: #1f2a44;
  --accent: #f07048;
  --accent-dark: #d86446;
  --danger: #d45542;
  --success: #2f8f7a;
  --warning: #d98a3d;
  --shadow: 0 18px 45px rgba(31, 42, 68, 0.12);
  font-family: Manrope, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.64;
}

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

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.auth-layout {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(64, 108, 176, 0.16), rgba(240, 112, 72, 0.12)),
    var(--bg);
}

.auth-panel {
  width: min(100%, 430px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-row,
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-row {
  flex-wrap: wrap;
}

.topbar-symbol-wrap {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

.brand-message-logo,
.topbar-icon {
  display: block;
  object-fit: contain;
}

.brand-login {
  justify-content: center;
  text-align: center;
}

.brand-message-logo {
  width: 118px;
  height: 118px;
  border-radius: 26px;
  box-shadow: 0 14px 26px rgba(31, 42, 68, 0.12);
}

.topbar-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
}

.brand-wordmark {
  display: block;
  width: min(190px, 58vw);
  height: auto;
  margin-bottom: 4px;
}

.auth-panel h1,
.topbar h1 {
  letter-spacing: 0;
}

.auth-panel h1 {
  font-size: 1.72rem;
  line-height: 1.12;
}

.muted {
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 16px;
  margin-top: 26px;
}

label {
  display: grid;
  gap: 7px;
}

label span,
.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

textarea {
  min-height: 132px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(64, 108, 176, 0.16);
}

.primary-action,
.secondary-action,
.ghost-action {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

.primary-action {
  background: var(--primary);
  color: #fff;
}

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

.primary-action.compact {
  min-height: 38px;
}

.secondary-action {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.secondary-action.compact {
  min-height: 36px;
  padding-inline: 12px;
}

.secondary-action:hover {
  border-color: #c6d4ec;
  background: #f5f8fd;
}

.ghost-action {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.ghost-action:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.form-error,
.dashboard-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 800;
}

.messages-app {
  min-height: 100vh;
  padding-bottom: max(26px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(18px, env(safe-area-inset-top)) 18px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  box-shadow: 0 12px 30px rgba(31, 42, 68, 0.08);
}

.topbar .eyebrow {
  color: var(--muted);
}

.topbar h1 {
  margin-top: 2px;
  font-size: clamp(1.32rem, 5vw, 2rem);
  line-height: 1.1;
}

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

.topbar-menu-wrap {
  position: relative;
}

.topbar-menu-trigger {
  min-width: 76px;
}

.topbar-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  width: min(260px, calc(100vw - 32px));
  display: grid;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.topbar-menu button {
  min-height: 42px;
  width: 100%;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  padding: 0 12px;
  text-align: left;
  font-weight: 800;
}

.topbar-menu button:hover {
  background: #f5f8fd;
  color: var(--primary-dark);
}

.icon-action {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #c6d4ec;
  border-radius: 999px;
  background: #f5f8fd;
  color: var(--primary-dark);
  font-weight: 900;
  font-size: 1rem;
}

.icon-action:hover {
  border-color: var(--primary);
  background: #eaf1fb;
}

.session-bar,
.push-panel,
.unread-summary-panel,
.toolbar,
.filters,
.content-grid,
.live-alert,
.dashboard-error,
.update-notice {
  width: min(1180px, calc(100% - 28px));
  margin-inline: auto;
}

.session-bar,
.push-panel,
.toolbar,
.filters {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(20, 34, 31, 0.06);
}

.session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding: 12px 14px;
}

.session-bar strong {
  display: block;
}

.push-panel {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  margin-top: 12px;
  padding: 12px 14px;
}

.push-panel strong {
  display: block;
  margin-bottom: 2px;
}

.push-panel p {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.push-panel.active {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.push-panel.active p {
  color: #166534;
}

.push-panel.blocked {
  border-color: #fed7aa;
  background: #fff7ed;
}

.push-panel.blocked p {
  color: #9a3412;
}

.school-select {
  width: min(100%, 340px);
}

.unread-summary-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 12px;
  padding: 16px 18px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  box-shadow: 0 18px 42px rgba(31, 42, 68, 0.18);
}

.unread-summary-panel span {
  font-size: 0.9rem;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.unread-summary-panel strong {
  min-width: 64px;
  text-align: right;
  font-size: clamp(2rem, 12vw, 3.1rem);
  line-height: 1;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.update-notice,
.live-alert,
.dashboard-error {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 8px;
}

.update-notice {
  border: 1px solid #fed7aa;
  background: #fff7ed;
  color: #9a3412;
}

.live-alert {
  border: 1px solid #c6d4ec;
  background: #f5f8fd;
  color: var(--primary-dark);
  font-weight: 800;
}

.dashboard-error {
  border: 1px solid #fecaca;
  background: #fef2f2;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 12px;
}

.mailbox-tabs {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.mailbox-tabs button {
  min-height: 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  padding: 0 14px;
  font-weight: 900;
}

.mailbox-tabs button.active {
  background: var(--primary);
  color: #fff;
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(160px, 0.65fr) auto;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
  padding: 12px;
}

.filter-summary {
  min-height: 38px;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 0 12px;
  font-size: 0.88rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-summary.active {
  border-color: var(--primary-200, #c6d4ec);
  background: #f5f8fd;
  color: var(--primary-dark);
}

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

.panel {
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(31, 42, 68, 0.06);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  font-size: 1.05rem;
}

.message-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 386px);
  min-height: 330px;
  overflow-y: auto;
  padding: 10px;
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  padding: 0 10px 12px;
}

.load-more-wrap .secondary-action {
  width: 100%;
}

.message-card {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
  text-align: left;
}

.message-card.unread {
  border-color: #93c5fd;
  background: linear-gradient(180deg, #dbeafe 0%, #eef2ff 100%);
}

.message-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(64, 108, 176, 0.14);
}

.message-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.message-card h3 {
  font-size: 0.98rem;
  line-height: 1.25;
}

.message-card-meta,
.message-card-preview {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.message-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 6px;
}

.message-card-preview {
  margin-top: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
}

.status-pill.unread {
  background: #fee2e2;
  color: #b91c1c;
}

.status-pill.read {
  background: #dff3ee;
  color: #1f6f5f;
}

.message-detail-panel {
  display: flex;
}

.message-detail-card {
  width: min(100%, 760px);
}

.message-detail {
  width: 100%;
  padding: 18px;
}

.message-detail-card .message-detail {
  padding: 0;
}

.message-detail h2 {
  font-size: clamp(1.2rem, 4vw, 1.75rem);
  line-height: 1.15;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.detail-body {
  margin-top: 20px;
  white-space: pre-wrap;
  line-height: 1.56;
  color: var(--text);
}

.sent-message-detail {
  display: grid;
  gap: 16px;
}

.sent-detail-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 14px;
  align-items: stretch;
}

.sent-detail-message-card,
.sent-detail-chart-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.sent-detail-message-card > span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.sent-detail-message-card p {
  margin-top: 8px;
  white-space: pre-wrap;
  line-height: 1.52;
}

.sent-detail-chart-card {
  display: grid;
  place-items: center;
  gap: 10px;
}

.sent-detail-donut {
  width: 124px;
  height: 124px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
}

.sent-detail-donut::after {
  content: '';
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  background: #fff;
}

.sent-detail-donut span {
  position: relative;
  z-index: 1;
  color: var(--primary-deep);
  font-size: 1.35rem;
  font-weight: 900;
}

.sent-detail-chart-legend {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
}

.legend-dot.read {
  background: #16a34a;
}

.legend-dot.unread {
  background: #e11d48;
}

.sent-detail-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.sent-detail-toolbar label {
  flex: 1;
}

.sent-detail-toolbar span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
}

.sent-detail-table-wrap {
  max-height: min(42vh, 420px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.sent-detail-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  background: #fff;
}

.sent-detail-table th,
.sent-detail-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.88rem;
}

.sent-detail-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-strong);
  color: var(--primary-dark);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.sent-detail-table td strong,
.sent-detail-table td span,
.sent-detail-table td small,
.sent-detail-table td em {
  display: block;
}

.sent-detail-table td span,
.sent-detail-table td small {
  color: var(--muted);
}

.sent-detail-table td em {
  margin-top: 4px;
  color: #b91c1c;
  font-style: normal;
}

.recipient-read-status,
.recipient-push-status {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 900;
}

.recipient-read-status.read,
.recipient-push-status.ok {
  background: #dcfce7;
  color: #166534;
}

.recipient-read-status.unread,
.recipient-push-status.error {
  background: #fee2e2;
  color: #b91c1c;
}

.recipient-push-status.warn {
  background: #fff7ed;
  color: #9a3412;
}

.recipient-push-status.muted,
.recipient-push-status.pending {
  background: #f1f5f9;
  color: #475569;
}

.sent-detail-empty {
  text-align: center;
  color: var(--muted);
}

.empty-state,
.loading-state {
  display: grid;
  min-height: 180px;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  background: rgba(15, 23, 42, 0.52);
}

.modal-card {
  width: min(100%, 920px);
  max-height: min(92vh, 880px);
  overflow-y: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.session-card {
  width: min(100%, 420px);
  display: grid;
  gap: 14px;
}

.info-card,
.update-card {
  width: min(100%, 560px);
}

.info-content {
  display: grid;
  gap: 10px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.info-row span {
  color: var(--muted);
  font-weight: 800;
}

.info-row strong {
  text-align: right;
  word-break: break-word;
}

.push-health {
  margin-top: 6px;
  border-radius: 8px;
  padding: 12px;
  font-weight: 900;
}

.push-health.ok {
  background: #dff3ee;
  color: #1f6f5f;
}

.push-health.warn {
  background: #fff7ed;
  color: #9a3412;
}

.update-card {
  display: grid;
  gap: 16px;
}

.update-message {
  border: 1px solid #fed7aa;
  border-radius: 8px;
  background: #fff7ed;
  color: #9a3412;
  padding: 14px;
}

.update-message strong {
  display: block;
  color: var(--primary-deep);
  margin-bottom: 6px;
}

.password-card {
  width: min(100%, 540px);
  display: grid;
  gap: 14px;
}

.password-fields {
  display: grid;
  gap: 12px;
}

.password-success {
  min-height: 20px;
  border: 1px solid #b7e4d8;
  border-radius: 8px;
  background: #dff3ee;
  color: #1f6f5f;
  padding: 10px 12px;
  font-size: 0.92rem;
  font-weight: 900;
}

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

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
}

.compose-card {
  display: grid;
  gap: 14px;
}

.filters-card {
  width: min(100%, 520px);
  display: grid;
  gap: 14px;
}

.quick-recipients {
  display: grid;
  gap: 8px;
}

.quick-recipients:empty {
  display: none;
}

.quick-check,
.recipient-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.quick-check input,
.recipient-item input {
  width: 18px;
  min-height: 18px;
  margin-top: 2px;
}

.quick-check strong,
.recipient-item strong {
  display: block;
}

.quick-check small,
.recipient-item small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}

.recipient-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.recipient-section {
  display: grid;
  gap: 8px;
}

.recipient-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.recipient-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding: 2px;
}

.compact-list {
  max-height: 180px;
}

.compose-summary {
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--primary-dark);
  font-weight: 900;
  padding: 11px 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 860px) {
  .session-bar,
  .push-panel,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .school-select {
    width: 100%;
  }

  .filters {
    grid-template-columns: 1fr 1fr;
  }

  .search-field,
  .filter-summary {
    grid-column: 1 / -1;
  }

  .content-grid,
  .recipient-grid,
  .sent-detail-summary {
    grid-template-columns: 1fr;
  }

  .message-list {
    max-height: none;
  }
}

@media (max-width: 520px) {
  .auth-panel,
  .modal-card {
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    flex-shrink: 0;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .search-field,
  .filter-summary {
    grid-column: auto;
  }

  .filters .secondary-action,
  .filters .primary-action {
    width: 100%;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

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

  .sent-detail-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .sent-detail-toolbar span {
    white-space: normal;
  }
}
