:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-strong: #ecfdf5;
  --text: #14221f;
  --muted: #64748b;
  --line: #dce6e2;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #7c3aed;
  --danger: #b91c1c;
  --success: #15803d;
  --warning: #92400e;
  --shadow: 0 18px 45px rgba(15, 35, 31, 0.12);
  font-family: 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(15, 118, 110, 0.12), rgba(124, 58, 237, 0.10)),
    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-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
}

.topbar-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
}

.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(15, 118, 110, 0.16);
}

.api-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfc;
}

.api-details summary {
  color: var(--muted);
  font-weight: 800;
}

.api-details label {
  margin-top: 12px;
}

.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:hover {
  border-color: #b8c7c2;
  background: #f9fbfa;
}

.ghost-action {
  border-color: rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.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;
  background: linear-gradient(120deg, #0f766e, #283593 55%, #7c3aed);
  color: #fff;
}

.topbar .eyebrow {
  color: rgba(255, 255, 255, 0.74);
}

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

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

.session-bar,
.status-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;
}

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

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

.unread-badge {
  min-width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 900;
}

.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 #bbf7d0;
  background: #f0fdf4;
  color: #166534;
  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, 1.4fr) minmax(120px, 0.55fr) repeat(2, minmax(135px, 0.6fr)) auto;
  gap: 12px;
  align-items: end;
  margin-top: 12px;
  padding: 12px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(0, 1.2fr);
  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(20, 34, 31, 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 - 342px);
  min-height: 330px;
  overflow-y: auto;
  padding: 10px;
}

.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(15, 118, 110, 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: #dcfce7;
  color: #166534;
}

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

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

.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: #243b36;
}

.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;
}

.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;
}

.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,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .school-select {
    width: 100%;
  }

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

  .search-field,
  .filters .secondary-action {
    grid-column: 1 / -1;
  }

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

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

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

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

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

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

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