:root {
  --navy: #1b365d;
  --navy-2: #152a49;
  --ink: #1c1917;
  --muted: #5c574f;
  --line: #e3ddd4;
  --paper: #f4f0ea;
  --card: #fffcf7;
  --accent: #0f6e6b;
  --accent-2: #0b5856;
  --danger: #9b2c2c;
  --gold: #8a5a12;
  --shadow: 0 1px 2px rgba(27, 54, 93, 0.06), 0 10px 28px rgba(27, 54, 93, 0.07);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  font-size: 16px;
  line-height: 1.45;
}

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

.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(15, 110, 107, 0.12), transparent 50%),
    radial-gradient(900px 500px at 110% 10%, rgba(27, 54, 93, 0.16), transparent 50%),
    var(--paper);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 36px 32px 32px;
}
.login-card h1 {
  margin: 0 0 6px;
  font-size: 26px;
  letter-spacing: -0.03em;
  color: var(--navy);
}
.login-card .sub { margin: 0 0 24px; color: var(--muted); }
.login-card label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.login-card input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #d4cfc6;
  border-radius: 10px;
  background: #fff;
  margin-bottom: 16px;
}
.login-card input:focus, .field input:focus, .field textarea:focus, .search input:focus {
  outline: 2px solid rgba(15, 110, 107, 0.35);
  border-color: var(--accent);
}
.err { color: var(--danger); min-height: 1.3em; margin: 0 0 8px; font-size: 14px; }

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--navy);
  color: #f7f4ef;
  flex-shrink: 0;
}
.brand { display: flex; flex-direction: column; min-width: 0; }
.brand strong { font-size: 16px; letter-spacing: -0.02em; }
.brand span { font-size: 11px; opacity: 0.75; }
.today-strip {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  opacity: 0.95;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.today-strip a { color: #fff; }
.topbar .sp { flex: 0; }
.top-actions { display: flex; gap: 8px; flex-shrink: 0; }

.shell {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  min-height: 0;
}

aside {
  background: #fbf8f3;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.search { padding: 12px 12px 8px; }
.search input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d4cfc6;
  border-radius: 10px;
  background: #fff;
}
.aside-actions { padding: 0 12px 8px; }
.list {
  flex: 1;
  overflow: auto;
  padding: 0 8px 16px;
  -webkit-overflow-scrolling: touch;
}
.list button.row {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 10px 10px;
  border-radius: 10px;
  display: block;
}
.list button.row:hover, .list button.row.active { background: #efe8dc; }
.row .co { font-weight: 650; color: var(--navy); display: block; }
.row .cn { color: var(--muted); font-size: 13px; }
.row .meta { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: 12px; color: var(--muted); }
.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: #e8efe9;
  color: #1e4d3a;
  font-weight: 600;
  font-size: 11px;
}
.badge.prospect { background: #f3ead4; color: #7a5410; }
.badge.customer { background: #dcefe8; color: #0b5856; }
.badge.not-interested, .badge.notinterested { background: #f0e4e4; color: #7a2e2e; }
.badge.auto-shop, .badge.autoshop { background: #e2ebf5; color: #1b365d; }
.empty { color: var(--muted); padding: 24px 16px; text-align: center; }

main {
  overflow: auto;
  padding: 18px 22px 48px;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(180deg, rgba(27, 54, 93, 0.03), transparent 120px),
    var(--paper);
}
.back {
  display: none;
  margin-bottom: 10px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 {
  margin: 0 0 16px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field.span-2 { grid-column: span 2; }
.field label { font-size: 12px; font-weight: 650; color: var(--muted); letter-spacing: 0.02em; }
.field input, .field textarea, .field select, .csz input, input[type="datetime-local"] {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #d4cfc6;
  border-radius: 10px;
  background: #fff;
}
.csz { display: grid; grid-template-columns: 1.4fr 0.7fr 0.7fr; gap: 8px; }
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  padding: 9px 14px;
  border-radius: 10px;
  font-weight: 650;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--accent-2); }
.btn.secondary {
  background: #fff;
  color: var(--navy);
  border-color: #d4cfc6;
}
.btn.secondary:hover { background: #f3eee6; }
.btn.navy { background: var(--navy); }
.btn.navy:hover { background: var(--navy-2); }
.btn.danger {
  background: transparent;
  color: var(--danger);
  border-color: #e4c9c9;
}
.btn.danger:hover { background: #f8ecec; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.linkish { background: transparent; color: var(--accent); border: 0; padding: 8px 6px; }

.placeholder {
  color: var(--muted);
  text-align: center;
  padding: 80px 20px;
}
.placeholder h2 { font-size: 22px; color: var(--navy); text-transform: none; letter-spacing: -0.03em; }

.cb-form, .note-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.cb-form .field, .note-form .field { flex: 1; min-width: 140px; }
.note-form { flex-direction: column; align-items: stretch; }
.note-form textarea { min-height: 110px; resize: vertical; }
.cb-item, .note {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.cb-item:first-of-type, .history .note:first-child { border-top: 0; }
.cb-item { display: flex; gap: 10px; justify-content: space-between; align-items: start; flex-wrap: wrap; }
.note time { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.note p { margin: 0; white-space: pre-wrap; }
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 50;
  display: none;
}
.toast.show { display: block; }

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(21, 42, 73, 0.45);
  display: none;
  place-items: center;
  padding: 16px;
  z-index: 40;
}
.modal-back.open { display: grid; }
.modal {
  background: var(--card);
  width: min(560px, 100%);
  max-height: min(86vh, 720px);
  overflow: auto;
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.modal h2 {
  margin: 0 0 8px;
  color: var(--navy);
  text-transform: none;
  letter-spacing: -0.03em;
  font-size: 20px;
}
.hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.status-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.status-row input { flex: 1; padding: 8px 10px; border: 1px solid #d4cfc6; border-radius: 8px; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  aside, main { display: none; min-height: 0; height: 100%; }
  body.list-view aside { display: flex; }
  body.contact-view main { display: block; }
  .back { display: inline-flex; }
  .grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: auto; }
  .csz { grid-template-columns: 1fr 80px 90px; }
  .topbar { flex-wrap: wrap; }
  .today-strip { flex-basis: 100%; white-space: normal; }
  main { padding: 14px 12px 40px; }
  .card { padding: 16px; }
}
