:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --text: #172033;
  --muted: #687086;
  --line: #e8eaf0;
  --primary: #1717ae;
  --primary-dark: #101078;
  --primary-soft: #eef0ff;
  --cyan: #16afe4;
  --yellow: #fff200;
  --purple: #137eac;
  --success: #16835b;
  --success-soft: #eaf8f2;
  --danger: #d92d20;
  --danger-soft: #fff0ef;
  --shadow: 0 18px 55px rgba(27, 35, 58, .10);
  --sidebar: 272px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.eyebrow {
  display: inline-block;
  color: rgba(255, 255, 255, .72);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.eyebrow.orange { color: var(--primary-dark); }
.muted { color: var(--muted); }

.brand,
.login-brand,
.login-mobile-brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.school-logo { display: block; max-width: 100%; height: auto; }
.school-logo-surface {
  width: min(310px, 72%);
  padding: 15px 18px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 20px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 18px 45px rgba(0,0,0,.20);
}
.login-school-logo { width: 100%; }
.mobile-school-logo { width: 210px; }
.sidebar-school-logo { width: 185px; }
.error-school-logo { width: min(260px, 78vw); margin-bottom: 24px; }

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(145deg, #ff8b32, #f25a0a);
  box-shadow: 0 8px 22px rgba(249, 115, 22, .28);
  font-size: 1.15rem;
  font-weight: 900;
}

.brand-mark.large { width: 52px; height: 52px; border-radius: 17px; font-size: 1.5rem; }
.brand strong, .login-brand strong, .login-mobile-brand strong { display: block; font-size: 1.05rem; line-height: 1.05; }
.brand span, .login-brand span, .login-mobile-brand span { color: var(--muted); font-size: .78rem; letter-spacing: .06em; }
.login-brand span { color: rgba(255,255,255,.68); }

.primary-button,
.secondary-button,
.compose-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0 18px;
  font-weight: 750;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}

.primary-button,
.compose-button {
  color: #fff;
  background: linear-gradient(135deg, var(--cyan), var(--primary));
  box-shadow: 0 9px 24px rgba(23, 23, 174, .22);
}

.primary-button:hover,
.compose-button:hover { transform: translateY(-1px); box-shadow: 0 12px 30px rgba(23, 23, 174, .30); }
.primary-button:disabled { opacity: .7; cursor: wait; transform: none; }
.secondary-button { color: #41495e; background: #fff; border-color: var(--line); }
.secondary-button:hover { background: var(--surface-soft); }
.full { width: 100%; }

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: #535b70;
  background: var(--surface);
  cursor: pointer;
}
.icon-button:hover { color: var(--text); background: var(--surface-soft); }
.icon-button.danger:hover { color: var(--danger); background: var(--danger-soft); border-color: #ffd5d2; }

/* Login */
.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(450px, 1.05fr) minmax(430px, .95fr); }
.login-visual {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: clamp(34px, 5vw, 72px);
  color: #fff;
  background:
    radial-gradient(circle at 18% 86%, rgba(22, 175, 228, .50), transparent 34%),
    linear-gradient(145deg, #07083f 0%, #161678 54%, #075f88 100%);
}
.visual-glow { position: absolute; border-radius: 50%; filter: blur(1px); pointer-events: none; }
.visual-glow-one { width: 320px; height: 320px; top: -150px; right: -80px; background: rgba(255, 242, 0, .24); }
.visual-glow-two { width: 260px; height: 260px; bottom: -110px; left: 32%; background: rgba(22, 175, 228, .25); }
.login-brand { position: relative; z-index: 1; }
.visual-copy { position: relative; z-index: 1; max-width: 590px; margin: auto 0; padding-bottom: 115px; }
.visual-copy h1 { max-width: 580px; margin: 16px 0; font-size: clamp(2.6rem, 5vw, 5.2rem); line-height: .98; letter-spacing: -.055em; }
.visual-copy p { max-width: 510px; margin: 0; color: rgba(255,255,255,.72); font-size: 1.12rem; }
.message-preview {
  position: absolute;
  z-index: 2;
  width: min(440px, 68%);
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 15px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 16px;
  background: rgba(255,255,255,.10);
  box-shadow: 0 20px 45px rgba(0,0,0,.18);
  backdrop-filter: blur(12px);
}
.preview-one { bottom: 70px; left: clamp(34px, 5vw, 72px); transform: rotate(-2deg); }
.preview-two { bottom: 25px; right: 7%; transform: rotate(2deg); }
.preview-avatar { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; color: #fff; background: var(--cyan); font-size: .72rem; font-weight: 900; }
.preview-avatar.purple { background: var(--purple); }
.message-preview strong, .message-preview span { display: block; }
.message-preview strong { font-size: .84rem; }
.message-preview span, .message-preview time { color: rgba(255,255,255,.65); font-size: .72rem; }
.login-panel { min-height: 100vh; display: grid; place-items: center; padding: 34px; background: #fff; }
.login-card { width: min(430px, 100%); }
.login-mobile-brand { display: none; margin-bottom: 58px; }
.login-card h2 { margin: 9px 0 7px; font-size: 2.1rem; letter-spacing: -.04em; }
.login-card > p { margin: 0; }
.login-form { display: grid; gap: 20px; margin-top: 34px; }
.login-form label > span { display: block; margin-bottom: 8px; color: #3f475b; font-size: .83rem; font-weight: 750; }
.login-form input,
.compose-form input,
.compose-form textarea {
  width: 100%;
  border: 1px solid #dfe2e9;
  border-radius: 12px;
  outline: none;
  background: #fff;
  transition: border .15s ease, box-shadow .15s ease;
}
.login-form input { height: 50px; padding: 0 14px; }
.login-form input:focus,
.compose-form input:focus,
.compose-form textarea:focus { border-color: #6e72da; box-shadow: 0 0 0 4px rgba(23,23,174,.10); }
.password-field { position: relative; }
.password-field input { padding-right: 75px; }
.password-toggle { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); border: 0; padding: 6px; color: var(--primary-dark); background: transparent; font-size: .76rem; font-weight: 700; cursor: pointer; }
.supported-domains { margin: 18px 0 0; color: #737b90; font-size: .72rem; line-height: 1.55; text-align: center; }
.supported-domains strong { color: #545d73; font-weight: 700; }
.security-note { display: flex; justify-content: center; gap: 7px; margin-top: 28px !important; color: #858b9c; font-size: .75rem; text-align: center; }
.security-note span { color: var(--success); }
.form-error { padding: 12px 14px; margin: 22px 0 0; border: 1px solid #ffd1ce; border-radius: 11px; color: #a92118; background: var(--danger-soft); font-size: .86rem; }

/* Application */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 25px 20px 18px;
  border-right: 1px solid var(--line);
  background: #fff;
}
.sidebar .brand { min-height: 70px; justify-content: center; padding: 0 9px; }
.compose-button { width: 100%; margin: 30px 0 22px; }
.compose-button span { font-size: 1.4rem; font-weight: 400; }
.folder-nav { display: grid; gap: 4px; overflow-y: auto; }
.folder-link { display: flex; align-items: center; gap: 12px; min-height: 43px; padding: 0 13px; border-radius: 11px; color: #5d6578; font-size: .9rem; font-weight: 620; }
.folder-link:hover { color: var(--text); background: #f7f8fa; }
.folder-link.active { color: var(--primary-dark); background: var(--primary-soft); }
.folder-icon { width: 20px; text-align: center; font-size: 1.1rem; }
.folder-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-card { display: grid; grid-template-columns: 38px minmax(0,1fr) auto; align-items: center; gap: 10px; margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--line); }
.avatar, .header-avatar { display: grid; place-items: center; border-radius: 50%; color: #fff; background: linear-gradient(145deg, var(--cyan), var(--primary)); font-weight: 800; }
.avatar { width: 38px; height: 38px; font-size: .72rem; }
.account-copy { min-width: 0; }
.account-copy strong, .account-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-copy strong { font-size: .8rem; }
.account-copy span { color: var(--muted); font-size: .65rem; }
.account-card .icon-button { width: 34px; height: 34px; border: 0; }
.workspace { min-width: 0; }
.workspace-header { min-height: 104px; display: grid; grid-template-columns: minmax(190px, 1fr) minmax(260px, 560px) 42px; align-items: center; gap: 25px; padding: 18px 32px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.92); }
.workspace-header h1 { margin: 2px 0 0; font-size: 1.7rem; letter-spacing: -.035em; }
.workspace-header.compact { min-height: 76px; grid-template-columns: 1fr auto; }
.workspace-header.compact > h1 { text-align: center; font-size: 1.05rem; }
.header-avatar { width: 42px; height: 42px; font-size: .75rem; }
.search-form { height: 46px; display: flex; align-items: center; gap: 9px; padding: 0 14px; border: 1px solid var(--line); border-radius: 13px; background: #f8f9fb; }
.search-form span { color: #8e95a5; font-size: 1.3rem; }
.search-form input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; }
.search-form a { color: var(--muted); font-size: 1.1rem; }
.mobile-header, .sidebar-scrim { display: none; }
.content-area { width: min(1240px, calc(100% - 54px)); margin: 27px auto 50px; }
.flash { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 13px 15px; margin-bottom: 16px; border-radius: 12px; font-size: .86rem; }
.flash-success { color: #126747; background: var(--success-soft); border: 1px solid #cdeee0; }
.flash-error { color: #a92118; background: var(--danger-soft); border: 1px solid #ffd1ce; }
.flash button { border: 0; background: transparent; cursor: pointer; font-size: 1.2rem; }
.list-toolbar { display: flex; align-items: center; justify-content: space-between; min-height: 54px; padding: 0 12px 0 18px; border: 1px solid var(--line); border-bottom: 0; border-radius: 15px 15px 0 0; background: #fff; }
.list-toolbar div { display: flex; gap: 5px; color: var(--muted); font-size: .8rem; }
.list-toolbar strong { color: var(--text); }
.list-toolbar .icon-button { width: 35px; height: 35px; border: 0; }
.message-list { overflow: hidden; border: 1px solid var(--line); border-radius: 0 0 15px 15px; background: #fff; box-shadow: 0 9px 35px rgba(26,34,56,.035); }
.message-row { min-height: 62px; display: grid; grid-template-columns: 44px minmax(0,1fr); align-items: center; border-bottom: 1px solid #eff0f3; background: #fff; }
.message-row:last-child { border-bottom: 0; }
.message-row:hover { background: #fafbfc; }
.message-row.unread { background: #fffaf6; }
.message-row.unread:hover { background: #fff7f1; }
.star-form { display: grid; place-items: center; }
.star-button { border: 0; padding: 6px; color: #9ba1af; background: transparent; cursor: pointer; font-size: 1.15rem; }
.star-button.active { color: #f2a314; }
.star-button.large { font-size: 1.45rem; }
.message-link { min-width: 0; display: grid; grid-template-columns: minmax(150px, 230px) minmax(250px, 1fr) 82px; align-items: center; gap: 20px; min-height: 61px; padding: 0 18px 0 0; }
.sender, .subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender { color: #41495c; font-size: .88rem; font-weight: 640; }
.subject { color: #555d70; font-size: .87rem; }
.message-row.unread .sender, .message-row.unread .subject { color: var(--text); font-weight: 780; }
.message-meta { color: #8990a0; font-size: .72rem; text-align: right; white-space: nowrap; }
.empty-state { display: grid; place-items: center; min-height: 430px; padding: 45px; border: 1px solid var(--line); border-radius: 0 0 15px 15px; background: #fff; text-align: center; }
.empty-icon { width: 66px; height: 66px; display: grid; place-items: center; border-radius: 22px; color: var(--primary); background: var(--primary-soft); font-size: 1.8rem; }
.empty-state h2 { margin: 18px 0 4px; font-size: 1.2rem; }
.empty-state p { margin: 0 0 20px; color: var(--muted); }
.pagination { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-top: 18px; color: var(--muted); font-size: .8rem; }
.pagination a { color: var(--primary-dark); font-weight: 700; }
.pagination a:last-child { text-align: right; }

/* Message */
.back-link { color: #4c556a; font-size: .86rem; font-weight: 700; }
.message-actions { display: flex; align-items: center; gap: 8px; }
.message-actions form { display: inline-flex; }
.message-view { width: min(980px, calc(100% - 58px)); margin: 36px auto 70px; }
.subject-line { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.subject-line h1 { max-width: 820px; margin: 0 0 25px; font-size: clamp(1.55rem, 3vw, 2.25rem); line-height: 1.17; letter-spacing: -.04em; }
.sender-card { display: grid; grid-template-columns: 43px minmax(0,1fr) auto; align-items: center; gap: 13px; padding-bottom: 25px; border-bottom: 1px solid var(--line); }
.sender-card .avatar { width: 43px; height: 43px; }
.sender-detail { min-width: 0; }
.sender-detail strong, .sender-detail span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-detail strong { font-size: .9rem; }
.sender-detail span, .sender-card time { color: var(--muted); font-size: .75rem; }
.email-body { min-height: 250px; padding: 32px 0; overflow-wrap: anywhere; color: #31394c; line-height: 1.7; }
.email-body img { max-width: 100%; height: auto; }
.email-body table { max-width: 100%; border-collapse: collapse; }
.email-body td, .email-body th { padding: 6px; }
.email-body a { color: #4f46e5; text-decoration: underline; }
.email-body pre { margin: 0; white-space: pre-wrap; font: inherit; }
.remote-image-blocked { display: inline-block; padding: 3px 7px; border-radius: 5px; color: #777f91; background: #f0f1f4; font-size: .7rem; }
.attachments { padding: 25px 0; border-top: 1px solid var(--line); }
.attachments h2 { margin: 0 0 14px; font-size: .95rem; }
.attachment-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.attachment-card { min-width: 220px; max-width: 320px; display: flex; align-items: center; gap: 11px; padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.attachment-card:hover { border-color: #ffc49c; background: #fffaf7; }
.attachment-icon { width: 35px; height: 35px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 9px; color: var(--primary-dark); background: var(--primary-soft); }
.attachment-card span:last-child { min-width: 0; }
.attachment-card strong, .attachment-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-card strong { font-size: .78rem; }
.attachment-card small { color: var(--muted); font-size: .68rem; }
.reply-actions { display: flex; gap: 10px; padding-top: 25px; border-top: 1px solid var(--line); }

/* Compose */
.compose-wrap { width: min(920px, calc(100% - 58px)); margin: 35px auto 70px; }
.compose-form { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: var(--shadow); }
.compose-row { display: grid; grid-template-columns: 80px minmax(0,1fr); align-items: center; min-height: 57px; padding: 0 22px; border-bottom: 1px solid var(--line); }
.compose-row label { color: #697084; font-size: .78rem; font-weight: 750; }
.compose-row input { height: 42px; padding: 0 10px; border-color: transparent; border-radius: 8px; }
.optional-recipients { border-bottom: 1px solid var(--line); }
.optional-recipients summary { padding: 8px 22px; color: var(--primary-dark); font-size: .72rem; font-weight: 700; cursor: pointer; }
.optional-recipients .compose-row:last-child { border-bottom: 0; }
.compose-form textarea { min-height: 390px; resize: vertical; padding: 24px; border: 0; border-radius: 0; line-height: 1.65; }
.compose-form textarea:focus { box-shadow: inset 0 0 0 2px rgba(23,23,174,.10); }
.compose-footer { min-height: 74px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 18px; border-top: 1px solid var(--line); background: #fbfbfc; }
.attachment-picker { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.attachment-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.attachment-picker span { color: #4d5569; font-size: .82rem; font-weight: 700; }
.attachment-picker small { color: var(--muted); font-size: .68rem; }

/* Error */
.error-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px; text-align: center; background: #fff; }
.error-page .brand-mark { margin-bottom: 18px; }
.error-page h1 { margin: 7px 0; font-size: 2rem; }
.error-page p { max-width: 520px; margin: 0 0 24px; color: var(--muted); }

@media (max-width: 980px) {
  :root { --sidebar: 235px; }
  .workspace-header { padding-inline: 22px; }
  .message-link { grid-template-columns: minmax(130px, 180px) minmax(180px, 1fr) 72px; gap: 13px; }
  .login-page { grid-template-columns: .9fr 1.1fr; }
  .message-preview { display: none; }
  .visual-copy { padding-bottom: 0; }
}

@media (max-width: 760px) {
  .login-page { display: block; }
  .login-visual { display: none; }
  .login-panel { min-height: 100svh; padding: 28px 22px; }
  .login-mobile-brand { display: flex; }
  .login-card h2 { font-size: 1.85rem; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; width: 282px; transform: translateX(-105%); transition: transform .22s ease; box-shadow: 20px 0 50px rgba(24,31,48,.18); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 20; background: rgba(20,25,39,.45); backdrop-filter: blur(2px); }
  .sidebar-scrim.open { display: block; }
  .mobile-header { min-height: 62px; display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: #fff; }
  .mobile-brand { text-align: center; font-size: .82rem; }
  .mobile-brand span { font-weight: 850; }
  .workspace-header { min-height: auto; display: block; padding: 19px 17px 16px; }
  .workspace-header > div:first-child { margin-bottom: 14px; }
  .workspace-header h1 { font-size: 1.45rem; }
  .workspace-header .header-avatar { display: none; }
  .workspace-header.compact { min-height: 61px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 15px; }
  .workspace-header.compact > h1 { display: none; }
  .message-actions .secondary-button { width: 40px; overflow: hidden; padding: 0; font-size: 0; }
  .message-actions .secondary-button::after { content: "○"; font-size: 1rem; }
  .content-area { width: calc(100% - 24px); margin: 13px auto 35px; }
  .list-toolbar { border-radius: 12px 12px 0 0; }
  .message-list { border-radius: 0 0 12px 12px; }
  .message-row { grid-template-columns: 36px minmax(0,1fr); }
  .message-link { grid-template-columns: minmax(0,1fr) auto; grid-template-rows: auto auto; gap: 2px 8px; min-height: 70px; padding: 9px 11px 9px 0; }
  .sender { grid-column: 1; grid-row: 1; }
  .message-meta { grid-column: 2; grid-row: 1; }
  .subject { grid-column: 1 / 3; grid-row: 2; font-size: .78rem; }
  .message-view, .compose-wrap { width: calc(100% - 26px); margin: 22px auto 45px; }
  .subject-line h1 { margin-bottom: 18px; font-size: 1.5rem; }
  .sender-card { grid-template-columns: 39px minmax(0,1fr); }
  .sender-card time { grid-column: 2; }
  .email-body { padding: 24px 0; font-size: .92rem; }
  .reply-actions { position: sticky; bottom: 0; padding: 12px 0; background: var(--bg); }
  .compose-form { border-radius: 12px; }
  .compose-row { grid-template-columns: 55px minmax(0,1fr); padding: 0 13px; }
  .compose-form textarea { min-height: 330px; padding: 18px; }
  .compose-footer { align-items: stretch; flex-direction: column; }
  .attachment-picker { min-height: 36px; }
  .compose-footer .primary-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
