@import url("/static/fonts/fonts.css");

/* ===== Material You (M3) tokens ===== */
:root {
  color-scheme: light;
  --font: "Google Sans", "Google Sans Text", Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Google Sans Code", "Roboto Mono", ui-monospace, Consolas, monospace;

  --shape-xs: 4px; --shape-s: 8px; --shape-m: 12px; --shape-l: 16px; --shape-xl: 28px; --shape-full: 999px;
  --ease: cubic-bezier(.2, 0, 0, 1);
  --ease-spring: cubic-bezier(.34, 1.4, .64, 1);

  /* blue (default) light */
  --primary: #0b57d0; --on-primary: #fff;
  --primary-container: #d3e3fd; --on-primary-container: #041e49;
  --secondary-container: #c2e7ff; --on-secondary-container: #001d35;
  --tertiary-container: #c4eed0; --on-tertiary-container: #072711;
  --surface: #f8fafd; --surface-dim: #dde3ea;
  --surface-c-lowest: #ffffff; --surface-c-low: #f3f6fb; --surface-c: #eef2f8;
  --surface-c-high: #e8edf4; --surface-c-highest: #e1e7ef;
  --on-surface: #1f1f1f; --on-surface-variant: #444746;
  --outline: #747775; --outline-variant: #c4c7c5;
  --error: #b3261e; --error-container: #f9dedc; --on-error-container: #410e0b;
  --success-container: #c4eed0; --on-success-container: #0f5223;
  --scrim: rgba(0, 0, 0, .32);
  --elev-1: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px 1px rgba(0,0,0,.15);
  --elev-2: 0 1px 2px rgba(0,0,0,.3), 0 2px 6px 2px rgba(0,0,0,.15);
}
[data-palette="iris"] {
  --primary: #6750a4; --primary-container: #eaddff; --on-primary-container: #21005d;
  --secondary-container: #e8def8; --on-secondary-container: #1d192b;
  --surface: #fef7ff; --surface-c-low: #f7f2fa; --surface-c: #f3edf7; --surface-c-high: #ece6f0; --surface-c-highest: #e6e0e9;
}
[data-palette="emerald"] {
  --primary: #146c2e; --primary-container: #b7f1c0; --on-primary-container: #002109;
  --secondary-container: #d0e8d1; --on-secondary-container: #0c1f11;
  --surface: #f6fbf3; --surface-c-low: #f0f5ed; --surface-c: #eaefe7; --surface-c-high: #e4eae2; --surface-c-highest: #dfe4dc;
}
[data-palette="rose"] {
  --primary: #a8305f; --primary-container: #ffd9e2; --on-primary-container: #3e001d;
  --secondary-container: #ffd9e2; --on-secondary-container: #2b151c;
  --surface: #fff8f8; --surface-c-low: #fff0f2; --surface-c: #fbeaec; --surface-c-high: #f5e4e6; --surface-c-highest: #efdee1;
}

[data-theme="dark"] {
  color-scheme: dark;
  --primary: #a8c7fa; --on-primary: #062e6f;
  --primary-container: #0842a0; --on-primary-container: #d3e3fd;
  --secondary-container: #004a77; --on-secondary-container: #c2e7ff;
  --surface: #131314; --surface-dim: #131314;
  --surface-c-lowest: #0e0e0f; --surface-c-low: #1b1b1c; --surface-c: #1e1f20;
  --surface-c-high: #282a2c; --surface-c-highest: #333537;
  --on-surface: #e3e3e3; --on-surface-variant: #c4c7c5;
  --outline: #8e918f; --outline-variant: #444746;
  --error: #f2b8b5; --error-container: #8c1d18; --on-error-container: #f9dedc;
  --success-container: #0f5223; --on-success-container: #c4eed0;
}
[data-theme="dark"][data-palette="iris"] { --primary: #d0bcff; --on-primary: #381e72; --primary-container: #4f378b; --on-primary-container: #eaddff; --secondary-container: #4a4458; --on-secondary-container: #e8def8; }
[data-theme="dark"][data-palette="emerald"] { --primary: #6dd58c; --on-primary: #00391a; --primary-container: #005321; --on-primary-container: #b7f1c0; --secondary-container: #364b39; --on-secondary-container: #d0e8d1; }
[data-theme="dark"][data-palette="rose"] { --primary: #ffb1c7; --on-primary: #650033; --primary-container: #881848; --on-primary-container: #ffd9e2; --secondary-container: #5c3f46; --on-secondary-container: #ffd9e2; }

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--surface); }
body {
  margin: 0; min-height: 100vh;
  font-family: var(--font); font-size: 14px; line-height: 20px; letter-spacing: .01em;
  color: var(--on-surface); background: var(--surface);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}
h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; opacity: .38; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }
code { font-family: var(--mono); font-size: .92em; padding: 1px 6px; border-radius: var(--shape-xs); background: var(--surface-c-highest); color: var(--on-surface); overflow-wrap: anywhere; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.svg-icon { width: 24px; height: 24px; fill: currentColor; flex: none; display: block; }

.wrap { width: min(1280px, calc(100% - 48px)); margin-inline: auto; }

/* ===== Top app bar ===== */
.masthead { position: sticky; top: 0; z-index: 10; background: var(--surface); transition: background-color .3s var(--ease); }
.masthead-inner { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; border-radius: var(--shape-l); background: var(--primary-container); color: var(--on-primary-container); flex: none; }
.brand-text { min-width: 0; }
.brand-text strong { display: block; font-size: 22px; line-height: 28px; font-weight: 500; }
.brand-text span { display: block; font-size: 12px; line-height: 16px; color: var(--on-surface-variant); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.masthead-actions { display: flex; align-items: center; gap: 12px; }
.local { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 14px 0 10px; border-radius: var(--shape-s); background: var(--success-container); color: var(--on-success-container); font-size: 13px; font-weight: 500; white-space: nowrap; }
.local .svg-icon { width: 18px; height: 18px; }
.palette-picker { display: flex; gap: 6px; padding: 6px; border-radius: var(--shape-full); background: var(--surface-c-high); }
.palette-dot { width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 0; background: var(--dot); transition: transform .25s var(--ease-spring), box-shadow .2s; }
.palette-dot[data-seed="blue"] { --dot: #0b57d0; } .palette-dot[data-seed="iris"] { --dot: #6750a4; }
.palette-dot[data-seed="emerald"] { --dot: #146c2e; } .palette-dot[data-seed="rose"] { --dot: #a8305f; }
.palette-dot:hover { transform: scale(1.12); }
.palette-dot[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface-c-high), 0 0 0 4px var(--dot); }
.theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-light { display: block; }
[data-theme="dark"] .theme-icon-dark { display: none; }

/* ===== Buttons ===== */
.icon-button {
  position: relative; display: inline-grid; place-items: center; flex: none;
  width: 40px; height: 40px; padding: 0; border: 0; border-radius: var(--shape-full);
  background: transparent; color: var(--on-surface-variant); overflow: hidden; isolation: isolate;
  transition: border-radius .25s var(--ease), background-color .2s;
}
.icon-button::before, .button::before, .message::before, .attachment::before, .seg button::before {
  content: ""; position: absolute; inset: 0; z-index: -1; background: currentColor; opacity: 0; transition: opacity .2s var(--ease);
}
.icon-button:hover:not(:disabled)::before, .button:hover:not(:disabled)::before,
.message:hover::before, .attachment:hover:not(:disabled)::before, .seg button:hover::before { opacity: .08; }
.icon-button:active:not(:disabled)::before, .button:active:not(:disabled)::before, .message:active::before { opacity: .12; }
.icon-button:active:not(:disabled) { border-radius: var(--shape-m); }
.icon-button.tonal { background: var(--secondary-container); color: var(--on-secondary-container); }

.button {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 56px; padding: 0 24px 0 20px; border: 0; border-radius: var(--shape-l);
  font-size: 15px; font-weight: 500; letter-spacing: .01em; white-space: nowrap; overflow: hidden; isolation: isolate;
  transition: border-radius .3s var(--ease), box-shadow .2s, transform .2s var(--ease);
}
.button .svg-icon { width: 20px; height: 20px; }
.primary { background: var(--primary); color: var(--on-primary); }
.primary:hover:not(:disabled) { box-shadow: var(--elev-1); border-radius: var(--shape-full); }
.primary:active:not(:disabled) { border-radius: var(--shape-m); }
.text-button { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 16px 0 12px; border: 0; border-radius: var(--shape-full); background: var(--secondary-container); color: var(--on-secondary-container); font-weight: 500; }
.text-button .svg-icon { width: 20px; height: 20px; }

/* ===== Layout ===== */
.main-stack { display: grid; gap: 16px; padding: 8px 0 24px; }

/* ===== Account card ===== */
.account-card { min-width: 0; padding: 24px 28px; border-radius: var(--shape-xl); background: var(--surface-c-low); }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.card-header-copy { min-width: 0; }
h1 { font-size: clamp(26px, 3.4vw, 36px); line-height: 1.2; font-weight: 400; letter-spacing: -.01em; }
.card-header p { margin-top: 6px; max-width: 64ch; color: var(--on-surface-variant); font-size: 14px; line-height: 20px; }
.privacy-chip { flex: none; display: inline-flex; align-items: center; height: 32px; padding: 0 12px; border-radius: var(--shape-s); border: 1px solid var(--outline-variant); color: var(--on-surface-variant); font-size: 13px; font-weight: 500; white-space: nowrap; }

.account-controls { display: flex; gap: 12px; align-items: stretch; }
.field {
  position: relative; flex: 1; min-width: 0; display: flex; align-items: center;
  height: 56px; border-radius: var(--shape-l); background: var(--surface-c-highest);
  transition: box-shadow .2s var(--ease), background-color .2s;
}
.field:focus-within { box-shadow: inset 0 0 0 2px var(--primary); background: var(--surface-c-lowest); }
.field.invalid { box-shadow: inset 0 0 0 2px var(--error); }
.field-leading { display: grid; place-items: center; width: 52px; flex: none; color: var(--on-surface-variant); }
.field input {
  flex: 1; min-width: 0; width: 100%; height: 100%; padding: 0 4px; border: 0; outline: 0; background: transparent;
  color: var(--on-surface); font-family: var(--mono); font-size: 14px; text-overflow: ellipsis;
}
.field input::placeholder { color: var(--on-surface-variant); opacity: .8; }
.field-trailing { display: flex; align-items: center; gap: 2px; padding-right: 8px; flex: none; }

.form-foot { margin-top: 12px; padding-inline: 4px; color: var(--on-surface-variant); font-size: 12px; line-height: 18px; }
.status {
  display: flex; align-items: flex-start; gap: 12px; margin-top: 14px; padding: 14px 16px;
  border-radius: var(--shape-l); background: var(--secondary-container); color: var(--on-secondary-container);
  font-size: 14px; line-height: 20px; overflow-wrap: anywhere; animation: rise .35s var(--ease);
}
.status .svg-icon { width: 20px; height: 20px; }
.status > span { min-width: 0; flex: 1; }
.status[data-tone="error"] { background: var(--error-container); color: var(--on-error-container); }
.status[data-tone="success"] { background: var(--success-container); color: var(--on-success-container); }

/* ===== Mailbox ===== */
.mailbox {
  display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 16px; min-height: 620px; min-width: 0;
}
.inbox, .reading { min-width: 0; border-radius: var(--shape-xl); overflow: hidden; }
.inbox { display: flex; flex-direction: column; background: var(--surface-c-low); max-height: calc(100vh - 110px); position: sticky; top: 88px; align-self: start; }
.inbox-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; padding: 12px 12px 8px 24px; flex: none; }
.inbox-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.inbox-title h2 { font-size: 22px; line-height: 28px; font-weight: 400; }
.count { display: inline-grid; place-items: center; min-width: 28px; height: 24px; padding: 0 8px; border-radius: var(--shape-full); background: var(--primary); color: var(--on-primary); font-size: 12px; font-weight: 500; }
#refresh.spinning .svg-icon { animation: spin .9s linear infinite; }

.messages { list-style: none; margin: 0; padding: 4px 8px 12px; overflow-y: auto; overflow-x: hidden; flex: 1; min-height: 0; scrollbar-width: thin; }
.messages li { min-width: 0; }
.messages li + li { margin-top: 2px; }
.message {
  position: relative; isolation: isolate; overflow: hidden;
  display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: 14px; align-items: center;
  width: 100%; min-width: 0; padding: 12px 14px; border: 0; border-radius: var(--shape-l);
  background: transparent; color: var(--on-surface); text-align: left;
  transition: background-color .2s var(--ease), border-radius .25s var(--ease);
}
.message[aria-current="true"] { background: var(--secondary-container); color: var(--on-secondary-container); border-radius: var(--shape-xl); }
.message-avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; font-size: 15px; font-weight: 500; color: var(--av-fg); background: var(--av-bg); }
.message-body { display: grid; gap: 2px; min-width: 0; }
.message-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.message-from { flex: 1 1 auto; min-width: 0; font-size: 14px; font-weight: 500; }
.message time { flex: none; font-size: 12px; color: var(--on-surface-variant); white-space: nowrap; }
.message[aria-current="true"] time { color: inherit; opacity: .8; }
.message-subject { display: block; font-size: 14px; color: var(--on-surface-variant); }
.message[aria-current="true"] .message-subject { color: inherit; }
.message-from, .message-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.inbox-state { padding: 24px; color: var(--on-surface-variant); text-align: center; }

/* ===== Reading pane ===== */
.reading { background: var(--surface-c-lowest); padding: 28px 32px 32px; display: flex; flex-direction: column; box-shadow: inset 0 0 0 1px var(--outline-variant); }
[data-theme="dark"] .reading { background: var(--surface-c); box-shadow: none; }
.reading > * { min-width: 0; max-width: 100%; }
.reading h2 { font-size: clamp(22px, 2.4vw, 28px); line-height: 1.28; font-weight: 400; overflow-wrap: anywhere; word-break: break-word; outline: none; }
.sender { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 14px; margin-top: 20px; }
.avatar { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; font-size: 16px; font-weight: 500; color: var(--av-fg); background: var(--av-bg); }
.sender-info { min-width: 0; }
.brand-anthropic { background: #f0eee6; color: #141413; box-shadow: inset 0 0 0 1px rgba(20, 20, 19, .08); }
.brand-anthropic .svg-icon { width: 55%; height: 55%; }
[data-theme="dark"] .brand-anthropic { background: #d97757; color: #141413; box-shadow: none; }
.sender-info strong { display: block; font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-info span { display: block; font-size: 13px; color: var(--on-surface-variant); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender time { font-size: 12px; color: var(--on-surface-variant); white-space: nowrap; text-align: right; }
.recipient { display: flex; gap: 6px; margin-top: 12px; font-size: 13px; color: var(--on-surface-variant); min-width: 0; }
.recipient b { font-weight: 500; flex: none; }
.recipient span { min-width: 0; overflow-wrap: anywhere; }

.view-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 20px 0 12px; flex-wrap: wrap; }
.seg { display: inline-flex; height: 40px; border: 1px solid var(--outline); border-radius: var(--shape-full); overflow: hidden; }
.seg button { position: relative; isolation: isolate; overflow: hidden; display: inline-flex; align-items: center; gap: 6px; min-width: 96px; justify-content: center; padding: 0 16px; border: 0; background: transparent; color: var(--on-surface); font-size: 14px; font-weight: 500; }
.seg button + button { border-left: 1px solid var(--outline); }
.seg button .svg-icon { width: 18px; height: 18px; display: none; }
.seg button[aria-pressed="true"] { background: var(--secondary-container); color: var(--on-secondary-container); }
.seg button[aria-pressed="true"] .svg-icon { display: block; }

.mail-body { display: block; width: 100%; min-width: 0; flex: 1; min-height: 520px; border: 0; border-radius: var(--shape-l); background: #fff; }
.plain-body {
  margin: 0; padding: 20px; overflow: auto; background: var(--surface-c-low); color: var(--on-surface);
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  font: 14px/1.6 var(--font);
}
.attachments { margin-top: 20px; }
.attachments h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 14px; font-weight: 500; color: var(--on-surface-variant); }
.attachments h3 .svg-icon { width: 18px; height: 18px; }
.attachment-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.attachment {
  position: relative; isolation: isolate; overflow: hidden;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px;
  min-width: 0; padding: 10px 12px; border: 1px solid var(--outline-variant); border-radius: var(--shape-l);
  background: var(--surface-c-low); color: var(--on-surface); text-align: left;
}
.file-kind { display: grid; place-items: center; min-width: 40px; height: 40px; padding: 0 6px; border-radius: var(--shape-m); background: var(--tertiary-container); color: var(--on-tertiary-container); font-size: 11px; font-weight: 700; letter-spacing: .04em; }
.file-meta { min-width: 0; display: grid; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.file-size { font-size: 12px; color: var(--on-surface-variant); }
.attachment > .svg-icon { width: 20px; height: 20px; color: var(--primary); }
.attachment:disabled > .svg-icon { animation: pulse 1s ease-in-out infinite; }

.reading-state { flex: 1; display: grid; place-content: center; justify-items: center; gap: 16px; min-height: 360px; text-align: center; color: var(--on-surface-variant); padding: 24px; }
.reading-state p { max-width: 36ch; overflow-wrap: anywhere; }
.empty-art { display: grid; place-items: center; width: 96px; height: 96px; border-radius: 32px; background: var(--primary-container); color: var(--on-primary-container); }
.empty-art .svg-icon { width: 44px; height: 44px; }
.spinner { width: 48px; height: 48px; border-radius: 50%; border: 4px solid var(--primary-container); border-top-color: var(--primary); animation: spin .9s linear infinite; }

/* skeletons */
.skeleton { display: grid; grid-template-columns: 40px minmax(0,1fr); gap: 14px; align-items: center; padding: 12px 14px; }
.skeleton i { display: block; border-radius: var(--shape-full); background: var(--surface-c-highest); animation: pulse 1.4s ease-in-out infinite; }
.skeleton .sk-av { width: 40px; height: 40px; border-radius: 50%; }
.skeleton .sk-lines { display: grid; gap: 8px; }
.skeleton .sk-lines i:first-child { height: 12px; width: 70%; }
.skeleton .sk-lines i:last-child { height: 10px; width: 90%; }

.back { display: none; align-self: flex-start; margin-bottom: 16px; }

.app-footer { display: flex; align-items: center; gap: 10px; padding: 8px 4px; color: var(--on-surface-variant); font-size: 12px; }
.app-footer .svg-icon { width: 18px; height: 18px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .45; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ===== Responsive ===== */
@media (max-width: 960px) {
  .local span { display: none; }
  .local { padding: 0 7px; }
  .mailbox { grid-template-columns: minmax(260px, 320px) minmax(0, 1fr); }
  .reading { padding: 22px 20px; }
}
@media (max-width: 760px) {
  .wrap { width: calc(100% - 24px); }
  .masthead-inner { min-height: 64px; }
  .brand-mark { width: 40px; height: 40px; border-radius: var(--shape-m); }
  .brand-text strong { font-size: 18px; line-height: 24px; }
  .palette-picker { display: none; }
  .account-card { padding: 20px 16px; border-radius: 24px; }
  .card-header { flex-direction: column; gap: 10px; }
  .account-controls { flex-direction: column; }
  .button.primary { width: 100%; }
  .mailbox { display: block; min-height: 0; }
  .inbox { position: static; max-height: none; }
  .reading { display: none; padding: 16px; border-radius: 24px; }
  .mailbox[data-mobile-view="message"] .reading { display: flex; }
  .mailbox[data-mobile-view="message"] .inbox { display: none; }
  .back { display: inline-flex; }
  .mail-body { min-height: 60vh; }
  .sender { grid-template-columns: 40px minmax(0, 1fr); }
  .sender time { grid-column: 2; text-align: left; }
  .avatar { width: 40px; height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
