@font-face {
  font-family: Manrope;
  src: url("/assets/manrope.ttf") format("truetype");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #655d53;
  --paper: #f9f7f3;
  --line: #ded7cb;
  --white: #fff;
  --accent: #c89a53;
  --accent-dark: #76511e;
  --wash: #f1ece4;
  --rail: #24211d;
  --rail-text: #f7f1e7;
  --rail-muted: #d0c7b9;
  font: 1rem/1.55 Manrope, system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(2rem, 4.5vw, 3.375rem); line-height: 1.08; letter-spacing: -.055em; overflow-wrap: anywhere; }
h2 { font-size: 1.15rem; line-height: 1.25; letter-spacing: -.025em; }
a { color: var(--accent-dark); text-underline-offset: .18em; }
:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: 3px; }
.rail :focus-visible, .login-top :focus-visible { outline-color: #e3bd81; }
.skip { position: fixed; z-index: 1; top: .5rem; left: .5rem; padding: .75rem; background: var(--white); transform: translateY(-150%); }
.skip:focus { transform: none; }

.shell { display: grid; grid-template-columns: 15rem minmax(0, 1fr); min-height: 100dvh; }
.rail { background: var(--rail); color: var(--rail-text); padding: 1.5rem 1.1rem; display: flex; flex-direction: column; gap: 2.25rem; }
.brand { display: flex; align-items: center; gap: .75rem; padding-inline: .35rem; }
.brand img { object-fit: contain; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 1.2rem; font-weight: 800; letter-spacing: -.035em; line-height: 1.14; }
.brand span, .profile button { color: var(--rail-muted); font-size: .82rem; }
.rail nav { display: grid; gap: .3rem; }
.rail nav a { display: flex; align-items: center; gap: .75rem; padding: .63rem .7rem; border-radius: .45rem; color: var(--rail-text); font-weight: 700; text-decoration: none; }
.rail nav a:hover { background: #38312a; }
.rail nav a[aria-current] { background: #493a29; color: #ffdfad; }
.rail nav a > span { width: 1rem; text-align: center; }
.nav-count { margin-left: auto; border-radius: 2rem; padding: 0 .45rem; background: #e3bd81; color: var(--ink); font-size: .8rem; }
.profile { display: flex; align-items: center; gap: .65rem; border-top: 1px solid #544a40; padding: 1rem .35rem 0; margin-top: auto; overflow-wrap: anywhere; }
.avatar { flex: 0 0 2.25rem; height: 2.25rem; display: grid; place-items: center; background: #493a29; border-radius: 50%; color: #ffdfad; font-weight: 800; }
.profile .plain { min-height: 2rem; padding: 0; }

.main { min-width: 0; max-width: 100rem; width: 100%; margin-inline: auto; padding: clamp(1rem, 3vw, 3.2rem); }
.heading { display: flex; align-items: end; justify-content: space-between; gap: .9rem; margin-bottom: 1.6rem; flex-wrap: wrap; }
.heading .muted { margin-top: .55rem; }
.back { display: inline-block; margin-bottom: .5rem; font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.panel { border: 1px solid var(--line); background: var(--white); border-radius: 1rem; min-width: 0; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .85rem; margin-bottom: 1.1rem; }
.metric { display: grid; align-content: space-between; gap: .3rem; border: 1px solid var(--line); border-radius: .8rem; color: var(--ink); padding: .9rem 1rem; background: var(--white); text-decoration: none; }
.metric:hover { border-color: var(--accent-dark); background: #fdf9f2; }
.metric span { font-size: .875rem; color: var(--muted); font-weight: 700; }
.metric strong { font-size: 2rem; line-height: 1.18; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }

button, input, select, textarea { font: inherit; }
button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.65rem; padding: .45rem .9rem; border: 1px solid transparent; border-radius: .45rem; color: var(--ink); font-size: .9rem; font-weight: 800; cursor: pointer; text-decoration: none; text-align: center; }
.primary { background: var(--accent); }
.primary:hover { background: #dbb67d; }
.secondary { background: var(--white); border-color: #a6998b; }
.secondary:hover { background: var(--wash); }
.plain { background: transparent; text-decoration: underline; text-underline-offset: .2em; }
.plain:hover { color: var(--accent-dark); }
.profile .plain:hover { color: var(--rail-text); }
label { display: grid; gap: .28rem; min-width: 0; font-size: .875rem; font-weight: 750; }
input, select, textarea { width: 100%; min-width: 0; min-height: 2.65rem; border: 1px solid #a6998b; border-radius: .4rem; padding: .42rem .55rem; font-size: 1rem; font-weight: 500; background: var(--white); color: var(--ink); }
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: .5rem; }
input[type="checkbox"] { width: 1.1rem; height: 1.1rem; min-height: 0; accent-color: var(--accent-dark); }
.filters { display: flex; align-items: end; flex-wrap: wrap; gap: .65rem; padding: 1rem; border-bottom: 1px solid var(--line); }
.filters label { flex: 1 1 8rem; }
.filters label:has(input[type="search"]) { flex: 1.7 1 12rem; }
.results { padding: .9rem 1rem; }
.results span { color: var(--muted); margin-left: .25rem; font-size: .92rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: .9rem; }
th, td { padding: .75rem 1rem; overflow-wrap: anywhere; }
thead th { background: var(--wash); color: var(--muted); font-weight: 800; }
tbody tr + tr, tfoot tr { border-top: 1px solid var(--line); }
tbody tr:hover { background: #fdfaf4; }
.lead-name { font-size: 1rem; font-weight: 800; color: var(--ink); }
.sub { display: block; color: var(--muted); font-size: .82rem; margin-top: .18rem; }
.urgent { color: #923c29; font-weight: 800; }
.tag { display: inline-block; padding: .16rem .48rem; border-radius: .35rem; background: var(--wash); color: #504438; font-size: .82rem; font-weight: 800; }
.stage-new { background: #f6e5ca; color: #714716; }
.stage-qualified, .stage-project, .stage-visit, .stage-estimate { background: #e9eef3; color: #315477; }
.stage-contract, .stage-paid, .enabled { background: #e5efde; color: #36582d; }
.stage-paused, .stage-closed, .stage-invalid { background: #f1e5e2; color: #773f35; }
.empty { display: grid; justify-items: start; gap: .6rem; padding: 1.65rem 1.1rem; }
.empty p, .muted { color: var(--muted); }
.pagination { display: flex; flex-wrap: wrap; gap: 1rem; border-top: 1px solid var(--line); padding: .75rem 1rem; }
.notice { background: #ecf0e5; padding: .75rem .9rem; margin-bottom: .9rem; border-radius: .45rem; color: #374b29; }
.notice.error { background: #f9ebe6; color: #7c3123; }

.card-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.editor { padding: 1.1rem; }
.stack { display: grid; align-content: start; gap: .8rem; min-width: 0; }
.stack > a { justify-self: start; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.form-grid .wide { grid-column: 1 / -1; }
summary { cursor: pointer; font-weight: 800; padding: .45rem 0; color: var(--accent-dark); }
details[open] > summary { margin-bottom: .5rem; }
dl { display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); gap: .2rem .7rem; margin: 0; font-size: .86rem; }
dd { margin: 0; overflow-wrap: anywhere; }
.preserve { white-space: pre-wrap; overflow-wrap: anywhere; }

.inbox { display: grid; grid-template-columns: minmax(13rem, 19rem) minmax(0, 1fr); min-height: 29rem; }
.dialogs { border-right: 1px solid var(--line); max-height: 46rem; overflow: auto; }
.inbox-filter { display: grid; gap: .45rem; padding: .85rem; border-bottom: 1px solid var(--line); }
.inbox-filter button { justify-self: start; }
.dialog { display: grid; padding: .75rem .85rem; border-bottom: 1px solid var(--line); gap: .12rem; color: var(--ink); text-decoration: none; }
.dialog:is(:hover, [aria-current]) { background: #f5ebdc; }
.dialog > div { display: flex; gap: .45rem; justify-content: space-between; align-items: baseline; }
.dialog strong, .dialog p { overflow-wrap: anywhere; }
.dialog time, .dialog span { color: var(--muted); font-size: .8rem; }
.dialog time { white-space: nowrap; }
.dialog p { font-size: .89rem; color: var(--muted); }
.conversation { display: flex; flex-direction: column; min-width: 0; }
.conversation-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .6rem; border-bottom: 1px solid var(--line); padding: .85rem 1rem; }
.conversation-head h2 { overflow-wrap: anywhere; }
.conversation-body { min-height: 12rem; }
.timeline { display: grid; gap: .6rem; padding: 0; margin: .8rem 0; list-style: none; }
.conversation .timeline { padding: 0 1rem; }
.event { border-radius: .55rem; padding: .58rem .75rem; background: var(--wash); }
.event-out { background: #f4e6cf; }
.event-in { background: #edf0f2; }
.event-meta { display: flex; gap: .45rem; flex-wrap: wrap; align-items: baseline; margin-bottom: .2rem; color: var(--muted); font-size: .8rem; }
.event-meta time { margin-left: auto; }
.event p { font-size: .94rem; }
.reply, .link-thread { border-top: 1px solid var(--line); padding: .8rem 1rem; }
.conversation > .notice { margin: .5rem 1rem; }
.report-note { padding: .75rem 1rem; font-size: .9rem; }
.channel-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .7rem; padding: 1rem; }
.channel-row + .channel-row { border-top: 1px solid var(--line); }
.channel-row p { color: var(--muted); }
.login { width: min(29rem, calc(100% - 2rem)); margin: clamp(2rem, 12vh, 8rem) auto; border: 1px solid var(--line); border-radius: 1rem; background: var(--white); }
.login-top { color: var(--rail-text); background: var(--rail); border-radius: 1rem 1rem 0 0; padding: 1rem; }
.login-body { display: grid; gap: .8rem; padding: 1.4rem; }
.login-body h1 { font-size: 2.4rem; }
.login-actions { display: flex; flex-wrap: wrap; gap: .3rem; }
.login-actions button { padding-inline: .15rem .6rem; }

@media (max-width: 58rem) {
  .shell { grid-template-columns: 1fr; }
  .rail { flex-direction: row; align-items: center; justify-content: space-between; gap: .7rem; flex-wrap: wrap; padding: .7rem 1rem; }
  .rail nav { display: flex; flex-wrap: wrap; order: 3; width: 100%; }
  .rail nav a { padding: .38rem .5rem; font-size: .9rem; gap: .4rem; }
  .profile { border-top: 0; padding: 0; margin: 0; }
}
@media (max-width: 42rem) {
  .card-grid, .inbox { grid-template-columns: 1fr; }
  .dialogs { max-height: 16rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
  .metric:last-child { grid-column: 1 / -1; }
  .metric strong { font-size: 1.6rem; }
  .main { padding: 1rem; }
  th, td { padding: .55rem; }
  .leads-table, .leads-table tbody { display: block; }
  .leads-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .leads-table tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: .6rem; }
  .leads-table td { display: block; }
  .leads-table td:nth-child(n+3)::before { display: block; content: attr(data-label); font-size: .8rem; color: var(--muted); }
}
@media (max-width: 27rem) {
  .form-grid { grid-template-columns: 1fr; }
  .heading { align-items: start; }
}
