:root {
  --paper: #f6f4ef;
  --paper-2: #efece4;
  --ink: #14181f;
  --muted: #5c6370;
  --rule: #d8d2c6;
  --accent: #1f4e79;
  --accent-soft: #e3eaf2;
  --accent-ink: #f6f4ef;
  --card: #fffcf7;
  --good: #2f6b45;
  --warn: #a2541b;
  --serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --sans: "Source Sans 3", "Source Sans Pro", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --pad-x: clamp(0.65rem, 2.5vw, 1.5rem);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --row: 2.9rem;
  --id-w: 2rem;
  --status-w: 9.5rem;
  --msg-w: 3.4rem;
  --url-w: 2.4rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

html,
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body {
  overflow-x: hidden;
  padding-bottom: var(--safe-bottom);
  font-size: 0.98rem;
  line-height: 1.45;
}

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

[hidden] {
  display: none !important;
}

code {
  font-family: var(--mono);
  font-size: 0.8em;
  background: var(--paper-2);
  padding: 0.05em 0.3em;
  border-radius: 3px;
}

/* ---------------------------------------------------------------- header */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: calc(0.6rem + var(--safe-top)) var(--pad-x) 0.6rem;
  border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 92%, #fff);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.mark {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

.brand strong {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.tag {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex: 0 0 auto;
}

.linkish {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  padding: 0.3rem 0.1rem;
  min-height: 2.1rem;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.linkish:hover {
  color: var(--ink);
  text-decoration: underline;
}
.linkish.danger {
  color: #8a2f2f;
  margin-left: auto;
}

.btn-primary {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.45rem 1rem;
  cursor: pointer;
}
.btn-primary:hover {
  background: #173d5f;
}

/* ---------------------------------------------------------------- layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 0.85fr);
  gap: 2rem;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 1.4rem var(--pad-x) 3rem;
}

.main-col,
.side {
  min-width: 0;
}

.title-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.25rem, 3.5vw, 1.7rem);
  letter-spacing: -0.02em;
  font-weight: 600;
}

h2 {
  margin: 0 0 0.6rem;
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 600;
}

.mode-badge {
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

.stats,
.pace {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.pace {
  margin-bottom: 0.9rem;
}
.pace.over {
  color: var(--warn);
}

/* ---------------------------------------------------------------- forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 0;
  flex: 1 1 10rem;
}
.field-grow {
  flex: 3 1 14rem;
}
.field-wide {
  grid-column: 1 / -1;
}

.field select,
.field input,
.field textarea,
.template-form textarea {
  font-family: var(--sans);
  font-size: 0.95rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  border: 1px solid var(--rule);
  background: var(--card);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  min-height: 2.3rem;
  width: 100%;
}
.field textarea,
.template-form textarea {
  resize: vertical;
  line-height: 1.45;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.template-form textarea:focus,
.status-select:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
  align-items: end;
}

.add-panel,
.detail {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.85rem;
  margin: 0 0 0.9rem;
}
.detail {
  margin: 0.25rem 0 0.6rem;
  border-color: color-mix(in srgb, var(--accent) 35%, var(--rule));
}

.add-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

.add-actions {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}
.add-hint {
  color: var(--muted);
  font-size: 0.82rem;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin-top: 0.7rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
}
.detail-meta em {
  font-style: normal;
  color: var(--ink);
}

/* ---------------------------------------------------------------- filters */
.filters {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  margin-bottom: 0.7rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar {
  display: none;
}

.filter {
  font: inherit;
  font-size: 0.78rem;
  border: 1px solid var(--rule);
  background: transparent;
  padding: 0.35rem 0.7rem;
  min-height: 2rem;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
  flex: 0 0 auto;
  -webkit-tap-highlight-color: transparent;
}
.filter.active,
.filter:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------------------------------------------------------------- list */
.list-head,
.prospect-row {
  display: grid;
  grid-template-columns: var(--id-w) minmax(0, 1fr) var(--status-w) var(--msg-w) var(--url-w);
  gap: 0.45rem;
  align-items: center;
  width: 100%;
}

.list-head {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.h-id,
.col-id,
.h-msg,
.h-url {
  text-align: center;
}

.prospect-row {
  min-height: var(--row);
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--rule);
}
.prospect-row.is-open {
  border-bottom-color: transparent;
}
.prospect-row.is-closed .who-name {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: var(--rule);
}

.col-id {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
  color: var(--muted);
}

.who {
  background: none;
  border: 0;
  padding: 0.1rem 0;
  text-align: left;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}
.who:hover .who-name {
  color: var(--accent);
}
.who-name {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.who-sub {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.status-select {
  font: inherit;
  font-size: 0.8rem;
  border: 1px solid var(--rule);
  background: var(--card);
  padding: 0.2rem 0.3rem;
  height: 2.1rem;
  border-radius: 6px;
  color: var(--ink);
  width: 100%;
  min-width: 0;
}

.msg-btn {
  font: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0;
  height: 2.1rem;
  width: 100%;
  border-radius: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.msg-btn:hover {
  background: var(--accent);
  color: var(--accent-ink);
}

a.in-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2.1rem;
  width: 100%;
  border-radius: 6px;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--rule);
}
a.in-link:hover {
  border-color: var(--accent);
}
.in-miss {
  display: block;
  text-align: center;
  color: var(--muted);
}

.empty {
  color: var(--muted);
  padding: 1rem 0;
  margin: 0;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  min-height: 1.1em;
  margin-top: 0.6rem;
}

/* ---------------------------------------------------------------- side */
.side-lead {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.step {
  margin-bottom: 1.2rem;
}

.step-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  min-height: 2rem;
}
.step-actions {
  display: inline-flex;
  gap: 0.75rem;
}

.bubble {
  background: var(--card);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 0.8rem 0.95rem;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.bubble .var {
  color: var(--accent);
  font-weight: 600;
}

.template-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.vars {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.pipeline {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  overflow: hidden;
}
.pipeline li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--rule);
}
.pipeline li:last-child {
  border-bottom: 0;
}
.pipeline b {
  font-family: var(--mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.window {
  color: var(--muted);
  font-size: 0.84rem;
  margin: 0.9rem 0 0;
  line-height: 1.5;
}
.window strong {
  color: var(--ink);
  font-weight: 600;
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 1.25rem;
    padding: 0.85rem var(--pad-x) calc(1.5rem + var(--safe-bottom));
  }
  .tag {
    display: none;
  }
  .side {
    border-top: 1px solid var(--rule);
    padding-top: 1.1rem;
  }
  .add-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  :root {
    --status-w: 7.2rem;
    --msg-w: 3rem;
    --url-w: 2.2rem;
    --id-w: 1.5rem;
  }
  .top-actions {
    gap: 0.6rem;
  }
  .linkish {
    font-size: 0.82rem;
  }
  .add-grid {
    grid-template-columns: 1fr;
  }
  .status-select {
    font-size: 0.72rem;
  }
}
