:root {
  --canvas: #f6f5f0;
  --surface: #fff;
  --soft: #eef3f1;
  --ink: #172321;
  --muted: #65736f;
  --line: #d9e0dc;
  --brand: #335c67;
  --brand-strong: #244851;
  --accent: #d98e46;
  --danger: #a33a32;
  --shadow: 0 18px 60px rgb(26 50 45 / 12%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, textarea { font: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 72%, transparent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #dce9e4 0, transparent 38%), linear-gradient(145deg, #f8f6ef, #e9f0ed); }
.login-card { width: min(100%, 430px); padding: 44px; border: 1px solid rgb(51 92 103 / 12%); border-radius: 28px; background: rgb(255 255 255 / 88%); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.brand-mark { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 17px; color: white; background: var(--brand); font: 32px Georgia, serif; box-shadow: 0 8px 20px rgb(51 92 103 / 24%); }
.brand-mark.small { width: 36px; height: 36px; border-radius: 11px; font-size: 21px; }
.eyebrow { margin: 28px 0 6px; color: var(--brand); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 12px; }
h1, h2, p { margin-top: 0; }
.login-card h1 { margin-bottom: 8px; font: 500 clamp(28px, 6vw, 38px)/1.1 Georgia, serif; }
.muted, .status { color: var(--muted); }
label { display: block; margin: 20px 0 7px; font-weight: 650; font-size: 14px; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; color: var(--ink); background: var(--surface); }
input:focus, textarea:focus { border-color: var(--brand); }
.primary { border: 0; border-radius: 12px; padding: 12px 22px; color: white; background: var(--brand); font-weight: 700; cursor: pointer; }
.primary:hover { background: var(--brand-strong); }
.secondary { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 12px; padding: 11px 22px; color: var(--brand-strong); background: var(--surface); text-decoration: none; font-weight: 700; }
.secondary:hover { background: var(--soft); }
.wide { width: 100%; margin-top: 28px; }
.form-error { margin: 12px 0 0; color: var(--danger); font-size: 14px; }
.openid-login { margin-top: 20px; text-align: center; }
.openid-login > span { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.openid-login .wide { margin-top: 0; }

.mail-shell { min-height: 100vh; display: grid; grid-template: 68px 1fr / 230px 1fr; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 18px; padding: 0 22px; border-bottom: 1px solid var(--line); background: rgb(255 255 255 / 88%); backdrop-filter: blur(14px); z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 190px; color: var(--ink); text-decoration: none; font: 23px Georgia, serif; }
.search { flex: 1; max-width: 760px; position: relative; }
.search input { padding-right: 44px; border: 0; background: var(--soft); }
.search button { position: absolute; right: 5px; top: 4px; width: 36px; height: 36px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 22px; }
.account-address { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }
.text-button, .icon-button { border: 0; background: transparent; color: var(--brand); cursor: pointer; font-weight: 650; }
.icon-button { display: inline-grid; place-items: center; min-width: 40px; min-height: 40px; border-radius: 50%; font-size: 20px; }
.icon-button:hover, .text-button:hover { background: var(--soft); }
.danger { color: var(--danger); }

.sidebar { padding: 24px 14px; border-right: 1px solid var(--line); background: #f1f4f1; }
.compose-button { width: 100%; display: flex; align-items: center; gap: 10px; border: 0; border-radius: 16px; padding: 14px 17px; color: white; background: var(--brand); box-shadow: 0 8px 18px rgb(51 92 103 / 20%); cursor: pointer; font-weight: 750; }
.compose-button span { font-size: 22px; }
.sidebar nav { margin-top: 24px; }
.sidebar nav a { display: flex; padding: 10px 14px; margin: 3px 0; border-radius: 10px; color: var(--ink); text-decoration: none; font-size: 14px; }
.sidebar nav a.active { color: var(--brand-strong); background: #dce9e4; font-weight: 750; }

.content { min-width: 0; display: grid; grid-template-columns: minmax(320px, 42%) 1fr; background: var(--surface); }
.message-column { min-width: 0; border-right: 1px solid var(--line); }
.pane-toolbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 22px; border-bottom: 1px solid var(--line); }
.pane-toolbar h1 { margin: 0; font: 500 24px Georgia, serif; }
.status { min-height: 20px; margin: 8px 22px; font-size: 13px; }
.message-list { margin: 0; padding: 0; list-style: none; }
.message-row { display: grid; grid-template-columns: minmax(110px, .8fr) minmax(180px, 1.6fr) auto; gap: 12px; padding: 15px 20px; border-bottom: 1px solid var(--line); cursor: pointer; }
.message-row:hover, .message-row.selected { background: var(--soft); }
.message-row.unread { font-weight: 700; }
.message-row button { display: contents; text-align: left; color: inherit; border: 0; background: transparent; cursor: pointer; }
.sender, .subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subject span { color: var(--muted); font-weight: 400; }
.message-row time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.empty-state, .reader-placeholder { min-height: 50vh; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.empty-state > span, .reader-placeholder > span { display: grid; place-items: center; width: 58px; height: 58px; margin-bottom: 15px; border-radius: 50%; background: var(--soft); font-size: 26px; }
.reader { min-width: 0; background: var(--surface); }
.reader-actions { justify-content: flex-end; }
.message-content { max-width: 850px; padding: 38px clamp(24px, 6vw, 72px) 80px; }
.message-content h1 { font: 500 clamp(26px, 4vw, 38px) Georgia, serif; }
.message-headers { margin: 26px 0; padding: 16px 0; border-block: 1px solid var(--line); font-size: 13px; }
.message-headers div { display: grid; grid-template-columns: 60px 1fr; margin: 5px 0; }
.message-headers dt { color: var(--muted); }
.message-headers dd { margin: 0; overflow-wrap: anywhere; }
.message-body { max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; font: 15px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace; }

.compose-dialog { width: min(680px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 18px; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); }
.compose-dialog::backdrop { background: rgb(14 25 23 / 45%); backdrop-filter: blur(3px); }
.compose-dialog form { display: grid; padding: 22px; }
.compose-dialog header, .compose-dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.compose-dialog header h2 { margin: 0; font: 500 24px Georgia, serif; }
.compose-dialog textarea { min-height: 260px; resize: vertical; }
.compose-dialog footer { margin-top: 18px; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: 360px; padding: 13px 18px; border-radius: 12px; color: white; background: var(--brand-strong); box-shadow: var(--shadow); z-index: 20; }
.mobile-only { display: none; }

@media (max-width: 900px) {
  .mail-shell { grid-template-columns: 1fr; }
  .topbar { padding: 0 12px; gap: 8px; }
  .brand { min-width: auto; }
  .brand > span:last-child, .account-address { display: none; }
  .mobile-only { display: inline-grid; }
  .sidebar { position: fixed; inset: 68px auto 0 0; width: 240px; transform: translateX(-100%); transition: transform .2s ease; z-index: 4; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .content { grid-column: 1; grid-template-columns: 1fr; }
  .reader { display: none; position: fixed; inset: 68px 0 0; overflow: auto; z-index: 3; }
  .reader.open { display: block; }
  .reader-actions { justify-content: space-between; }
}

@media (max-width: 560px) {
  .login-card { padding: 30px 24px; border-radius: 20px; }
  .brand > span:last-child, .account-address, .logout-button { display: none; }
  .message-row { grid-template-columns: 1fr auto; }
  .message-row .subject { grid-column: 1 / -1; }
}

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