/* ============================================================
   Lead Console — themeable. Deep teal accent in both modes.
   Light = default. Dark = [data-theme="dark"] on <html>.
   ============================================================ */

:root,
[data-theme="light"] {
  --bg:         #f6f7f8;
  --surface:    #ffffff;
  --surface-2:  #f0f2f3;
  --surface-3:  #e8ebed;
  --line:       #e2e6e9;
  --line-soft:  #eef1f2;
  --text:       #1a2127;
  --text-dim:   #5e6b76;
  --text-faint: #95a1ab;

  --accent:        #0f7d75;
  --accent-hover:  #0c6a63;
  --accent-soft:   #e3f1ef;
  --accent-ink:    #ffffff;

  --new-bg:       #fdf3e1;  --new-fg:       #a76a16;
  --contacted-bg: #e3f1ef;  --contacted-fg: #0c6a63;
  --closed-bg:    #eef0f2;  --closed-fg:    #6b7682;

  --danger:    #c8392f;
  --danger-bg: #fbe9e7;

  --bubble-out-bg: #0f7d75;
  --bubble-out-fg: #ffffff;
  --bubble-in-bg:  #eef1f2;
  --bubble-in-fg:  #1a2127;

  --shadow: 0 1px 2px rgba(16,32,40,.06), 0 2px 8px rgba(16,32,40,.04);
  --login-glow: #dfeeec;
}

[data-theme="dark"] {
  --bg:         #11161b;
  --surface:    #192027;
  --surface-2:  #202932;
  --surface-3:  #28323d;
  --line:       #29333d;
  --line-soft:  #1f272f;
  --text:       #e7edf2;
  --text-dim:   #97a4b1;
  --text-faint: #6c7986;

  --accent:        #2bb3a3;
  --accent-hover:  #34c4b3;
  --accent-soft:   #15302e;
  --accent-ink:    #06201d;

  --new-bg:       #362b15;  --new-fg:       #e6b057;
  --contacted-bg: #133230;  --contacted-fg: #4fcabb;
  --closed-bg:    #232c35;  --closed-fg:    #8593a0;

  --danger:    #ef6b60;
  --danger-bg: #3a1c1a;

  --bubble-out-bg: #1f8d80;
  --bubble-out-fg: #f3fffd;
  --bubble-in-bg:  #232c35;
  --bubble-in-fg:  #e7edf2;

  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 2px 10px rgba(0,0,0,.25);
  --login-glow: #15302e;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; color: var(--text); }
::placeholder { color: var(--text-faint); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 320px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}

.sidebar-header {
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.brand { display: flex; gap: 11px; align-items: center; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(150deg, var(--accent), var(--accent-hover));
  flex-shrink: 0; position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; left: 7px; right: 7px; top: 12px;
  height: 2px; background: var(--accent-ink); opacity: .55;
  border-radius: 2px; box-shadow: 0 5px 0 var(--accent-ink);
}
.brand h1 { font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.brand p { font-size: 11.5px; color: var(--text-dim); }

.header-controls { display: flex; gap: 6px; flex-shrink: 0; }
.theme-btn, .logout {
  background: none; border: 1px solid var(--line);
  color: var(--text-dim); font-size: 11.5px;
  padding: 5px 10px; border-radius: 7px;
  transition: color .12s, border-color .12s, background .12s;
}
.theme-btn:hover, .logout:hover { color: var(--text); border-color: var(--text-faint); }

.stats-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  padding: 12px; border-bottom: 1px solid var(--line);
}
.stat {
  background: var(--surface-2); border: 1.5px solid transparent; border-radius: 8px;
  padding: 9px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: border-color .12s, background .12s;
}
.stat:hover { background: var(--surface-3); }
.stat.is-active { border-color: var(--accent); background: var(--accent-soft); }
.stat-num { font-size: 17px; font-weight: 650; line-height: 1; }
.stat-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.stat.is-active .stat-num { color: var(--accent); }
.stat.is-active .stat-label { color: var(--accent); }

.search-wrap { padding: 12px 12px 4px; }
.search-wrap input {
  width: 100%; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 11px; font-size: 13px;
}
.search-wrap input:focus { border-color: var(--accent); outline: none; }

.filter-label {
  padding: 10px 16px 6px; font-size: 10px;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint);
}

.leads-list { flex: 1; overflow-y: auto; min-height: 0; }
.lead-item {
  padding: 11px 16px; border-bottom: 1px solid var(--line-soft);
  cursor: pointer; display: flex; flex-direction: column; gap: 4px;
  transition: background .1s;
}
.lead-item:hover { background: var(--surface-2); }
.lead-item.is-active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.lead-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lead-row-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.unread-badge {
  background: var(--accent); color: var(--accent-ink);
  font-size: 10px; font-weight: 700; min-width: 18px; height: 18px;
  border-radius: 99px; display: inline-flex; align-items: center; justify-content: center;
  padding: 0 5px;
}
.lead-name { font-size: 13.5px; font-weight: 550; }
.lead-time { font-size: 11.5px; color: var(--text-dim); }
.no-results { padding: 28px 16px; text-align: center; color: var(--text-faint); font-size: 12.5px; }

.badge {
  font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
}
.badge.new       { background: var(--new-bg);       color: var(--new-fg); }
.badge.contacted { background: var(--contacted-bg); color: var(--contacted-fg); }
.badge.closed    { background: var(--closed-bg);    color: var(--closed-fg); }

.detail { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.detail-empty { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.detail-empty[hidden] { display: none; }
.detail-empty-inner { text-align: center; color: var(--text-faint); max-width: 280px; }
.detail-empty-mark {
  display: block; width: 44px; height: 44px; margin: 0 auto 14px;
  border-radius: 12px; border: 2px dashed var(--line);
}
.detail-empty p { font-size: 13.5px; }

.detail-content { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.detail-content[hidden] { display: none; }

.detail-header {
  padding: 18px 22px 14px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 14px;
  flex-shrink: 0;
}
.detail-header-main { min-width: 0; }
.detail-header h2 { font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
.detail-header p { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; }
.detail-header-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.status-badge {
  font-size: 11px; font-weight: 600; padding: 4px 11px; border-radius: 99px;
  text-transform: uppercase; letter-spacing: .03em;
}
.status-badge.new       { background: var(--new-bg);       color: var(--new-fg); }
.status-badge.contacted { background: var(--contacted-bg); color: var(--contacted-fg); }
.status-badge.closed    { background: var(--closed-bg);    color: var(--closed-fg); }

.close-btn {
  background: none; border: 1px solid var(--line); color: var(--text-dim);
  font-size: 11.5px; padding: 5px 11px; border-radius: 7px;
  transition: color .12s, border-color .12s;
}
.close-btn:hover { color: var(--text); border-color: var(--text-faint); }

.phone-bar {
  padding: 11px 22px; border-bottom: 1px solid var(--line);
  background: var(--surface); flex-shrink: 0;
  display: flex; align-items: baseline; gap: 10px;
}
.phone { font-size: 14px; font-weight: 600; letter-spacing: .01em; }
.phone-label { font-size: 11px; color: var(--text-faint); }

.fields-disclosure { border-bottom: 1px solid var(--line); flex-shrink: 0; }
.fields-disclosure summary {
  list-style: none; cursor: pointer;
  padding: 11px 22px; font-size: 10px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-faint);
  display: flex; align-items: center; gap: 6px;
}
.fields-disclosure summary::-webkit-details-marker { display: none; }
.fields-disclosure summary::before {
  content: ""; width: 6px; height: 6px; border-right: 1.5px solid var(--text-faint);
  border-bottom: 1.5px solid var(--text-faint); transform: rotate(45deg);
  transition: transform .15s;
}
.fields-disclosure[open] summary::before { transform: rotate(-135deg); }
.fields {
  display: grid; grid-template-columns: 1fr 1fr; gap: 7px;
  padding: 2px 22px 16px;
}
.field {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: 8px; padding: 8px 11px;
}
.field.full { grid-column: 1 / -1; }
.field-label { font-size: 9.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); }
.field-value { font-size: 13.5px; font-weight: 550; margin-top: 2px; }

.convo {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: 18px 22px; display: flex; flex-direction: column; gap: 4px;
}
.convo-empty { margin: auto; text-align: center; color: var(--text-faint); font-size: 12.5px; max-width: 240px; }

.bubble-wrap { display: flex; flex-direction: column; max-width: 78%; margin-bottom: 8px; }
.bubble-wrap.out { align-self: flex-end; align-items: flex-end; }
.bubble-wrap.in  { align-self: flex-start; align-items: flex-start; }

.bubble-line { display: flex; align-items: flex-end; gap: 6px; }
.bubble {
  padding: 9px 13px; border-radius: 16px; font-size: 13.5px; line-height: 1.45;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.bubble-wrap.out .bubble {
  background: var(--bubble-out-bg); color: var(--bubble-out-fg);
  border-bottom-right-radius: 4px;
}
.bubble-wrap.in .bubble {
  background: var(--bubble-in-bg); color: var(--bubble-in-fg);
  border-bottom-left-radius: 4px;
}
.bubble-wrap.failed .bubble {
  background: var(--danger-bg); color: var(--danger);
  border: 1px solid var(--danger);
}

.fail-mark {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 16px; text-align: center;
  flex-shrink: 0; cursor: help;
}

.bubble-meta { font-size: 10.5px; color: var(--text-faint); margin-top: 3px; padding: 0 4px; display: flex; gap: 6px; align-items: center; }
.ticks { font-size: 11px; letter-spacing: -2px; color: var(--text-faint); }
.ticks.delivered { color: var(--accent); letter-spacing: -2px; }
.bubble-meta .retry {
  background: none; border: none; color: var(--accent); font-size: 10.5px;
  font-weight: 600; padding: 0; cursor: pointer; text-decoration: underline;
}
.fail-text { color: var(--danger); font-weight: 600; }

.compose {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 12px 18px; border-top: 1px solid var(--line);
  background: var(--surface); flex-shrink: 0;
}
.compose textarea {
  flex: 1; resize: none; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 20px;
  padding: 9px 15px; font-size: 13.5px; line-height: 1.4;
  max-height: 140px; min-height: 40px;
}
.compose textarea:focus { border-color: var(--accent); outline: none; }

#send-btn {
  background: var(--accent); color: var(--accent-ink); border: none;
  font-weight: 600; font-size: 13px; height: 40px; padding: 0 16px;
  border-radius: 20px; white-space: nowrap;
  display: flex; align-items: center; gap: 7px;
  transition: background .12s;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: .55; cursor: default; }
.send-icon {
  width: 14px; height: 14px; flex-shrink: 0;
  background: currentColor;
  -webkit-mask: var(--send-svg) center / contain no-repeat;
          mask: var(--send-svg) center / contain no-repeat;
}
:root { --send-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 11l18-8-8 18-2-7-8-3z'/%3E%3C/svg%3E"); }

.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: radial-gradient(900px 500px at 50% -10%, var(--login-glow) 0%, transparent 70%), var(--bg);
}
.login-card {
  width: 100%; max-width: 340px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 32px 28px; box-shadow: var(--shadow);
}
.login-mark {
  width: 42px; height: 42px; border-radius: 11px;
  background: linear-gradient(150deg, var(--accent), var(--accent-hover));
  margin-bottom: 18px;
}
.login-card h1 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.login-sub { color: var(--text-dim); font-size: 13px; margin-top: 4px; margin-bottom: 22px; }
.login-card label {
  display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-faint); margin-bottom: 6px; margin-top: 14px;
}
.login-card input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; font-size: 14px;
}
.login-card input:focus { border-color: var(--accent); outline: none; }
#login-btn {
  width: 100%; margin-top: 22px; background: var(--accent); color: var(--accent-ink);
  border: none; font-weight: 650; font-size: 14px; padding: 11px; border-radius: 8px;
  transition: background .12s;
}
#login-btn:hover { background: var(--accent-hover); }
#login-btn:disabled { opacity: .6; cursor: default; }
.login-error { margin-top: 14px; font-size: 12.5px; color: var(--danger); text-align: center; }

@media (max-width: 760px) {
  .app { flex-direction: column; height: 100dvh; }
  .sidebar { width: 100%; height: 44%; border-right: none; border-bottom: 1px solid var(--line); }
  .detail { height: 56%; }
  .fields { grid-template-columns: 1fr; }
  .send-label { display: none; }
  #send-btn { padding: 0 13px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
