/* IP Diamonds CRM
   Restrained, high contrast, built for scanning a long list of leads
   quickly. Champagne accent because the business sells diamonds; every
   other colour carries meaning, not decoration. */

:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-2: #f3f1ed;
  --border: #e2ded6;
  --text: #14151a;
  --text-dim: #6b6a66;
  --text-faint: #9a9892;
  --accent: #9a7b31;
  --accent-soft: #f2e9d6;
  --danger: #b3261e;
  --ok: #2e6b46;
  --warn: #8a5a12;
  --shadow: 0 1px 2px rgba(20, 21, 26, 0.06), 0 8px 24px rgba(20, 21, 26, 0.08);
  --radius: 10px;
  --sidebar-w: 232px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f13;
    --surface: #16181e;
    --surface-2: #1d2029;
    --border: #2a2e39;
    --text: #edecea;
    --text-dim: #9b9a97;
    --text-faint: #6c6b68;
    --accent: #c9a961;
    --accent-soft: #2a2413;
    --danger: #e06b62;
    --ok: #6bbf8e;
    --warn: #d9a441;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Assistant", "Heebo", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.brand { display: flex; align-items: baseline; gap: 9px; }
.brand-mark { font-size: 21px; letter-spacing: -0.02em; font-weight: 600; }
.brand-sub { color: var(--text-faint); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }

/* ---------------------------------------------------------------- Login */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 40px 34px;
  box-shadow: var(--shadow);
}

.login-card .brand-mark { font-size: 26px; }
.login-card p.lede { color: var(--text-dim); margin: 6px 0 28px; font-size: 14px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }

.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }

.btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  transition: filter 0.15s;
}

.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn-quiet {
  width: auto;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 7px 12px;
  font-weight: 500;
  font-size: 13px;
}

.btn-quiet:hover { color: var(--text); border-color: var(--text-faint); filter: none; }

.error, .notice {
  padding: 11px 13px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}

.error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
}

.notice {
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--text);
}

/* ---------------------------------------------------------------- Shell */

.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  grid-column: 1;
  background: var(--surface);
  border-inline-start: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand { padding: 20px 20px 18px; border-bottom: 1px solid var(--border); }

#nav { padding: 12px 10px; flex: 1; overflow-y: auto; }

#nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14.5px;
  margin-bottom: 2px;
  transition: background 0.12s, color 0.12s;
}

#nav a:hover { background: var(--surface-2); color: var(--text); }

#nav a.on {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

#nav .ico { width: 18px; text-align: center; opacity: 0.75; font-size: 13px; }

#nav em {
  margin-inline-start: auto;
  font-style: normal;
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.sidebar-foot {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.who { flex: 1; font-size: 13px; line-height: 1.3; min-width: 0; }
.who strong { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { color: var(--text-faint); font-size: 12px; }

.main { grid-column: 2; min-width: 0; padding-bottom: 40px; }

.view-title {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 26px 0;
  flex-wrap: wrap;
}

.view-title h1 { margin: 0; font-size: 23px; letter-spacing: -0.02em; font-weight: 600; }
.view-title .sub { color: var(--text-faint); font-size: 13.5px; }
.spacer { flex: 1; }

/* --------------------------------------------------------------- Stats */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 18px 26px 0;
}

.stat { background: var(--surface); padding: 14px 18px; }
.stat .n { font-size: 25px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--text-faint); letter-spacing: 0.03em; }

/* ------------------------------------------------------------- Toolbar */

.toolbar { display: flex; gap: 10px; padding: 16px 26px; align-items: center; flex-wrap: wrap; }

.toolbar input[type="search"] {
  flex: 1;
  min-width: 200px;
  padding: 9px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.toolbar input[type="search"]:focus { border-color: var(--accent); }

.toolbar select, .toolbar button {
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  color: var(--text);
}

.toolbar button:hover { border-color: var(--accent); color: var(--accent); }
.count { color: var(--text-faint); font-size: 13px; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- Cards */

.card {
  margin: 0 26px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-head {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
}

.card-head .sub { font-weight: 400; color: var(--text-faint); font-size: 13px; }
.card-body { padding: 16px 18px; }
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: right;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-faint);
  letter-spacing: 0.03em;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
}

td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; transition: background 0.1s; }
tr.clickable:hover { background: var(--surface-2); }

.name { font-weight: 600; }
.muted { color: var(--text-dim); font-size: 13px; }

.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
  text-align: left;
}

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.pill[data-s="new"]       { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.pill[data-s="contacted"] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.pill[data-s="qualified"] { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.pill[data-s="won"]       { color: #fff; background: var(--ok); border-color: var(--ok); }
.pill[data-s="lost"]      { color: var(--text-faint); }
.pill.ok    { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.pill.bad   { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.pill.idle  { color: var(--text-faint); }

.empty { padding: 50px 24px; text-align: center; color: var(--text-faint); }

/* --------------------------------------------------------------- Panel */

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 40; }

.panel {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(540px, 100%);
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  z-index: 50;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.panel-head {
  padding: 22px 24px 16px 56px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.panel-head h2 { margin: 0 0 3px; font-size: 20px; letter-spacing: -0.01em; }
.panel-body { padding: 20px 24px 40px; }

.panel-close {
  position: absolute;
  top: 18px;
  left: 18px;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 24px;
  line-height: 1;
  padding: 2px 8px;
}

.panel-close:hover { color: var(--text); }

/* Question labels come straight from the advertiser and can be long
   Hebrew sentences. They wrap onto their own line above the answer
   rather than fighting it for horizontal space. */
dl.facts { margin: 0; }

.row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  min-width: 0;
}

.row:last-child { border-bottom: none; }

.row dt {
  color: var(--text-faint);
  font-size: 12.5px;
  margin-bottom: 3px;
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.row dd { margin: 0; overflow-wrap: anywhere; min-width: 0; }

/* Short label and short value sit on one line; anything longer stacks. */
@media (min-width: 520px) {
  .row.inline { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 14px; align-items: baseline; }
  .row.inline dt { margin-bottom: 0; }
}

.section-title {
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 26px 0 8px;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.actions a, .actions button {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  width: auto;
}

.actions a:hover, .actions button:hover { border-color: var(--accent); color: var(--accent); filter: none; }

/* ------------------------------------------------------------ WhatsApp */

.chat { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 520px; }
.chat-list { border-inline-start: 1px solid var(--border); overflow-y: auto; max-height: 68vh; }

.thread {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.thread:hover, .thread.on { background: var(--surface-2); }
.thread strong { display: block; font-size: 14px; }
.thread .last { color: var(--text-faint); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-pane { display: flex; flex-direction: column; max-height: 68vh; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 18px; }

.msg {
  padding: 9px 13px;
  border-radius: 12px;
  margin-bottom: 8px;
  max-width: 78%;
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.in  { background: var(--surface-2); margin-inline-end: auto; }
.msg.out { background: var(--accent-soft); margin-inline-start: auto; }
.msg time { display: block; font-size: 11px; color: var(--text-faint); margin-top: 4px; }

.chat-send { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.chat-send input { flex: 1; padding: 10px 13px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; outline: none; }
.chat-send button { width: auto; padding: 10px 20px; }

/* --------------------------------------------------------------- Toast */

.toast {
  position: fixed;
  bottom: 22px;
  inset-inline-start: 22px;
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 9px;
  font-size: 14px;
  z-index: 90;
  box-shadow: var(--shadow);
  max-width: 420px;
}

/* -------------------------------------------------------------- Mobile */

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; grid-column: 1; border-inline-start: none; border-bottom: 1px solid var(--border); }
  #nav { display: flex; overflow-x: auto; padding: 8px; }
  #nav a { white-space: nowrap; margin-bottom: 0; }
  #nav em { display: none; }
  .main { grid-column: 1; }
  .stats, .card, .toolbar, .view-title { margin-inline: 12px; padding-inline: 0; }
  .toolbar { padding: 14px 12px; }
  .view-title { padding: 18px 12px 0; }
  .chat { grid-template-columns: 1fr; }
  .chat-list { max-height: 200px; }
}
