/* ============================================================
   SORTING OFFICE — reply queue. Same design system as the
   deliverability dashboard; the queue is the sibling app.
   Postal red is reserved for critical / suppress / destructive.
   Ink stays ≥7:1 on paper; de-emphasis is size/weight only.
   ============================================================ */

:root {
  --desk: #EDE7D8;
  --paper: #FBF8F0;
  --paper-2: #F3EEDF;
  --line: #D9D1BC;
  --line-hard: #B9AE92;
  --ink: #1C2129;
  --ink-2: #3A4150;
  --blue: #2F4FCB;
  --blue-deep: #24409F;
  --red: #C9332B;
  --red-text: #A82420;
  --good-text: #1F6B30;
  --warn-text: #8F4A00;
  --shadow: rgba(84, 72, 44, 0.35);
  --hi: rgba(255, 255, 255, 0.85);
  --radius: 14px;
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font-family: "Archivo", system-ui, sans-serif;
  line-height: 1.5;
}

/* ---------- signature: airmail edge ---------- */
.airmail-edge, .dialog-stripe {
  height: 7px;
  background: repeating-linear-gradient(
    -45deg,
    var(--red) 0 14px, var(--paper) 14px 26px,
    var(--blue) 26px 40px, var(--paper) 40px 52px);
}
.airmail-edge { position: sticky; top: 0; z-index: 50; }
.dialog-stripe { margin: -1.4rem -1.6rem 1rem; border-radius: 10px 10px 0 0; }

/* ---------- header frank ---------- */
header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem 1.5rem;
  align-items: center;
  padding: 1.1rem 1.6rem 0.9rem;
}
.frank {
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 0.45rem 0.9rem 0.5rem;
  background: var(--paper);
  box-shadow: 3px 3px 0 var(--ink);
  transform: rotate(-0.6deg);
}
.frank-title {
  font-weight: 900;
  font-size: 1.12rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  line-height: 1.1;
}
.frank-sub {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--ink-2);
}

nav { display: flex; flex-wrap: wrap; gap: 0.45rem; flex: 1; }
nav button {
  background: var(--desk);
  color: var(--ink);
  border: 1px solid rgba(185, 174, 146, 0.4);
  border-radius: 999px;
  padding: 0.38rem 0.95rem;
  font: 600 0.84rem "Archivo", sans-serif;
  cursor: pointer;
  box-shadow: 2.5px 2.5px 6px var(--shadow), -2.5px -2.5px 6px var(--hi);
  transition: box-shadow 120ms ease, color 120ms ease;
}
nav button:hover { color: var(--blue-deep); }
nav button[aria-pressed="true"] {
  color: var(--blue-deep);
  font-weight: 800;
  box-shadow: inset 2.5px 2.5px 6px var(--shadow), inset -2.5px -2.5px 6px var(--hi);
}

main {
  padding: 0.6rem 1.6rem 4rem;
  max-width: 1500px;
  margin: 0 auto;
  display: grid;
  gap: 0.9rem;
}

/* ---------- panels & toolbar ---------- */
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  min-width: 0;
  box-shadow: 0 1px 3px rgba(84, 72, 44, 0.14);
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem 1rem;
  align-items: center;
}
.filters { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.filters button {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font: 600 0.78rem "Archivo", sans-serif;
  color: var(--ink);
  padding: 0.22rem 0.75rem;
  cursor: pointer;
}
.filters button[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }

.search {
  flex: 1;
  min-width: 160px;
  max-width: 320px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.38rem 0.65rem;
  font: 500 0.85rem "Archivo", sans-serif;
  color: var(--ink);
}
.search:focus { outline: 2px solid var(--blue); outline-offset: 1px; }

select {
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.38rem 0.6rem;
  font: 500 0.84rem "Archivo", sans-serif;
  max-width: 260px;
}
.check { font-size: 0.83rem; display: flex; gap: 0.4rem; align-items: center; font-weight: 600; }
.pager { display: flex; gap: 0.5rem; align-items: center; font: 500 0.78rem "IBM Plex Mono", monospace; margin-left: auto; }

/* category count strip */
.cat-strip { display: flex; flex-wrap: wrap; gap: 0.45rem; padding: 0 0.2rem; min-height: 1.6rem; }

/* ---------- split ---------- */
.split { display: grid; grid-template-columns: minmax(340px, 1fr) minmax(0, 1.35fr); gap: 0.9rem; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

.list-tools {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 0.4rem;
}
.kbd-hint { margin-left: auto; font-size: 0.7rem; }

/* ---------- reply rows: envelope entries ---------- */
.reply-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  align-items: start;
  padding: 0.55rem 0.55rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 100ms ease;
}
.reply-row:hover { background: var(--paper-2); box-shadow: inset 3px 0 0 var(--blue); }
.reply-row[aria-selected="true"] { background: var(--paper-2); box-shadow: inset 3px 0 0 var(--blue); }
.reply-row .top { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.reply-row .who {
  font-weight: 700;
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-row.unread .who::before { content: "● "; color: var(--blue); }
.reply-row .when {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--ink-2);
  white-space: nowrap;
}
.reply-row .subj {
  font-size: 0.8rem;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-row .chips { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-top: 0.25rem; }

/* ---------- stamp chips ---------- */
.stamp {
  display: inline-block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.08rem 0.45rem;
  border: 1.5px dashed currentColor;
  border-radius: 4px;
  transform: rotate(-1.2deg);
  background: var(--paper);
}
.stamp.cat-interested, .stamp.cat-meeting_request { color: var(--good-text); }
.stamp.cat-unsubscribe, .stamp.cat-hostile, .stamp.suppress { color: var(--red-text); }
.stamp.cat-bounce_notice, .stamp.cat-out_of_office, .stamp.cat-auto_reply_other { color: var(--ink-2); }
.stamp.cat-unclear, .stamp.cat-objection, .stamp.cat-not_interested, .stamp.cat-referral { color: var(--warn-text); }
.stamp.needs-human { color: var(--blue-deep); }
.stamp.count { transform: none; cursor: pointer; }
.stamp.count[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-style: solid; }

/* ---------- detail ---------- */
.detail h2 { font-size: 1rem; margin: 0.2rem 0 0.5rem; font-weight: 800; }
.meta {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--ink-2);
  display: grid;
  gap: 0.15rem;
  margin-bottom: 0.75rem;
}
.policy {
  border: 1.5px solid var(--blue);
  border-left-width: 5px;
  background: var(--paper-2);
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  font-size: 0.84rem;
  margin: 0.75rem 0;
}
.policy.blocked { border-color: var(--red); }
.policy b {
  font-family: "IBM Plex Mono", monospace;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
}
.policy .hint { display: block; margin-top: 0.2rem; }

.body-text {
  white-space: pre-wrap;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  font-size: 0.88rem;
  max-height: 320px;
  overflow-y: auto;
}

.thread { margin-top: 0.75rem; display: grid; gap: 0.5rem; }
.thread .msg { border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.8rem; font-size: 0.82rem; }
.thread .msg .h {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  color: var(--ink-2);
  font-size: 0.68rem;
  margin-bottom: 0.25rem;
}

/* ---------- the box under every reply in the list ---------- */
.reply-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  margin-bottom: 0.55rem;
  overflow: hidden;
}
.reply-item .reply-row { margin-bottom: 0; border: 0; border-radius: 0; }
.row-composer {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  padding: 0.5rem 0.7rem 0.6rem;
  border-top: 1px dashed var(--line-hard);
  background: var(--paper-2);
}
.row-composer textarea.mini {
  flex: 1;
  min-height: 2.6rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.83rem;
  border-radius: 8px;
  background: var(--paper);
}
.row-composer-side {
  display: grid;
  gap: 0.2rem;
  justify-items: end;
  min-width: 6.5rem;
}
.btn.small { padding: 0.3rem 0.8rem; font-size: 0.76rem; }
.small { font-size: 0.72rem; }
.row-composer.blocked-note {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--red-text);
  border-top: 1px dashed var(--red);
}

/* ---------- composer: writing the reply yourself ---------- */
.composer {
  margin-top: 1rem;
  display: grid;
  gap: 0.5rem;
  border-top: 2px dashed var(--line-hard);
  padding-top: 0.9rem;
}
.composer-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.composer-head b {
  font-family: "IBM Plex Mono", monospace;
  text-transform: uppercase;
  font-size: 0.74rem;
  letter-spacing: 0.06em;
}
.composer-blocked { margin-top: 1rem; }
.warn-text { color: var(--warn-text); font-size: 0.82rem; font-weight: 600; }
.warn-list { margin: 0.35rem 0 0; padding-left: 1.1rem; font-size: 0.82rem; }
.warn-list li { margin-bottom: 0.2rem; }

/* What the confirm dialog shows before anything leaves. */
.send-to { margin: 0 0 0.3rem; font-size: 0.85rem; }
.send-to b {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.send-preview-head {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-2);
  margin: 0.8rem 0 0.3rem;
}
.send-preview {
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  font-size: 0.88rem;
  max-height: 300px;
  overflow-y: auto;
}
.send-preview p { margin: 0 0 0.9rem; }
.send-preview p:last-child { margin-bottom: 0; }
textarea {
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.95rem;
  font: 500 0.88rem "Archivo", sans-serif;
  min-height: 120px;
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.composer-actions { display: flex; gap: 0.55rem; flex-wrap: wrap; }

.btn {
  background: var(--desk);
  color: var(--ink);
  border: 1px solid rgba(185, 174, 146, 0.5);
  border-radius: 9px;
  padding: 0.4rem 0.9rem;
  font: 700 0.82rem "Archivo", sans-serif;
  cursor: pointer;
  box-shadow: 2px 2px 5px var(--shadow), -2px -2px 5px var(--hi);
}
.btn:hover { color: var(--blue-deep); }
.btn:active { box-shadow: inset 2px 2px 5px var(--shadow), inset -2px -2px 5px var(--hi); }
.btn.primary { color: var(--good-text); }
.btn.primary:hover { background: var(--good-text); color: #fff; border-color: var(--good-text); }
.btn.danger { color: var(--red-text); }
.btn.danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, nav button:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.hint { font-size: 0.82rem; color: var(--ink-2); }

/* ---------- skeletons ---------- */
.skel {
  border-radius: 8px;
  background: linear-gradient(100deg, var(--paper-2) 40%, var(--paper) 50%, var(--paper-2) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.1s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-row { height: 3.2rem; margin-bottom: 0.45rem; }

/* ---------- toast & dialog ---------- */
#status {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--ink);
  color: var(--paper);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  display: none;
  z-index: 60;
}
#status.show { display: block; }
#status.err { background: var(--red); color: #fff; }

dialog {
  background: var(--paper);
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 12px;
  padding: 1.4rem 1.6rem;
  max-width: 540px;
  box-shadow: 6px 6px 0 rgba(28, 33, 41, 0.25);
}
dialog::backdrop { background: rgba(40, 34, 20, 0.5); }
dialog h3 { margin: 0 0 0.5rem; font-size: 1rem; text-transform: uppercase; letter-spacing: 0.08em; }
blockquote {
  margin: 0.75rem 0;
  padding: 0.6rem 0.9rem;
  background: var(--paper-2);
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  white-space: pre-wrap;
  font-size: 0.86rem;
  max-height: 200px;
  overflow-y: auto;
}
.dialog-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1rem; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- master inbox: two columns ---------- */
.autopilot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font: 600 0.8rem "IBM Plex Mono", monospace;
  border: 1.5px solid var(--line-hard);
  border-radius: 999px;
  padding: 0.25rem 0.5rem 0.25rem 0.8rem;
  background: var(--paper);
}
.autopilot .lamp {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--line-hard);
  box-shadow: 0 0 0 3px rgba(185,174,146,0.25);
}
.autopilot .lamp.on { background: var(--good-text); box-shadow: 0 0 0 3px rgba(31,107,48,0.2); }
.autopilot .lamp.off { background: var(--red); box-shadow: 0 0 0 3px rgba(201,51,43,0.18); }

.inbox-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; align-items: start; }
@media (max-width: 1000px) { .inbox-grid { grid-template-columns: 1fr; } }

.column { display: grid; gap: 0.5rem; }
.interested-col { border-color: var(--good-text); box-shadow: inset 4px 0 0 var(--good-text), 0 1px 3px rgba(84,72,44,0.14); }
.col-head {
  display: flex; align-items: center; gap: 0.6rem;
  justify-content: space-between;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 0.4rem;
}
.reply-list { max-height: 460px; overflow-y: auto; }

.ws-tag {
  font: 600 0.62rem "IBM Plex Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--blue-deep);
  border: 1px solid var(--blue);
  border-radius: 3px;
  padding: 0 0.3rem;
}
.sent-badge { color: var(--good-text); font-weight: 800; }

/* ---------- conversation view ---------- */
.convo { display: grid; gap: 0.7rem; }
.msg-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  background: var(--paper-2);
}
.msg-card.outbound { border-left: 4px solid var(--line-hard); }
.msg-card.inbound { border-left: 4px solid var(--blue); background: var(--paper); }
.msg-card.agent { border-left: 4px solid var(--good-text); }
.msg-card.by-hand { border-left: 4px solid var(--blue-deep); }
.msg-card.by-hand .who { color: var(--blue-deep); }
.msg-card .who {
  font: 700 0.7rem "IBM Plex Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-2);
  display: flex; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap;
}
.msg-card .subj { font-weight: 700; font-size: 0.88rem; margin: 0.15rem 0 0.35rem; }
.msg-card .body { white-space: pre-wrap; font-size: 0.87rem; max-height: 260px; overflow-y: auto; }
.msg-card.agent .who { color: var(--good-text); }

.show-more {
  width: 100%;
  margin-top: 0.5rem;
  font-size: 0.78rem;
}
