/* Inbox (#233): the mail client on a project's Inbox page. Two panes
   (mailboxes, threads) side by side on wide screens, stacked on narrow
   ones; the open thread, a new message, settings and domains open in the
   right-hand drawer. Colours are the dashboard's roles from style.css;
   nothing here sets one of its own. */

/* The drawer sits outside .ki-root (it is the shell's), so both scopes. */
.ki-root .row, .ki-drawer .row { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
.ki-root .grow, .ki-drawer .grow { flex: 1 1 auto; }
.ki-pad { padding: 8px 12px; }
.ki-client { margin: 16px 0 32px; }

.ki-grid {
  display: grid;
  grid-template-columns: minmax(200px, 260px) minmax(0, 1fr);
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--card-hi);
  overflow: hidden;
}
.ki-grid > * { min-width: 0; }
.ki-boxes { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.ki-threads { display: flex; flex-direction: column; }
.ki-boxes-foot { margin-top: auto; border-top: 1px solid var(--line); }
.ki-pane-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); min-height: 48px; }
.ki-pane-head .eyebrow { margin: 0; flex: 1 1 auto; }

.ki-boxes ul, .ki-list, .ki-delivery-list { list-style: none; margin: 0; padding: 0; }
.ki-box {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; background: none; border: 0; border-left: 2px solid transparent;
  color: var(--text-2); text-align: left; cursor: pointer; font: inherit;
}
.ki-box:hover { background: var(--hover); color: var(--text); }
.ki-box.on { border-left-color: var(--vivid); background: var(--vivid-soft); color: var(--text); }
.ki-box-name { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.ki-box-name .mono { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ki-box .sub { font-size: 12px; color: var(--text-2); }

/* The selected mailbox: its name, its address to copy, and what to do. */
.ki-mailbox-bar { display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ki-mailbox-id { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 240px; }
.ki-mailbox-name { font-size: 15px; color: var(--text); }
.ki-mailbox-address { display: flex; align-items: center; gap: 2px; min-width: 0; }
.ki-mailbox-address code { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ki-mailbox-bar .btn.on { background: var(--vivid-soft); border-color: var(--vivid); }
/* All / Unread. */
.ki-seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; flex: none; }
.ki-seg button { background: none; border: 0; padding: 5px 12px; font: inherit; font-size: 13px; color: var(--text-2); cursor: pointer; }
.ki-seg button + button { border-left: 1px solid var(--line); }
.ki-seg button:hover { color: var(--text); background: var(--hover); }
.ki-seg button[aria-pressed="true"] { background: var(--vivid-soft); color: var(--text); }
.ki-search { flex: 1 1 auto; }
.ki-search input { width: 100%; padding: 6px 10px; font-size: 13px; }
.iconbtn.on { color: var(--vivid-ink); background: var(--vivid-soft); }

.ki-threads { overflow: hidden; }
.ki-list { overflow-y: auto; flex: 1 1 auto; max-height: 720px; }
.ki-thread {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px;
  width: 100%; padding: 10px 12px; background: none; border: 0; border-bottom: 1px solid var(--line);
  border-left: 2px solid transparent; text-align: left; cursor: pointer; font: inherit; color: var(--text-2);
}
.ki-thread:hover { background: var(--hover); }
.ki-thread.on { background: var(--vivid-soft); border-left-color: var(--vivid); }
.ki-thread.unread .ki-who, .ki-thread.unread .ki-subject { color: var(--text); font-weight: 500; }
.ki-who { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.ki-when { font-family: var(--mono); font-size: 11px; }
.ki-subject { grid-column: 1 / -1; color: var(--text); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ki-snippet { grid-column: 1 / -1; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ki-empty { border: 0; padding: 40px 16px; }

/* The drawer: an inset card whose head (title, actions, close) stays put
   while the thread, form or records scroll under it. */
.ki-drawer .card-head h3 { flex: 1 1 auto; min-width: 0; flex-wrap: wrap; }
.ki-drawer-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.ki-drawer > .act-error:empty { display: none; }
.ki-drawer > .act-error { margin: 12px 16px 0; }
.ki-drawer .ki-compose { padding-top: 16px; }
.ki-drawer .ki-settings-body { display: flex; flex-direction: column; gap: 12px; }
.ki-drawer .table-wrap { border-top: 1px solid var(--line); }
.ki-drawer .ki-domain .table-wrap { border-top: 0; }
.ki-thread-subject { font-size: 16px; font-weight: 400; overflow-wrap: anywhere; }
.ki-msg { border-bottom: 1px solid var(--line); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.ki-msg.out { background: var(--well); }
.ki-msg-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; position: relative; }
.ki-from { overflow-wrap: anywhere; }
.ki-from strong { font-weight: 500; }
.ki-msg-meta { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-2); white-space: nowrap; }
.ki-to { grid-column: 1 / -1; overflow-wrap: anywhere; }
.ki-menu { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.ki-menu[hidden] { display: none; }
.ki-text {
  margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--sans); font-size: 14px;
  line-height: 1.6; color: var(--text); background: none; border: 0; padding: 0;
}
.ki-html { width: 100%; height: 480px; border: 1px solid var(--line); border-radius: var(--r); background: #fff; resize: vertical; }
/* In the drawer, a message gets most of its height. */
.ki-drawer .ki-msg .ki-html { height: clamp(360px, 68vh, 1100px); }
/* Remote images wait for the reader. */
.ki-images { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--well); font-size: 13px; color: var(--text-2); }
.ki-images > span { flex: 1 1 220px; }
.ki-body-tools { display: flex; align-items: center; gap: 12px; }
.ki-files { display: flex; flex-wrap: wrap; gap: 8px; }
.ki-file {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; font: inherit; font-size: 13px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--field); color: var(--text); cursor: pointer;
}
.ki-file:hover { border-color: var(--line-hover); background: var(--hover); }
.ki-file-wrap { display: inline-flex; align-items: center; gap: 2px; }
.ki-file-wrap.on .ki-file { border-color: var(--vivid); background: var(--vivid-soft); }
.ki-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: var(--r-xs); background: var(--well); }
.ki-viewer { border: 1px solid var(--line); border-radius: var(--r); background: var(--well); overflow: hidden; }
.ki-viewer-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.ki-viewer .skel-group, .ki-viewer .error-box { margin: 12px; }
.ki-view-image { display: block; max-width: 100%; max-height: 640px; margin: 0 auto; padding: 12px; object-fit: contain; }
.ki-view-pdf { display: block; width: 100%; height: 720px; border: 0; background: #fff; }
.ki-view-audio { display: block; width: calc(100% - 24px); margin: 16px 12px; }
.ki-view-video { display: block; max-width: 100%; max-height: 640px; margin: 0 auto; background: #000; }
.ki-view-text { margin: 0; padding: 12px; max-height: 520px; overflow: auto; font-family: var(--mono); font-size: 12px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); }
/* What became of a sent message: a chip that opens the data drawer. */
.ki-delivery-chip { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; padding: 3px 10px; border: 1px solid var(--line); border-radius: var(--r-pill); background: transparent; color: var(--text-2); font: inherit; font-size: 12px; cursor: pointer; }
.ki-delivery-chip:hover { color: var(--text); border-color: var(--line-hover); background: var(--hover); }
.ki-delivery-list li { padding: 10px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.ki-delivery-list li:last-child { border-bottom: 0; }
.ki-delivery-row { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.ki-delivery-reply { margin-top: 4px; color: var(--text-2); }
/* How a domain's mail leaves. */
.ki-delivery { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 14px; margin: 4px 0 12px; }
.ki-delivery .field { margin: 0; min-width: 240px; }
.ki-delivery > .small { flex: 1 1 260px; padding-bottom: 8px; }
.ki-reply-tools { display: flex; gap: 8px; padding: 12px 16px; }
.ki-reply-tools[hidden] { display: none; }

.ki-compose { display: flex; flex-direction: column; gap: 12px; padding: 0 16px 16px; }
/* .field grows along a row (flex: 1 1 200px); down a column that would be
   200px of height each. */
.ki-compose > *, .ki-settings > * { flex: 0 0 auto; }
.ki-compose .ki-pane-head { margin: 0 -16px; }
.ki-textarea { min-height: 180px; font-family: var(--sans); }
.ki-compose-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ki-attach { cursor: pointer; }
.ki-format { display: flex; gap: 20px; }
.ki-html-edit { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.ki-html-edit[hidden], .ki-compose [data-ki-part][hidden] { display: none; }
.ki-html-edit .ki-textarea { min-height: 360px; font-size: 12px; }
.ki-live { height: 360px; }
.ki-preview { border: 1px solid var(--line); border-radius: var(--r); background: var(--well); padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px; }
.ki-preview .ki-pane-head { margin: 0 -12px; }
.ki-preview-head { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; margin: 0; font-size: 13px; }
.ki-preview-head dt { color: var(--text-2); font-family: var(--mono); font-size: 11px; letter-spacing: .2em; text-transform: uppercase; }
.ki-preview-head dd { margin: 0; overflow-wrap: anywhere; }
.ki-rcpt { display: inline-block; margin-right: 10px; }
.ki-rcpt.missing { color: var(--error); }
.ki-preview-text summary { cursor: pointer; }
@media (max-width: 1100px) { .ki-html-edit { grid-template-columns: minmax(0, 1fr); } }

.ki-new { margin-top: 16px; padding: 16px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); display: flex; flex-direction: column; gap: 12px; }
.ki-new h3 { margin: 0; font-weight: 300; }
.ki-drawer .ki-new { margin: 0; padding: 0; border: 0; background: none; }

.ki-settings-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.ki-domain { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px; margin-bottom: 16px; background: var(--surface); }
.ki-domain-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 8px; }
.ki-records { table-layout: fixed; width: 100%; }
.ki-records th:nth-child(1) { width: 64px; }
.ki-records th:nth-child(2) { width: 28%; }
.ki-records th:nth-child(4) { width: 22%; }
.ki-records th:nth-child(5) { width: 96px; }
.ki-records td { white-space: normal; vertical-align: top; }
.ki-records code { font-size: 12px; overflow-wrap: anywhere; word-break: break-all; }
.ki-add-domain { margin-top: 8px; }

@media (max-width: 760px) {
  .ki-grid { grid-template-columns: minmax(0, 1fr); }
  .ki-boxes { border-right: 0; border-bottom: 1px solid var(--line); }
  .ki-list { max-height: 360px; }
}
.ki-settings { display: flex; flex-direction: column; gap: 12px; }
.ki-settings-save { display: flex; justify-content: flex-start; }
