/* TerriTool Sales Desk — classic, professional, minimal */

:root {
  --ink: #1a2330;
  --ink-soft: #3d4a5c;
  --muted: #6a7585;
  --line: #dce1e8;
  --line-soft: #eaedf2;
  --paper: #f4f2ee;
  --surface: #ffffff;
  --accent: #1e4a6e;
  --accent-hover: #163a57;
  --accent-soft: #e8eef3;
  --danger: #a33b32;
  --warn: #9a6b1f;
  --ok: #2f6b4f;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(26, 35, 48, 0.04), 0 8px 24px rgba(26, 35, 48, 0.06);
  --font: 'Source Sans 3', 'Helvetica Neue', sans-serif;
  --font-display: 'Source Serif 4', Georgia, serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(30, 74, 110, 0.07), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(47, 107, 79, 0.05), transparent 50%),
    var(--paper);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

/* ---------- sync modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(26, 35, 48, 0.48);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 36px 32px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow);
  text-align: center;
}
.modal-card img { height: 30px; margin-bottom: 20px; }
.modal-card h2 {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 10px;
}
.modal-card p {
  color: var(--muted); line-height: 1.5;
  margin-bottom: 18px; font-size: 14px;
}
.modal-card .modal-mcp-url {
  margin: -6px 0 22px; font-size: 12px; color: var(--muted); word-break: break-all;
}
.modal-card .modal-mcp-url code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  background: var(--paper);
  padding: 3px 7px; border-radius: 4px;
  border: 1px solid var(--line); color: var(--ink-soft);
}
.modal-card .modal-actions { display: flex; flex-direction: column; gap: 8px; }
.modal-card .btn-primary {
  width: 100%; padding: 12px 14px;
  background: var(--accent); color: #fff;
  border: 0; border-radius: var(--radius);
  font-weight: 600; font-size: 14.5px; letter-spacing: 0.01em;
}
.modal-card .btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.modal-card .btn-primary:disabled { opacity: .6; cursor: wait; }
.modal-card .btn-secondary {
  width: 100%; padding: 11px 14px;
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: var(--radius);
  font-weight: 550; font-size: 14px;
}
.modal-card .btn-secondary:hover {
  color: var(--ink); border-color: #c8ced8; background: var(--paper);
}
.modal-card .modal-error { color: var(--danger); font-size: 13px; min-height: 1.2em; margin-top: 4px; }
.modal-card .modal-status { color: var(--muted); font-size: 13px; min-height: 1.2em; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 40px 36px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow);
}
.login-logo { height: 32px; display: block; margin-bottom: 28px; }
.login-card h1 {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.login-card .sub { color: var(--muted); margin-bottom: 28px; font-size: 14.5px; }
.login-card label {
  display: block; font-weight: 600; font-size: 12.5px;
  letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--ink-soft); margin: 16px 0 6px;
}
.login-card input {
  width: 100%; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 15px; background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30, 74, 110, 0.12);
}
.login-card button {
  width: 100%; margin-top: 26px; padding: 12px;
  background: var(--accent); color: #fff;
  border: 0; border-radius: var(--radius);
  font-weight: 600; font-size: 15px;
}
.login-card button:hover { background: var(--accent-hover); }
.login-error { color: var(--danger); margin-top: 14px; font-size: 13px; }

/* ---------- layout ---------- */
.topbar {
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px; min-height: 64px;
  position: sticky; top: 0; z-index: 30;
  box-shadow: 0 1px 10px rgba(26, 35, 48, 0.035);
}
.brand {
  display: flex; align-items: center; gap: 12px;
  margin-right: 8px; white-space: nowrap;
}
.brand img { height: 24px; display: block; }
.brand span {
  color: var(--ink-soft);
  font-weight: 650; font-size: 11.5px;
  letter-spacing: 0.1em; text-transform: uppercase;
  border-left: 1px solid var(--line); padding-left: 14px;
}
.topbar .spacer { flex: 1; }
.sync-status-wrap {
  display: flex; align-items: center; gap: 7px;
  min-width: 0;
  padding: 6px 10px;
  background: #f7f9f8;
  border: 1px solid #e4ebe7;
  border-radius: 999px;
}
.sync-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex: 0 0 auto;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(47, 107, 79, 0.1);
}
.topbar .sync-status {
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions {
  display: flex; align-items: center; gap: 7px;
  padding-right: 14px;
  border-right: 1px solid var(--line);
}
.account {
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap;
}
.avatar {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px; font-weight: 700; letter-spacing: .03em;
}
.topbar .who {
  color: var(--ink-soft); font-size: 12.5px; font-weight: 600;
}
.btn {
  min-height: 34px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 7px;
  font-weight: 600; font-size: 12.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s, transform .12s;
}
.btn:hover {
  background: var(--paper); color: var(--ink); border-color: #c8ced8;
  box-shadow: 0 1px 2px rgba(26, 35, 48, .06);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid rgba(30, 74, 110, .16); outline-offset: 1px; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn.logout {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding-left: 8px; padding-right: 8px;
}
.btn.logout:hover { background: var(--paper); color: var(--ink); box-shadow: none; }

.tabs {
  display: flex; gap: 0; overflow-x: auto;
  background: rgba(255, 255, 255, 0.7);
  border-bottom: 1px solid var(--line);
  padding: 0 20px;
}
.tab {
  padding: 13px 16px; border: 0; background: none;
  font-weight: 600; font-size: 13.5px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--ink-soft); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count {
  background: var(--accent-soft); color: var(--accent);
  border-radius: 4px; padding: 1px 7px;
  font-size: 11px; font-weight: 650; margin-left: 6px;
}
.tab .due { background: var(--danger); color: #fff; }

.filters {
  display: flex; gap: 8px; padding: 14px 20px 10px;
  flex-wrap: wrap; align-items: center;
}
.filters input[type=search] {
  padding: 9px 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  min-width: 200px; flex: 1; max-width: 320px;
  background: var(--surface);
}
.filters input[type=search]:focus,
.filters select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30, 74, 110, 0.1);
}
.filters select {
  padding: 9px 11px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); font-size: 13px; color: var(--ink-soft);
}

/* ---------- grid ---------- */
.grid-wrap {
  margin: 0 20px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 1px 2px rgba(26, 35, 48, 0.03);
}
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; }
.grid th {
  position: sticky; top: 0; z-index: 10;
  background: #faf9f7;
  text-align: left;
  font-size: 11px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted);
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap; cursor: pointer; user-select: none;
}
.grid th.sorted { color: var(--accent); }
.grid td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
  max-width: 320px; overflow: hidden; text-overflow: ellipsis;
  vertical-align: middle;
  color: var(--ink-soft);
}
.grid tr.lead-row { cursor: pointer; }
.grid tr.lead-row:hover td { background: #f7f5f1; }
.grid th.pin, .grid td.pin {
  position: sticky; left: 0; z-index: 5;
  background: var(--surface);
  border-right: 1px solid var(--line-soft);
  font-weight: 600; min-width: 160px; color: var(--ink);
}
.grid th.pin { z-index: 15; background: #faf9f7; }
.grid tr.lead-row:hover td.pin { background: #f7f5f1; }
.grid select.inline {
  padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--surface); font-size: 13px; max-width: 140px;
  color: var(--ink-soft);
}
.empty-state {
  padding: 56px 24px; text-align: center; color: var(--muted);
  font-size: 14.5px; line-height: 1.5;
}

/* ---------- pagination ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 0 20px 18px;
}
.pager-top .pager {
  padding-bottom: 10px;
}
.pager-info, .pager-page {
  color: var(--muted);
  font-size: 12.5px;
}
.pager-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pager-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- loading overlay ---------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(247, 245, 241, 0.72);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading-overlay[hidden] { display: none !important; }
.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 22px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 180px;
}
.loading-spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.loading-msg {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11.5px; font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.pill.list-new_trial { background: var(--accent-soft); color: var(--accent); }
.pill.list-cancelled_sub { background: #f5e8e6; color: var(--danger); }
.pill.list-cancelled_trial { background: #f5efdf; color: var(--warn); }
.pill.yes { background: var(--accent); color: #fff; }
.pill.no { background: var(--line-soft); color: var(--muted); }

.st {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11.5px; font-weight: 600;
}
.st-New { background: #eceff2; color: #425064; }
.st-Contacting { background: #f5efdf; color: var(--warn); }
.st-Contacted { background: var(--accent-soft); color: var(--accent); }
.st-Interested { background: #e6f0ea; color: var(--ok); }
.st-Booked { background: #e8ecef; color: #3a4d5c; }
.st-DeckSent { background: #e9eef2; color: #355066; }
.st-Negotiations { background: #f0ebe6; color: #6b4f3a; }
.st-Won { background: var(--ok); color: #fff; }
.st-Lost { background: #5a6572; color: #fff; }
.st-NotInterested { background: #f5e8e6; color: var(--danger); }
.st-Unreachable { background: #eceff2; color: var(--muted); }

.attempts { font-size: 11.5px; color: var(--muted); margin-left: 6px; }
.attempts.hot { color: var(--danger); font-weight: 700; }

.fu { font-size: 13px; font-weight: 600; }
.fu.overdue { color: var(--danger); }
.fu.today { color: var(--warn); }

.act-type {
  display: inline-block;
  font-size: 11px; font-weight: 650;
  letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft);
  padding: 2px 6px; border-radius: 3px; margin-right: 6px;
}

/* ---------- drawer ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(26, 35, 48, 0.32); z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 520px; max-width: 100%;
  background: var(--surface); z-index: 50;
  box-shadow: -12px 0 40px rgba(26, 35, 48, 0.1);
  display: flex; flex-direction: column;
  border-left: 1px solid var(--line);
}
.drawer-head {
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; gap: 10px;
  background: #faf9f7;
}
.drawer-head h2 {
  font-family: var(--font-display);
  font-size: 20px; font-weight: 600; letter-spacing: -0.01em;
}
.drawer-head .close {
  margin-left: auto; border: 0; background: none;
  font-size: 24px; line-height: 1; color: var(--muted); padding: 4px 8px;
}
.drawer-head .close:hover { color: var(--ink); }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 22px 32px; -webkit-overflow-scrolling: touch; }
.journey { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.drawer h3 {
  font-size: 11px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin: 22px 0 10px;
}
.fieldgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.fieldgrid .f label {
  display: block; font-size: 11.5px; color: var(--muted);
  margin-bottom: 4px; font-weight: 600; letter-spacing: 0.02em;
}
.fieldgrid .f select, .fieldgrid .f input {
  width: 100%; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--surface); font-size: 13.5px;
}
.contact-insight {
  margin-top: 22px;
}
.contact-insight h3 {
  margin-top: 0;
}
.contact-insight-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px;
  background: #f7f8fb;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.insight-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.insight-item .k {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.insight-item .v {
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.sa-facts {
  background: var(--paper); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 12px 14px;
}
.sa-facts .row { display: flex; gap: 8px; padding: 4px 0; font-size: 13px; }
.sa-facts .row .k { color: var(--muted); min-width: 130px; flex-shrink: 0; }
.sa-facts .row .v { word-break: break-word; white-space: pre-wrap; color: var(--ink-soft); }

.act-form {
  background: var(--paper); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 14px;
}
.act-form .row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.act-form select, .act-form input {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--surface); font-size: 13.5px;
}
.act-form textarea {
  width: 100%; min-height: 64px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 4px;
  resize: vertical; background: var(--surface); font-size: 13.5px;
}
.act-form .actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }

.timeline { margin-top: 6px; }
.tl-item {
  display: flex; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}
.tl-icon {
  min-width: 52px; height: 28px; padding: 0 8px;
  border-radius: 4px; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; flex-shrink: 0;
}
.tl-main { flex: 1; min-width: 0; }
.tl-head { font-size: 13px; color: var(--ink-soft); }
.tl-head b { text-transform: capitalize; color: var(--ink); }
.tl-when { color: var(--muted); font-size: 12px; }
.tl-note { margin-top: 4px; font-size: 13px; white-space: pre-wrap; color: var(--ink-soft); }
.tl-del { border: 0; background: none; color: var(--muted); font-size: 12px; padding: 2px 4px; }
.tl-del:hover { color: var(--danger); }

/* ---------- follow-ups ---------- */
.fu-page { padding: 4px 20px 28px; max-width: 1100px; }
.fu-summary { color: var(--muted); font-size: 13px; margin-left: 4px; }
.fu-empty { max-width: 440px; margin: 48px auto; text-align: center; }
.fu-empty h3 {
  font-family: var(--font-display);
  font-size: 20px; font-weight: 600; margin-bottom: 10px; color: var(--ink);
}
.fu-empty p { line-height: 1.5; color: var(--muted); }
.fu-section h2 {
  font-size: 13px; font-weight: 650; letter-spacing: 0.04em;
  text-transform: uppercase; margin: 22px 0 10px;
  display: flex; align-items: center; gap: 8px; color: var(--ink-soft);
}
.fu-section h2 .n {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 8px;
  font-size: 11.5px; color: var(--muted); text-transform: none; letter-spacing: 0;
}
.fu-section h2.overdue { color: var(--danger); }
.fu-section h2.today { color: var(--warn); }
.fu-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 8px;
  display: flex; align-items: flex-start; gap: 14px;
  cursor: pointer; flex-wrap: wrap; justify-content: space-between;
  transition: border-color .12s;
}
.fu-card:hover { border-color: #b7c2cf; }
.fu-card.overdue { border-left: 2px solid var(--danger); }
.fu-card.today { border-left: 2px solid var(--warn); }
.fu-card-main { flex: 1; min-width: 200px; }
.fu-card-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.fu-card-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.fu-card .who { color: var(--muted); font-size: 12.5px; }
.fu-card .name { font-weight: 600; font-size: 14.5px; color: var(--ink); }
.fu-card-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.fu-card-actions .btn { padding: 7px 10px; font-size: 12.5px; }
input.fu-date.inline, .fu-card-actions input.fu-date {
  padding: 7px 8px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--surface); font-size: 13px; max-width: 150px;
}
.grid input.fu-date.inline {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--surface); font-size: 13px;
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 6px;
  font-size: 13.5px; z-index: 100;
  box-shadow: var(--shadow);
}
.toast.err { background: var(--danger); }

@media (max-width: 900px) {
  .drawer { width: 100%; }
  .grid-wrap { margin: 0 10px 10px; }
  .filters { padding: 10px; }
  .tabs, .topbar { padding-left: 10px; padding-right: 10px; }
  .topbar { gap: 9px; }
  .sync-status-wrap { display: none; }
  .topbar-actions { padding-right: 9px; }
  .account .who { display: none; }
  .pager { padding-left: 10px; padding-right: 10px; }
  .grid td, .grid th { padding: 12px 10px; }
  .grid select.inline { padding: 9px 8px; }
  .fieldgrid { grid-template-columns: 1fr; }
  .contact-insight-grid { grid-template-columns: 1fr; }
  .fu-page { padding-left: 10px; padding-right: 10px; }
}

@media (max-width: 620px) {
  .topbar { min-height: 58px; gap: 7px; overflow-x: auto; }
  .brand { margin-right: 2px; }
  .brand img { height: 22px; }
  .brand span, .account .avatar { display: none; }
  .topbar-actions { gap: 5px; padding-right: 7px; }
  .topbar .btn { min-height: 32px; padding: 6px 9px; font-size: 12px; }
}
