:root {
  --green: #7ed957;
  --green-deep: #3d7a1f;
  --navy: #001c72;
  --navy-deep: #000f42;
  --red: #e30613;
  --gold: #e8a908;
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-soft: #4b5563;
  --line: #e5e7eb;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 28, 114, 0.08);
  --shadow-lg: 0 18px 50px rgba(0, 28, 114, 0.18);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Plus Jakarta Sans", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }

.screen { padding: 16px; max-width: 900px; margin: 0 auto; }

/* ---------- LOGIN ---------- */
#login { display: grid; place-items: center; min-height: 100dvh; }
.login-card {
  background: var(--card); border-radius: 22px; padding: 28px;
  box-shadow: var(--shadow-lg); width: 100%; max-width: 380px;
  display: grid; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--navy);
  position: relative;
}
.brand-mark::before {
  content: ""; position: absolute; inset: 8px;
  background: var(--green);
  clip-path: polygon(50% 0, 100% 60%, 100% 100%, 0 100%, 0 60%);
}
.brand-mark.small { width: 32px; height: 32px; border-radius: 8px; }
.brand-mark.small::before { inset: 6px; }
.brand-title { font-weight: 800; letter-spacing: -0.01em; }
.brand-sub { color: var(--ink-soft); font-size: 13px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.field input, .field select, .field textarea {
  font: inherit; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: #fff; color: var(--ink);
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(0, 28, 114, 0.12);
}

.btn-primary {
  font: inherit; font-weight: 700; padding: 14px 18px;
  border: none; border-radius: 12px; cursor: pointer;
  background: var(--navy); color: #fff; letter-spacing: 0.01em;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
}
.btn-primary:hover:not(:disabled) { background: var(--navy-deep); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary .ico { width: 18px; height: 18px; }

.btn-text {
  font: inherit; background: none; border: none; color: var(--ink-soft);
  text-decoration: underline; cursor: pointer; padding: 10px 0; font-size: 13px;
  width: 100%; text-align: center; margin-top: 4px;
}
.btn-text:hover { color: var(--navy); }

/* Icons */
.ico    { width: 18px; height: 18px; flex: none; }
.ico-lg { width: 22px; height: 22px; flex: none; }

.error { color: var(--red); font-size: 14px; margin: 0; }
.ok    { color: var(--green-deep); font-size: 14px; margin: 0;
         display: inline-flex; align-items: center; gap: 6px; }
.ok .ico { color: var(--green-deep); }
.lead-copy { color: var(--ink-soft); font-size: 14px; margin: 0 0 14px; line-height: 1.5; }

/* Code input (the big number-pad input) */
#code-input {
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 26px; font-weight: 700; letter-spacing: 8px;
  text-align: center; padding: 14px;
}
#login-step-2 { display: grid; gap: 12px; }
#login-step-1 { display: grid; gap: 12px; }

/* ---------- TOPBAR ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); padding: 12px 14px; border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-title { font-weight: 800; letter-spacing: -0.01em; }
.topbar-sub { color: var(--ink-soft); font-size: 13px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--navy);
}
.icon-btn:hover { background: #f8fafc; }
.icon-btn:disabled { opacity: 0.4; }
.icon-btn .ico { width: 18px; height: 18px; }
#notif-toggle.active { background: var(--green); color: var(--navy); border-color: var(--green); }
#notif-toggle.active:hover { background: #6bc847; }

/* ---------- COUNTERS ---------- */
.counters {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  margin-bottom: 14px;
}
@media (max-width: 540px) { .counters { grid-template-columns: repeat(2, 1fr); } }
.counter {
  display: grid; gap: 4px; padding: 14px 12px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); text-align: left;
  font: inherit; cursor: pointer;
}
.counter:hover { border-color: var(--navy); }
.counter-value { font-size: 28px; font-weight: 800; line-height: 1; color: var(--navy); }
.counter-label { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.counter[data-filter="followup"] .counter-value { color: var(--red); }
.counter[data-filter="no_answer"] .counter-value { color: var(--gold); }
.counter[data-filter="quoted"] .counter-value { color: var(--navy); }

/* ---------- TOOLBAR ---------- */
.toolbar { display: grid; gap: 10px; margin-bottom: 12px; }
#search {
  font: inherit; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: #fff;
}
#search:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(0, 28, 114, 0.12); }

.chips { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.chip {
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 8px 12px; border-radius: 999px;
  background: #fff; border: 1px solid var(--line); color: var(--ink-soft);
  cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ---------- LIST ---------- */
.list { display: grid; gap: 8px; }
.row {
  background: var(--card); border-radius: var(--radius); padding: 12px 14px;
  display: grid; grid-template-columns: 1fr auto; gap: 10px;
  box-shadow: var(--shadow); cursor: pointer; border: 1px solid transparent;
}
.row:hover { border-color: var(--navy); }
.row-main { display: grid; gap: 4px; min-width: 0; }
.row-name { font-weight: 700; letter-spacing: -0.01em; }
.row-line { color: var(--ink-soft); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-aside { display: grid; gap: 6px; justify-items: end; }
.ago { font-size: 12px; color: var(--ink); font-weight: 600; }
.ago-sub { font-size: 11px; color: var(--ink-soft); }

.pill {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase;
  background: #eef2ff; color: var(--navy);
}
.pill[data-status="new"]       { background: #e0f2fe; color: #075985; }
.pill[data-status="called"]    { background: #e9f7e0; color: var(--green-deep); }
.pill[data-status="no_answer"] { background: #fff4dc; color: #92400e; }
.pill[data-status="quoted"]    { background: #ede9fe; color: #5b21b6; }
.pill[data-status="won"]       { background: var(--green); color: var(--navy); }
.pill[data-status="lost"]      { background: #fee2e2; color: #b91c1c; }

.row.followup { box-shadow: 0 0 0 2px rgba(227, 6, 19, 0.15), var(--shadow); }
.row.followup .ago { color: var(--red); font-weight: 700; }

.empty { text-align: center; color: var(--ink-soft); padding: 32px; }

/* ---------- DRAWER ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.5); }
.drawer-panel {
  position: absolute; right: 0; top: 0; height: 100dvh; width: min(480px, 100%);
  background: var(--bg); overflow-y: auto;
  display: grid; gap: 14px; padding: 14px 14px calc(20px + env(safe-area-inset-bottom));
  animation: slideIn 180ms ease-out;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: none; } }
@media (max-width: 540px) {
  .drawer-panel { width: 100%; }
  @keyframes slideIn { from { transform: translateY(100%); } to { transform: none; } }
}

.drawer-head {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); padding: 12px 14px; border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.drawer-title { font-weight: 800; font-size: 18px; letter-spacing: -0.01em; }
.drawer-sub { color: var(--ink-soft); font-size: 13px; }

.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.qa {
  display: grid; place-items: center; gap: 6px; padding: 16px 8px;
  border-radius: var(--radius); text-decoration: none;
  font-weight: 700; font-size: 13px; color: #fff;
  background: var(--navy);
}
.qa:hover { filter: brightness(1.07); }
.qa .ico-lg { color: currentColor; }
.qa-call { background: var(--green); color: var(--navy); }
.qa-wa   { background: #25d366; }
.qa-mail { background: var(--navy); }

.kv {
  background: var(--card); border-radius: var(--radius); padding: 12px 14px;
  display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 0;
  box-shadow: var(--shadow);
}
.kv dt { color: var(--ink-soft); font-size: 13px; font-weight: 600; align-self: start; padding-top: 2px; }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }
.kv dd.msg { white-space: pre-wrap; line-height: 1.45; }

.edit-block {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  display: grid; gap: 12px; box-shadow: var(--shadow);
}
.edit-block textarea { resize: vertical; min-height: 88px; }
