:root {
  --bg: #ebeff4;
  --ink: #11161d;
  --muted: #4a5563;
  --line: #b7c0cc;
  --line-soft: #d5dce5;
  --surface: #f7f9fb;
  --accent: #0868a0;
  --hot: #d24d16;
  --ok: #1a6b45;
  --warn: #8a5a00;
  --font: 'Figtree', 'Avenir Next', sans-serif;
  --display: 'Syne', 'Avenir Next', sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    linear-gradient(180deg, #f4f7fa 0%, var(--bg) 38%, #e4e9f0 100%);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

a {
  color: var(--accent);
}

#app {
  min-height: 100vh;
}

/* ——— Login ——— */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
}

.login-panel {
  width: min(100%, 26rem);
  border-top: 4px solid var(--ink);
  background: var(--surface);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-left: 1px solid var(--line);
  padding: 2rem 1.75rem 1.75rem;
}

.login-panel .mark {
  margin: 0 0 0.85rem;
  line-height: 0;
}

.login-panel .mark img {
  width: auto;
  height: 3.5rem;
  max-width: 100%;
}

.login-panel h1 {
  margin: 0 0 0.35rem;
  font-family: var(--display);
  font-size: 1.85rem;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.login-panel .lede {
  margin: 0 0 1.5rem;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 0;
  border-bottom: 1.5px solid var(--line);
  background: transparent;
  padding: 0.55rem 0.1rem;
  border-radius: 0;
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-bottom-color: var(--accent);
}

.field textarea {
  min-height: 6.5rem;
  resize: vertical;
  line-height: 1.45;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: #fff;
  padding: 0.65rem 1.1rem;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.01em;
  border-radius: 0;
}

.btn:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.btn.ghost {
  background: transparent;
  color: var(--ink);
}

.btn.ghost:hover {
  background: var(--ink);
  color: #fff;
}

.btn.block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.err {
  color: var(--hot);
  margin: 0 0 1rem;
  font-weight: 600;
}

.hint {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.qr-wrap {
  display: grid;
  place-items: center;
  margin: 0 0 1rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.qr {
  width: 240px;
  height: 240px;
  image-rendering: pixelated;
}

.secret-line {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
  word-break: break-all;
}

.secret-line code {
  color: var(--ink);
  font-weight: 700;
}

button.linkish {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

/* ——— Shell ——— */
.shell {
  width: min(100% - 2rem, 78rem);
  margin: 0 auto;
  padding: 1.25rem 0 3rem;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 1.25rem;
}

.topbar .brand {
  margin: 0 0 0.35rem;
  line-height: 0;
}

.topbar .brand img {
  width: auto;
  height: 2.4rem;
}

.topbar h1 {
  margin: 0.2rem 0 0;
  font-family: var(--display);
  font-size: clamp(1.7rem, 3.5vw, 2.35rem);
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.topbar .meta {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.layout {
  display: grid;
  grid-template-columns: 12.5rem minmax(0, 1fr);
  gap: 1.75rem;
}

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.side nav {
  display: grid;
  gap: 0;
}

.side button.nav-item {
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  padding: 0.7rem 0.15rem;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}

.side button.nav-item:hover {
  color: var(--ink);
}

.side button.nav-item.is-on {
  color: var(--ink);
  border-bottom-color: var(--ink);
  font-weight: 800;
}

.side .count {
  float: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 600;
}

.side .side-foot {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.side .side-foot strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ——— Main panes ——— */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.toolbar .search {
  flex: 1 1 14rem;
  border: 0;
  border-bottom: 1.5px solid var(--line);
  background: transparent;
  padding: 0.5rem 0.1rem;
  outline: none;
  border-radius: 0;
}

.toolbar .search:focus {
  border-bottom-color: var(--accent);
}

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--ink);
}

table.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

table.ledger th {
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  padding: 0.7rem 0.55rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table.ledger td {
  padding: 0.85rem 0.55rem;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
  vertical-align: top;
}

table.ledger tr {
  cursor: pointer;
}

table.ledger tbody tr:hover {
  background: color-mix(in srgb, var(--surface) 70%, transparent);
}

table.ledger tr.is-selected {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.who {
  font-weight: 700;
}

.who small {
  display: block;
  font-weight: 500;
  color: var(--muted);
  margin-top: 0.15rem;
}

.money {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}

.status-text {
  font-weight: 700;
}

.status-text[data-s='responded'] {
  color: var(--ok);
}

.status-text[data-s='spoken'],
.status-text[data-s='quoted'] {
  color: var(--accent);
}

.status-text[data-s='won'] {
  color: var(--ok);
}

.status-text[data-s='lost'],
.status-text[data-s='cold'] {
  color: var(--muted);
}

.empty {
  padding: 2.5rem 0.25rem;
  color: var(--muted);
  border-top: 1px solid var(--ink);
}

/* ——— Detail drawer ——— */
.detail {
  margin-top: 1.5rem;
  border-top: 2px solid var(--ink);
  padding-top: 1.25rem;
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1.5rem;
}

@media (max-width: 820px) {
  .detail {
    grid-template-columns: 1fr;
  }
}

.detail h2 {
  margin: 0 0 1rem;
  font-family: var(--display);
  letter-spacing: -0.03em;
  font-size: 1.45rem;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.muted {
  color: var(--muted);
}

.flash {
  margin: 0 0 1rem;
  padding: 0.65rem 0;
  border-bottom: 1.5px solid var(--ok);
  color: var(--ok);
  font-weight: 700;
}

.flash.bad {
  border-bottom-color: var(--hot);
  color: var(--hot);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
}

@media (max-width: 600px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

.sent-row .subject {
  font-weight: 700;
}

.sent-row .when {
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.snippet {
  color: var(--muted);
  max-width: 36rem;
}

.imap-banner {
  margin-bottom: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1.5px solid var(--warn);
  color: var(--warn);
  font-weight: 600;
}
