:root {
  --ink: #1B2430;
  --ink-soft: #2A3648;
  --paper: #F7F5F0;
  --paper-dim: #EDEAE2;
  --amber: #E8A33D;
  --sage: #6B8F71;
  --clay: #C0563E;
  --slate: #5C6672;
  --line: #DAD5C8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { font-family: 'Fraunces', serif; margin: 0; }

.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar: pigeonholes ---------- */
.pigeonholes {
  background: var(--ink);
  color: var(--paper);
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  font-size: 22px;
  color: var(--amber);
}
.brand h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--paper);
}
.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: #9AA5B4;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: 0.03em;
}

.connect-btn {
  background: transparent;
  border: 1px solid #3D4A5E;
  color: var(--paper);
  padding: 11px 14px;
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.connect-btn:hover { border-color: var(--amber); background: rgba(232,163,61,0.08); }
.connect-btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.slots {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  flex: 1;
}

.slot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--ink-soft);
  position: relative;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}
.slot:hover { border-color: #3D4A5E; }
.slot.active { border-color: var(--amber); background: rgba(232,163,61,0.12); }
.slot-color {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.slot-info { flex: 1; min-width: 0; }
.slot-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--paper);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot-email {
  font-size: 11px;
  color: #8B95A5;
  font-family: 'IBM Plex Mono', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot-remove {
  background: none;
  border: none;
  color: #6B7688;
  cursor: pointer;
  font-size: 15px;
  padding: 2px 6px;
  border-radius: 4px;
}
.slot-remove:hover { color: var(--clay); background: rgba(192,86,62,0.12); }

.empty-hint {
  color: #8B95A5;
  font-size: 13px;
  line-height: 1.5;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11.5px;
  color: #8B95A5;
  padding-top: 4px;
  border-top: 1px solid #2E3A4C;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--slate);
}
.dot.ok { background: var(--sage); }
.dot.err { background: var(--clay); }

/* ---------- Main: ledger ---------- */
.ledger-view {
  padding: 36px 44px;
  max-width: 980px;
}

.ledger-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 22px;
}
.eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--slate);
  margin: 0 0 6px;
}
#totalCount { font-size: 26px; font-weight: 500; }

.refresh-btn {
  background: var(--ink);
  color: var(--paper);
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
}
.refresh-btn:hover { background: var(--ink-soft); }
.refresh-btn:disabled { opacity: 0.5; cursor: default; }

.error-banner {
  background: #FBEDEA;
  border: 1px solid #E8C3BA;
  color: #8A3A28;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
}

.filter-indicator {
  font-size: 12.5px;
  color: var(--slate);
  margin: 0 0 14px;
}
.filter-indicator strong { color: var(--ink); }
.filter-indicator #clearFilterBtn {
  background: none;
  border: none;
  color: var(--clay);
  text-decoration: underline;
  cursor: pointer;
  font-size: 12.5px;
  padding: 0;
  font-family: 'Inter', sans-serif;
}

.search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  margin-bottom: 16px;
}
.search-input:focus {
  outline: none;
  border-color: var(--amber);
}
.search-input::placeholder { color: #9AA0AA; }

.ledger {
  border-top: 1px solid var(--line);
}

.row {
  display: grid;
  grid-template-columns: 3px 130px 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 14px 6px;
  border-bottom: 1px solid var(--line);
  transition: background 0.1s;
  cursor: pointer;
}
.row:hover { background: var(--paper-dim); }
.row:focus-visible { outline: 2px solid var(--amber); outline-offset: -2px; background: var(--paper-dim); }

.row-bar { align-self: stretch; border-radius: 2px; }

.row-account {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11.5px;
  color: var(--slate);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-main { min-width: 0; }
.row-subject {
  font-size: 14.5px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-subject.unread::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--amber);
  margin-right: 8px;
  vertical-align: middle;
}
.row-from {
  font-size: 12.5px;
  color: var(--slate);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-date {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11.5px;
  color: #9AA0AA;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .pigeonholes { border-right: none; border-bottom: 1px solid var(--line); }
  .ledger-view { padding: 24px; }
  .row { grid-template-columns: 3px 1fr; }
  .row-account, .row-date { grid-column: 2; }
}

/* ---------- Inline detail: accordion ---------- */
.row.is-open { background: var(--paper-dim); }

.row-detail {
  border-bottom: 1px solid var(--line);
  padding: 18px 22px 22px 25px;
  background: var(--paper-dim);
}

.detail-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--ink);
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px dashed var(--line);
}
.detail-meta-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate);
  display: inline-block;
  width: 65px;
}

.otp-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #FFF6E7;
  border: 1px solid #F0D9A6;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.otp-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8A6A1F;
}
.otp-code {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--ink);
  flex: 1;
}
.otp-copy {
  background: var(--ink);
  color: var(--paper);
  border: none;
  padding: 6px 12px;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
}
.otp-copy:hover { background: var(--ink-soft); }

.detail-body {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 14px;
}

.link-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.link-chip {
  display: inline-block;
  background: var(--ink);
  color: var(--paper);
  text-decoration: none;
  padding: 7px 13px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
}
.link-chip:hover { background: var(--ink-soft); }
