:root {
  --ink: #1b2d3c;
  --muted: #6c7e8c;
  --line: #dce5ea;
  --paper: #fff;
  --wash: #f5f8fa;
  --accent: #146d91;
  --accent-dark: #0d506b;
  --accent-wash: #e4f3f8;
  --danger: #b43232;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--wash);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--wash); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid #7fc7df; outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.form-error { min-height: 1.2rem; margin: .55rem 0; color: var(--danger); font-size: .875rem; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(circle at 15% 15%, #d5eef5, transparent 36%), #f6f9fa; }
.login-card { width: min(100%, 410px); padding: 2.5rem; background: var(--paper); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 20px 55px #16394a1b; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; color: #fff; background: linear-gradient(145deg, #1c89ae, #125d7b); font-family: Georgia, serif; font-size: 1.5rem; font-weight: 700; }
.brand-mark.small { width: 30px; height: 30px; border-radius: 9px; font-size: 1.1rem; }
.eyebrow { margin: 1.2rem 0 .35rem; letter-spacing: .16em; color: var(--accent); font-size: .7rem; font-weight: 700; }
.login-card h1 { margin: 0 0 .6rem; font-size: 1.55rem; }
.login-card form { margin-top: 1.65rem; display: grid; gap: .6rem; }
label { display: grid; gap: .42rem; font-size: .875rem; font-weight: 650; }
input, textarea { width: 100%; padding: .72rem .78rem; color: var(--ink); background: #fff; border: 1px solid #bfccd4; border-radius: 8px; }
textarea { resize: vertical; line-height: 1.55; }
.button { border: 1px solid transparent; border-radius: 8px; padding: .68rem 1rem; font-weight: 700; transition: .16s ease; }
.button.primary { color: #fff; background: var(--accent); box-shadow: 0 1px 2px #09394c33; }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { color: var(--ink); background: #fff; border-color: var(--line); }
.button.secondary:hover { background: var(--wash); }
.button.full { width: 100%; margin-top: .25rem; }

.app-shell { height: 100vh; display: grid; grid-template: 64px minmax(0, 1fr) / 242px 400px minmax(360px, 1fr); overflow: hidden; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 1.5rem; padding: 0 1.1rem 0 1.35rem; background: #fff; border-bottom: 1px solid var(--line); }
.topbar-brand { width: 202px; display: flex; align-items: center; gap: .62rem; font-size: 1.05rem; letter-spacing: -.02em; white-space: nowrap; }
.search-box { width: min(610px, calc(100vw - 420px)); display: flex; align-items: center; gap: .65rem; padding: .05rem .8rem; color: #587080; background: var(--wash); border: 1px solid transparent; border-radius: 9px; }
.search-box:focus-within { background: #fff; border-color: #99c4d3; box-shadow: 0 0 0 2px #d9f0f7; }
.search-box input { padding: .62rem 0; border: 0; background: transparent; outline: 0; }
.topbar .icon-button { margin-left: auto; }
.icon-button { display: inline-grid; width: 35px; height: 35px; place-items: center; color: #3e5564; background: transparent; border: 0; border-radius: 50%; font-size: 1.25rem; }
.icon-button:hover { background: #eaf0f3; }
.sidebar { padding: 1rem .75rem; background: #fff; border-right: 1px solid var(--line); overflow-y: auto; }
.compose { width: 100%; margin: .1rem 0 1.2rem; text-align: left; box-shadow: 0 4px 12px #13546d28; }
.folders { display: grid; gap: .2rem; }
.folder { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: .62rem .68rem; color: #526673; background: transparent; border: 0; border-radius: 7px; font-size: .9rem; text-align: left; }
.folder:hover { background: #eff5f7; }
.folder.active { color: #0d5975; background: var(--accent-wash); font-weight: 750; }
.folder strong { min-width: 1.4rem; text-align: right; }
.sidebar-note { margin: 2rem .65rem; color: #8a99a3; font-size: .74rem; line-height: 1.6; }
.mail-list-panel { display: flex; flex-direction: column; min-width: 0; background: #fff; border-right: 1px solid var(--line); }
.panel-toolbar { display: flex; justify-content: space-between; align-items: center; min-height: 84px; padding: 1rem 1rem 1rem 1.2rem; border-bottom: 1px solid var(--line); }
.panel-toolbar h1 { margin: 0; font-size: 1.05rem; }
.panel-toolbar p { margin: .28rem 0 0; font-size: .78rem; }
.mail-list { overflow-y: auto; }
.mail-row { display: grid; grid-template-columns: 25px minmax(92px, .72fr) minmax(0, 1.8fr) 17px 73px; align-items: center; gap: .35rem; width: 100%; padding: .72rem .7rem; color: var(--ink); background: #fff; border: 0; border-bottom: 1px solid #eef2f4; text-align: left; }
.mail-row:hover { background: #f6fafb; box-shadow: inset 3px 0 var(--accent); }
.mail-row.selected { background: #eaf5f8; box-shadow: inset 3px 0 var(--accent); }
.mail-row.unread { background: #f2f9fb; font-weight: 750; }
.star { color: #9aaab2; font-size: 1.05rem; }
.mail-row.starred .star { color: #db9a20; }
.sender, .subject, .preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender { font-size: .85rem; }
.mail-copy { min-width: 0; display: flex; gap: .25rem; overflow: hidden; font-size: .84rem; }
.preview { color: var(--muted); font-weight: 400; }
.attachment-indicator { color: #67818f; transform: rotate(35deg); }
.mail-row time { color: #71828c; font-size: .72rem; text-align: right; }
.reader-panel { min-width: 0; overflow-y: auto; background: #fff; }
.empty-reader { height: 100%; display: grid; place-content: center; justify-items: center; padding: 2rem; text-align: center; color: var(--muted); }
.empty-reader h2 { margin: 1rem 0 .25rem; color: var(--ink); font-size: 1.1rem; }
.empty-reader p { margin: 0; font-size: .9rem; }
.empty-symbol { display: grid; width: 55px; height: 55px; place-items: center; color: var(--accent); background: var(--accent-wash); border-radius: 50%; font-size: 1.55rem; }
.reader { padding: 1.6rem clamp(1.2rem, 4vw, 3rem) 2rem; }
.reader-heading { display: flex; align-items: start; gap: 1rem; margin-bottom: 1.5rem; }
.reader-heading h1 { flex: 1; margin: .25rem 0; font-size: clamp(1.22rem, 2vw, 1.62rem); line-height: 1.35; }
.message-card { padding: 1rem 0 1.4rem; border-top: 1px solid #e8eef1; }
.message-card:first-of-type { border-top: 0; }
.message-meta { display: flex; align-items: start; gap: .65rem; }
.avatar { flex: 0 0 auto; display: grid; width: 34px; height: 34px; place-items: center; color: #fff; background: #467e94; border-radius: 50%; font-weight: 750; }
.message-from { flex: 1; min-width: 0; font-size: .9rem; }
.message-from strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-from small { color: var(--muted); font-size: .75rem; }
.message-time { color: var(--muted); font-size: .75rem; white-space: nowrap; }
.message-content { margin: 1rem 0 0 2.65rem; color: #213846; line-height: 1.65; font-size: .94rem; }
.message-content pre { margin: 0; font: inherit; white-space: pre-wrap; }
.email-frame { width: 100%; min-height: 160px; border: 0; }
.attachment-list { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0 0 2.65rem; }
.attachment { display: inline-flex; align-items: center; gap: .45rem; max-width: 100%; padding: .47rem .6rem; color: var(--accent-dark); background: #f0f6f8; border: 1px solid #d6e4e9; border-radius: 6px; font-size: .8rem; text-decoration: none; }
.attachment:hover { background: #e3f0f4; }
.reply-panel { margin: 1.3rem 0 0 2.65rem; padding: .9rem; border: 1px solid #d7e2e7; border-radius: 9px; background: #fbfdfe; }
.reply-panel textarea { min-height: 100px; border-color: transparent; background: transparent; }
.reply-panel textarea:focus { border-color: #9fc8d7; background: #fff; }
.reply-actions { display: flex; justify-content: space-between; align-items: center; margin-top: .6rem; }
.reply-actions .form-error { margin: 0; }
.list-empty { padding: 2.5rem 1.5rem; color: var(--muted); text-align: center; }

.compose-dialog { width: min(640px, calc(100% - 2rem)); padding: 0; color: var(--ink); border: 1px solid #a9bdc8; border-radius: 12px; box-shadow: 0 24px 80px #062f412e; }
.compose-dialog::backdrop { background: #09253470; }
.compose-dialog form { display: grid; gap: .8rem; padding: 1rem 1.2rem 1.2rem; }
.dialog-title { display: flex; align-items: center; justify-content: space-between; margin: -.1rem 0 .35rem; }
.dialog-title h2 { margin: 0; font-size: 1.1rem; }
.dialog-actions { display: flex; justify-content: end; gap: .65rem; }

@media (max-width: 900px) {
  .app-shell { grid-template: 58px minmax(0, 1fr) / 64px minmax(280px, 42%) minmax(0, 1fr); }
  .topbar { gap: .7rem; padding: 0 .65rem; }
  .topbar-brand { width: auto; }
  .topbar-brand > span:last-child, .compose span, .folder span { display: none; }
  .sidebar { padding: .7rem .45rem; }
  .compose { padding: .65rem; text-align: center; }
  .folder { justify-content: center; padding: .65rem .2rem; }
  .folder strong { position: absolute; margin: -24px 0 0 20px; font-size: .7rem; }
  .sidebar-note { display: none; }
  .search-box { width: auto; flex: 1; }
  .mail-row { grid-template-columns: 20px minmax(72px, .6fr) minmax(0, 1.6fr) 12px 56px; padding: .68rem .45rem; }
}

@media (max-width: 680px) {
  .app-shell { display: block; height: auto; min-height: 100vh; overflow: auto; }
  .topbar { position: sticky; top: 0; z-index: 2; min-height: 58px; }
  .topbar-brand { display: none; }
  .sidebar { display: flex; gap: .5rem; padding: .65rem; border: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .compose { width: auto; margin: 0; white-space: nowrap; }
  .folders { display: flex; }
  .folder { width: auto; white-space: nowrap; }
  .folder span { display: inline; }
  .folder strong { position: static; margin: 0 0 0 .3rem; }
  .mail-list-panel { min-height: 45vh; border-right: 0; }
  .reader-panel { min-height: 55vh; border-top: 6px solid var(--wash); }
  .mail-row { grid-template-columns: 22px 88px minmax(0, 1fr) 12px 54px; }
  .message-content, .attachment-list, .reply-panel { margin-left: 0; }
}
