:root {
  color-scheme: light;
  --paper: #f1eee5;
  --paper-deep: #e5e0d4;
  --ink: #171714;
  --muted: #6d695f;
  --line: #c8c2b4;
  --accent: #f04424;
  --green: #237b52;
  --mono: "Azeret Mono", monospace;
  --serif: "Instrument Serif", Georgia, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--mono);
  font-size: 12px;
}

button, input, textarea, select { font: inherit; }
button { color: inherit; }

.grain {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: .16;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E");
}

.masthead {
  height: 64px;
  display: grid;
  grid-template-columns: 240px 1fr auto;
  align-items: center;
  border-bottom: 1px solid var(--ink);
  padding-right: 22px;
}

.wordmark {
  height: 100%;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 0 18px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: .13em;
  border-right: 1px solid var(--ink);
}

.mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  color: var(--paper);
  background: var(--accent);
  letter-spacing: -.12em;
}

.system-state {
  justify-self: center;
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .12em;
}

.pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px #237b5218; }

.shell { min-height: calc(100vh - 64px); display: grid; grid-template-columns: 240px 1fr; }
.rail { position: relative; display: flex; flex-direction: column; min-height: calc(100vh - 64px); border-right: 1px solid var(--ink); background: var(--paper-deep); }
.rail-heading, .section-bar { height: 48px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px 0 18px; border-bottom: 1px solid var(--line); font-size: 10px; letter-spacing: .12em; }
.square-button { border: 1px solid var(--ink); background: transparent; width: 28px; height: 28px; cursor: pointer; font-size: 18px; line-height: 1; }
.square-button:hover { color: var(--paper); background: var(--ink); }
.inbox-list { flex: 1; }
.inbox-item { width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 16px 18px; cursor: pointer; }
.inbox-item:hover, .inbox-item.active { background: var(--paper); }
.inbox-item.active { box-shadow: inset 3px 0 var(--accent); }
.inbox-item strong, .inbox-item span { display: block; overflow: hidden; text-overflow: ellipsis; }
.inbox-item strong { margin-bottom: 8px; font-size: 11px; font-weight: 500; }
.inbox-item span { color: var(--muted); font-size: 9px; letter-spacing: .08em; }
.rail-note { margin: 18px; padding-top: 15px; border-top: 1px solid var(--ink); color: var(--muted); font-size: 9px; line-height: 1.7; }
.rail-note span { display: block; color: var(--ink); margin-bottom: 6px; letter-spacing: .1em; }

.workspace { min-width: 0; }
.empty-state { min-height: calc(100vh - 64px); padding: 11vh 9vw 8vh; position: relative; overflow: hidden; }
.empty-state::after { content: "@"; position: absolute; right: 2vw; bottom: -24vh; color: transparent; -webkit-text-stroke: 1px var(--line); font-family: var(--serif); font-size: min(70vw, 840px); line-height: 1; z-index: -1; }
.eyebrow { display: block; margin-bottom: 20px; font-size: 10px; letter-spacing: .16em; color: var(--accent); }
.empty-state h1, .inbox-header h1, .dialog-panel h2 { font-family: var(--serif); font-weight: 400; }
.empty-state h1 { margin: 0 0 28px; max-width: 760px; font-size: clamp(62px, 8vw, 126px); line-height: .78; letter-spacing: -.045em; }
.empty-state h1 em { font-weight: 400; color: var(--accent); }
.empty-state p { max-width: 520px; margin: 0 0 35px; color: var(--muted); line-height: 1.8; font-size: 13px; }

.primary-button, .secondary-button { border: 1px solid var(--ink); padding: 13px 16px; cursor: pointer; letter-spacing: .05em; font-weight: 600; }
.primary-button { display: inline-flex; justify-content: space-between; gap: 35px; color: var(--paper); background: var(--ink); }
.primary-button:hover { color: var(--paper); border-color: var(--accent); background: var(--accent); }
.primary-button:disabled { opacity: .45; cursor: wait; }
.secondary-button { background: transparent; }
.secondary-button:hover { background: var(--paper-deep); }
.text-button { padding: 4px 0; border: 0; border-bottom: 1px solid transparent; color: var(--muted); background: none; cursor: pointer; font-size: 10px; letter-spacing: .08em; }
.text-button:hover { color: var(--ink); border-color: var(--ink); }

.inbox-view { min-height: calc(100vh - 64px); }
.inbox-header { min-height: 180px; display: flex; align-items: end; justify-content: space-between; gap: 28px; padding: 32px 36px; border-bottom: 1px solid var(--ink); }
.inbox-header h1 { margin: 0 0 12px; max-width: 820px; overflow-wrap: anywhere; font-size: clamp(30px, 4.2vw, 70px); line-height: .9; letter-spacing: -.025em; }
.meta-line { display: flex; gap: 20px; color: var(--muted); font-size: 9px; letter-spacing: .08em; }
.header-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.message-layout { display: grid; grid-template-columns: minmax(330px, .9fr) minmax(400px, 1.1fr); min-height: calc(100vh - 245px); }
.message-column { border-right: 1px solid var(--ink); }
.section-bar div { display: flex; gap: 14px; }
.message-list { max-height: calc(100vh - 293px); overflow: auto; }
.message-row { width: 100%; display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; padding: 18px; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: transparent; cursor: pointer; }
.message-row:hover, .message-row.active { background: #faf7ef; }
.direction { align-self: start; padding: 3px 5px; border: 1px solid var(--line); font-size: 8px; letter-spacing: .08em; }
.direction.outbound { color: var(--accent); border-color: var(--accent); }
.message-summary { min-width: 0; }
.message-summary strong, .message-summary span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.message-summary strong { margin-bottom: 6px; font-size: 11px; }
.message-summary span { color: var(--muted); font-size: 10px; }
.message-time { color: var(--muted); font-size: 9px; }
.no-messages { padding: 55px 20px; color: var(--muted); text-align: center; line-height: 1.8; }

.message-detail { min-width: 0; padding: 36px; background: #f7f3ea; }
.detail-placeholder { max-width: 360px; margin: 13vh auto; color: var(--muted); text-align: center; line-height: 1.7; }
.detail-placeholder span { display: block; color: var(--ink); margin-bottom: 10px; font-size: 10px; letter-spacing: .1em; }
.detail-header { padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.detail-header h2 { margin: 6px 0 18px; font-family: var(--serif); font-size: 38px; font-weight: 400; line-height: 1; }
.detail-routing { display: grid; grid-template-columns: 56px 1fr; gap: 6px 12px; color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.detail-routing span:nth-child(odd) { color: var(--ink); }
.message-body { padding: 32px 0; white-space: pre-wrap; font-family: ui-monospace, monospace; font-size: 13px; line-height: 1.75; }
.attachment-list { margin-bottom: 25px; padding: 12px; border: 1px dashed var(--line); color: var(--muted); }
.reply-form { border-top: 1px solid var(--ink); padding-top: 20px; }
.reply-form label { display: block; margin-bottom: 10px; font-size: 9px; letter-spacing: .1em; }
.reply-form textarea { width: 100%; min-height: 120px; margin-bottom: 8px; }

dialog { width: min(92vw, 560px); padding: 0; border: 1px solid var(--ink); color: var(--ink); background: var(--paper); box-shadow: 16px 16px 0 #17171426; }
dialog::backdrop { background: #171714b8; backdrop-filter: blur(3px); }
.dialog-panel { position: relative; padding: 34px; }
.dialog-panel.wide { width: min(92vw, 620px); }
.dialog-index { margin-bottom: 40px; color: var(--accent); font-size: 9px; letter-spacing: .12em; }
.dialog-close { position: absolute; right: 18px; top: 15px; border: 0; background: none; font-size: 28px; cursor: pointer; }
.dialog-panel h2 { margin: 0 0 12px; font-size: 48px; line-height: .95; }
.dialog-panel > p { margin: 0 0 28px; color: var(--muted); line-height: 1.65; }
.dialog-panel label { display: block; margin-top: 18px; font-size: 9px; letter-spacing: .1em; }
input, textarea, select { width: 100%; margin-top: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 0; outline: 0; color: var(--ink); background: #faf7ef; }
input:focus, textarea:focus, select:focus { border-color: var(--ink); box-shadow: inset 3px 0 var(--accent); }
textarea { resize: vertical; line-height: 1.6; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.full { width: 100%; margin-top: 26px; }
.compose-from { display: grid; grid-template-columns: 60px 1fr; gap: 10px; padding: 10px 0; border-block: 1px solid var(--line); overflow-wrap: anywhere; }
.compose-from span { color: var(--muted); }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: min(420px, calc(100vw - 44px)); padding: 14px 18px; color: var(--paper); background: var(--ink); box-shadow: 6px 6px 0 var(--accent); line-height: 1.5; }
.hidden { display: none !important; }

@media (max-width: 900px) {
  .masthead { grid-template-columns: 170px 1fr auto; }
  .shell { grid-template-columns: 180px 1fr; }
  .rail { min-height: calc(100vh - 64px); }
  .message-layout { grid-template-columns: 1fr; }
  .message-column { border-right: 0; }
  .message-list { max-height: 420px; }
  .message-detail { border-top: 1px solid var(--ink); }
  .inbox-header { align-items: start; flex-direction: column; }
}

@media (max-width: 640px) {
  .masthead { height: 56px; grid-template-columns: 1fr auto; }
  .wordmark { border-right: 0; }
  .system-state { display: none; }
  .shell { display: block; }
  .rail { min-height: 0; border-right: 0; border-bottom: 1px solid var(--ink); }
  .inbox-list { display: flex; overflow-x: auto; }
  .inbox-item { min-width: 200px; border-right: 1px solid var(--line); }
  .rail-note { display: none; }
  .empty-state { min-height: calc(100vh - 160px); padding: 12vh 24px 50px; }
  .empty-state h1 { font-size: clamp(54px, 17vw, 82px); }
  .inbox-header { padding: 28px 20px; }
  .inbox-header h1 { font-size: 34px; }
  .header-actions { width: 100%; flex-wrap: wrap; }
  .header-actions button { flex: 1; }
  .message-row { grid-template-columns: 58px 1fr; }
  .message-time { display: none; }
  .message-detail { padding: 28px 20px; }
  .dialog-panel { padding: 26px 20px; }
  .dialog-panel h2 { font-size: 40px; }
}
