:root {
  --ink: #1c1c1e; --ink-soft: #46464b; --muted: #6b6b70;
  --paper: #f6f4ef; --card: #ffffff; --line: #e4dfd3;
  --gold: #beaf87; --gold-deep: #8a7a4f;
  --ok: #2e6b3f; --warn: #a15c00; --bad: #a12c2c;
  --radius: 12px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--gold-deep); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--ink); color: #fff;
}
.logo {
  width: 36px; height: 36px; border-radius: 9px; background: #000; color: var(--gold);
  display: grid; place-items: center; font: 700 15px Georgia, serif; text-decoration: none; flex: none;
}
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { color: #cfcabb; text-decoration: none; padding: 7px 12px; border-radius: 999px; font-weight: 600; font-size: .92rem; white-space: nowrap; }
.tabs a.active { background: #2c2c30; color: #fff; }

#view { max-width: 980px; margin: 0 auto; padding: 18px 16px 40px; }
.foot { max-width: 980px; margin: 0 auto; padding: 0 16px 40px; display: flex; justify-content: space-between; gap: 12px; font-size: .88rem; color: var(--muted); }
.foot form { margin: 0; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); padding: 9px 14px; border-radius: 10px; font: 600 .95rem var(--sans);
  text-decoration: none; cursor: pointer; min-height: 40px;
}
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: default; }
.linkish { background: none; border: 0; color: var(--muted); font: inherit; text-decoration: underline; cursor: pointer; padding: 0; }
input, select, textarea {
  width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 4px; }

/* Cards & lists */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 22px 0 8px; }
.section-title h2 { margin: 0; }
.count { background: var(--ink); color: #fff; border-radius: 999px; padding: 1px 9px; font-size: .8rem; font-weight: 700; }
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none; }
.row:hover { background: #faf8f3; }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; }
.row .sub { font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .side { text-align: right; font-size: .82rem; color: var(--muted); flex: none; }
.empty { padding: 18px; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }

.pill { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 999px; background: #eee9dc; color: var(--ink-soft); }
.pill.new { background: #fde9c8; color: #6b4300; }
.pill.under_contract, .pill.active_buyer, .pill.active_seller { background: #dcebdf; color: var(--ok); }
.pill.ref { background: #f7dede; color: var(--bad); }
.overdue { color: var(--bad); font-weight: 700; }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.toolbar input { flex: 1 1 220px; }
.toolbar select { flex: 0 1 200px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat span { font-size: .8rem; color: var(--muted); text-transform: capitalize; }

/* Contact */
.contact-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; justify-content: space-between; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 .full { grid-column: 1 / -1; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: .95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.alert { border-left: 4px solid var(--bad); background: #fbefef; padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 0; border-top: 1px solid var(--line); }
.timeline .meta { font-size: .8rem; color: var(--muted); }
.timeline .kind { font-weight: 700; text-transform: capitalize; color: var(--ink); }
.timeline .body { white-space: pre-wrap; }
.log-kinds { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.log-kinds input { display: none; }
.log-kinds label { margin: 0; text-transform: none; letter-spacing: 0; font-size: .9rem; color: var(--ink); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; cursor: pointer; background: #fff; }
.log-kinds input:checked + label { background: var(--ink); color: #fff; border-color: var(--ink); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; font-size: .88rem; color: var(--muted); }

/* Pipeline */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: #ece8de; border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col h3 { display: flex; justify-content: space-between; text-transform: capitalize; font-size: .9rem; }
.mini { display: block; background: #fff; border-radius: 9px; padding: 9px 11px; margin-bottom: 8px; text-decoration: none; border: 1px solid var(--line); }
.mini small { display: block; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 50; }

/* Login */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 28px; text-align: center; }
.login-card .logo { margin: 0 auto 14px; width: 48px; height: 48px; font-size: 18px; }
.login-card form { text-align: left; display: grid; gap: 10px; margin-top: 10px; }

@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
  .row .side { display: none; }
  .top .btn { padding: 6px 10px; }
}
