:root {
  --forest: #1B4332;
  --forest-2: #2D6A4F;
  --gold: #C8A951;
  --gold-soft: #F4ECD6;
  --cream: #FAFAF8;
  --paper: #FFFFFF;
  --ink: #1F2421;
  --ink-2: #4B524E;
  --muted: #7A817D;
  --line: #E8E6E0;
  --hover: #F3F2EE;
  --active: #EAF1EC;
  --danger: #A63D32;
  --radius: 12px;
  --shadow: 0 10px 40px rgba(27, 67, 50, .16);
  --display: "Fraunces", Georgia, serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--cream); color: var(--ink); font: 14px/1.45 var(--body); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Brand */
.brand { display: flex; align-items: center; gap: 9px; font: 600 19px/1 var(--display); color: var(--forest); letter-spacing: -.01em; }
.brand-sub { color: var(--gold); font-weight: 600; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--forest); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; inset: 8px 6px; border: 1.8px solid var(--gold); border-radius: 2px;
  background: linear-gradient(to bottom right, transparent 47%, var(--gold) 48%, var(--gold) 53%, transparent 54%) top left / 50% 60% no-repeat,
              linear-gradient(to bottom left, transparent 47%, var(--gold) 48%, var(--gold) 53%, transparent 54%) top right / 50% 60% no-repeat; }
.brand-lg { font-size: 28px; justify-content: center; }
.brand-lg .brand-mark { width: 34px; height: 34px; border-radius: 9px; }
.brand-lg .brand-mark::after { inset: 10px 8px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid transparent; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--forest); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--forest-2); }
.btn-gold { background: var(--gold); color: #1d1a10; }
.btn-gold:hover { background: #d3b765; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { background: var(--hover); }
.btn-block { width: 100%; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; font-weight: 500; border-radius: 8px; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.link-btn { border: 0; background: none; padding: 0; color: var(--forest); font-weight: 500; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 20% -10%, #E3EDE6 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, var(--gold-soft) 0%, transparent 55%), var(--cream); }
.login-card { width: 100%; max-width: 380px; background: var(--paper); border: 1px solid var(--line); border-radius: 18px; padding: 36px 30px 30px; box-shadow: var(--shadow); }
.login-lead { text-align: center; color: var(--muted); margin: 10px 0 26px; }
.login-card label { display: block; font-weight: 600; margin-bottom: 6px; }
.login-card input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font: inherit; font-size: 15px; background: var(--cream); }
.login-card input:focus { outline: none; border-color: var(--forest); background: #fff; box-shadow: 0 0 0 3px rgba(27, 67, 50, .12); }
.form-error { color: var(--danger); min-height: 20px; margin: 8px 0; font-size: 13px; }

/* App layout */
.app { display: grid; grid-template-columns: 248px minmax(320px, 400px) 1fr; height: 100vh; height: 100dvh; }
.sidebar { background: var(--paper); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 14px; overflow-y: auto; }
.sidebar-head { padding: 2px 6px 18px; }
.compose-btn { margin-bottom: 16px; height: 42px; }
.side-label { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 18px 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; text-align: left; color: var(--ink-2); font-weight: 500; }
.nav-item:hover { background: var(--hover); color: var(--ink); }
.nav-item.active { background: var(--active); color: var(--forest); font-weight: 600; }
.nav-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { font-size: 12px; font-weight: 600; color: var(--forest); background: var(--gold-soft); border-radius: 20px; padding: 1px 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--forest)); flex: none; }
.side-foot { margin-top: auto; padding: 18px 10px 4px; border-top: 1px solid var(--line); }

.list-pane { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); background: var(--cream); }
.list-head { display: flex; align-items: center; gap: 8px; padding: 16px 16px 10px; }
.list-title { flex: 1; min-width: 0; }
.list-title h1 { margin: 0; font: 600 22px/1.2 var(--display); color: var(--ink); }
.list-sub { color: var(--muted); font-size: 12.5px; }
.search { margin: 0 16px 10px; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; color: var(--muted); }
.search:focus-within { border-color: var(--forest); box-shadow: 0 0 0 3px rgba(27, 67, 50, .1); }
.search input { flex: 1; border: 0; outline: none; background: transparent; font: inherit; color: var(--ink); min-width: 0; }
.list { flex: 1; overflow-y: auto; padding: 0 8px 16px; }
.row { display: flex; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent; border-radius: 11px; padding: 11px 10px; cursor: pointer; position: relative; }
.row + .row { margin-top: 2px; }
.row:hover { background: var(--hover); }
.row.active { background: var(--paper); box-shadow: 0 1px 0 var(--line), 0 0 0 1px var(--line); }
.row .dot { margin-top: 6px; }
.row-main { flex: 1; min-width: 0; }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-from { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.row-date { font-size: 12px; color: var(--muted); flex: none; }
.row-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); margin-top: 1px; }
.row.unread .row-from, .row.unread .row-subject { color: var(--ink); font-weight: 600; }
.row.unread::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 3px; background: var(--gold); }
.row-meta { display: flex; align-items: center; gap: 6px; margin-top: 6px; color: var(--muted); font-size: 12px; }
.row-meta svg { width: 14px; height: 14px; }
.chip { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
  color: var(--c, var(--forest)); background: color-mix(in srgb, var(--c, var(--forest)) 10%, white); white-space: nowrap; }
.star { color: var(--gold); }
.star svg { fill: currentColor; }
.nav-item .domain { color: var(--muted); font-weight: 400; font-size: 12px; }
.nav-item.active .domain { color: var(--forest-2); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty strong { display: block; font: 600 17px var(--display); color: var(--ink-2); margin-bottom: 4px; }
.skeleton { height: 64px; border-radius: 11px; margin: 4px 0; background: linear-gradient(90deg, #efeee9 0%, #f7f6f2 50%, #efeee9 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Reader */
.reader-pane { display: flex; flex-direction: column; min-width: 0; background: var(--paper); }
.reader-empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px; }
.reader-empty .brand-mark { margin: 0 auto 14px; width: 44px; height: 44px; border-radius: 12px; opacity: .9; }
.reader-empty .brand-mark::after { inset: 13px 10px; }
.reader-top { display: flex; align-items: center; gap: 4px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.reader-top .spacer { flex: 1; }
.reader-head { padding: 20px 28px 14px; }
.reader-head h2 { margin: 0 0 14px; font: 600 23px/1.25 var(--display); color: var(--ink); word-break: break-word; }
.sender { display: flex; gap: 12px; align-items: flex-start; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; color: #fff; background: var(--c, var(--forest)); flex: none; }
.sender-main { flex: 1; min-width: 0; }
.sender-name { font-weight: 600; }
.sender-email { color: var(--muted); font-weight: 400; }
.sender-to { color: var(--muted); font-size: 13px; margin-top: 2px; word-break: break-word; }
.sender-date { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.reader-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.images-bar { display: flex; align-items: center; gap: 10px; margin: 0 28px 10px; padding: 8px 12px; background: var(--gold-soft); border-radius: 9px; font-size: 13px; color: #6a5720; }
.reader-body { flex: 1; min-height: 0; display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.reader-body iframe { flex: 1; width: 100%; border: 0; background: #fff; min-height: 300px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 28px 18px; border-top: 1px solid var(--line); }
.att { display: inline-flex; align-items: center; gap: 8px; max-width: 280px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); text-decoration: none; background: var(--cream); }
.att:hover { border-color: var(--forest); }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att small { color: var(--muted); flex: none; }
.back-btn { margin-right: 4px; }

/* Compose */
.compose-wrap { position: fixed; inset: 0; background: rgba(20, 30, 25, .35); display: grid; place-items: center; padding: 20px; z-index: 30; }
.compose { width: 100%; max-width: 720px; height: min(760px, 100%); background: var(--paper); border-radius: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.compose-head { display: flex; align-items: center; padding: 14px 14px 10px 22px; border-bottom: 1px solid var(--line); }
.compose-head h2 { flex: 1; margin: 0; font: 600 19px var(--display); }
.compose-fields { padding: 4px 22px 0; }
.field { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); min-height: 44px; }
.field > span { width: 58px; color: var(--muted); font-size: 13px; flex: none; }
.field input, .field select { flex: 1; min-width: 0; border: 0; outline: none; font: inherit; font-size: 14.5px; background: transparent; height: 42px; color: var(--ink); }
.field select { cursor: pointer; font-weight: 600; color: var(--forest); }
.cc-toggle { display: flex; justify-content: flex-end; margin: -32px 0 0; height: 32px; align-items: center; pointer-events: none; }
.cc-toggle .link-btn { pointer-events: auto; font-size: 13px; }
.compose-body { flex: 1; border: 0; outline: none; resize: none; padding: 16px 22px; font: 15px/1.55 var(--body); color: var(--ink); }
.compose-atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 22px; }
.compose-atts .chip { --c: var(--ink-2); height: 26px; }
.compose-atts .chip button { border: 0; background: none; cursor: pointer; padding: 0; color: inherit; font-size: 15px; line-height: 1; }
.compose-foot { display: flex; align-items: center; gap: 10px; padding: 12px 22px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.compose-foot .form-error { margin: 0; flex: 1; min-height: 0; }
.attach-btn { cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; z-index: 40; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

.only-mobile { display: none; }
.scrim { display: none; }

@media (max-width: 1100px) {
  .app { grid-template-columns: 220px minmax(300px, 360px) 1fr; }
}
@media (max-width: 1320px) and (min-width: 861px) {
  .reader-top .btn-sm span { display: none; }
  .reader-top .btn-sm { width: 36px; padding: 0; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .app.menu-open .sidebar { transform: none; }
  .app.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(20, 30, 25, .3); z-index: 15; }
  .list-pane { border-right: 0; }
  .reader-pane { position: fixed; inset: 0; z-index: 10; transform: translateX(100%); transition: transform .2s; }
  .app.reading .reader-pane { transform: none; }
  .reader-head { padding: 16px 16px 12px; }
  .images-bar { margin: 0 16px 10px; }
  .attachments { padding: 12px 16px 16px; }
  .compose-wrap { padding: 0; }
  .compose { height: 100%; max-width: none; border-radius: 0; }
  .field > span { width: 52px; }
}
