/* ====================================================
   ClientRig App UI — matches landing page design system
   Uses the same CSS variables defined in theme.css
   ==================================================== */

/* Nav */
.app-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.nav-logo {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
  color: var(--fg);
  text-decoration: none;
}

.nav-logo span { color: var(--accent); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--fg-muted);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover { color: var(--fg); background: var(--bg-card); }
.nav-link.active { color: var(--accent); background: var(--accent-dim); }

.nav-biz {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-dim);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* App shell */
.app-body {
  min-height: calc(100vh - 56px);
  background: var(--bg);
}

.app-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* Page header */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 32px;
  gap: 16px;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--fg-muted);
  margin-top: 4px;
}

/* Stat cards */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  padding: 20px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.2s;
}

.stat-card:hover { border-color: var(--fg-dim); }

.stat-card-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-dim);
  margin-bottom: 8px;
}

.stat-card-value {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--fg);
  line-height: 1;
}

.stat-card-value.accent { color: var(--accent); }
.stat-card-value.warning { color: #f59e0b; }
.stat-card-value.danger { color: #ef4444; }

/* Layout: list + detail panel */
.dash-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  align-items: start;
}

/* Lead list */
.leads-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--fg);
}

.filter-tabs {
  display: flex;
  gap: 4px;
}

.filter-tab {
  padding: 4px 10px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--fg-muted);
  background: transparent;
  transition: all 0.15s;
}

.filter-tab:hover { color: var(--fg); border-color: var(--border); }
.filter-tab.active { color: var(--accent); background: var(--accent-dim); border-color: var(--accent); }

.lead-list { max-height: calc(100vh - 280px); overflow-y: auto; }

.lead-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  color: inherit;
}

.lead-item:last-child { border-bottom: none; }
.lead-item:hover { background: var(--bg-elevated); }
.lead-item.selected { background: var(--accent-dim); border-left: 2px solid var(--accent); }

.lead-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.lead-info { flex: 1; min-width: 0; }

.lead-phone {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lead-preview {
  font-size: 0.75rem;
  color: var(--fg-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lead-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.lead-time {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-dim);
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.badge-new        { background: rgba(0,229,160,0.12); color: #00e5a0; }
.badge-contacted  { background: rgba(99,102,241,0.12); color: #818cf8; }
.badge-qualified  { background: rgba(245,158,11,0.12); color: #fbbf24; }
.badge-booked     { background: rgba(16,185,129,0.12); color: #34d399; }
.badge-closed     { background: rgba(107,114,128,0.12); color: #9ca3af; }
.badge-lost       { background: rgba(239,68,68,0.12); color: #f87171; }

/* Detail panel */
.detail-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  position: sticky;
  top: 80px;
}

.detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  color: var(--fg-dim);
  text-align: center;
}

.detail-empty-icon {
  font-size: 2rem;
  margin-bottom: 16px;
  opacity: 0.4;
}

.detail-empty p {
  font-size: 0.875rem;
  font-family: var(--font-mono);
}

.detail-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.detail-phone {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 8px;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.status-select {
  appearance: none;
  padding: 6px 28px 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238b8b96'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.15s;
}

.status-select:focus { outline: none; border-color: var(--accent); }

/* Message thread */
.message-thread {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 340px;
  overflow-y: auto;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}

.msg.outbound { align-self: flex-end; align-items: flex-end; }
.msg.inbound  { align-self: flex-start; align-items: flex-start; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
}

.msg.outbound .msg-bubble {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--fg);
  border-radius: 12px 12px 2px 12px;
}

.msg.inbound .msg-bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 12px 12px 12px 2px;
}

.msg-time {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--fg-dim);
  margin-top: 4px;
}

/* Reply box */
.reply-box {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.reply-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.reply-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-family: var(--font-display);
  font-size: 0.875rem;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  transition: border-color 0.15s;
}

.reply-input:focus { outline: none; border-color: var(--accent); }
.reply-input::placeholder { color: var(--fg-dim); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #000;
}
.btn-primary:hover { background: #00c98d; }

.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--fg); border-color: var(--fg-dim); }

.btn-sm { padding: 6px 12px; font-size: 10px; }

/* Notes section */
.notes-section {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

.notes-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-dim);
  margin-bottom: 8px;
}

.notes-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  font-family: var(--font-display);
  font-size: 0.875rem;
  resize: none;
  min-height: 72px;
  transition: border-color 0.15s;
}

.notes-input:focus { outline: none; border-color: var(--accent); }
.notes-input::placeholder { color: var(--fg-dim); }

/* Setup / Onboarding */
.setup-wrap {
  max-width: 560px;
  margin: 64px auto;
  padding: 0 24px;
}

.setup-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
}

.setup-logo {
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
  margin-bottom: 32px;
}

.setup-logo span { color: var(--accent); }

.setup-card h1 {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.setup-card p {
  font-size: 0.875rem;
  color: var(--fg-muted);
  margin-bottom: 32px;
  line-height: 1.6;
}

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-muted);
  margin-bottom: 8px;
}

.form-input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--fg);
  font-family: var(--font-display);
  font-size: 0.9rem;
  transition: border-color 0.15s;
}

.form-input:focus { outline: none; border-color: var(--accent); }
.form-input::placeholder { color: var(--fg-dim); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.form-hint {
  font-size: 0.75rem;
  color: var(--fg-dim);
  margin-top: 6px;
  line-height: 1.4;
}

.form-textarea {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--fg);
  font-family: var(--font-display);
  font-size: 0.9rem;
  resize: none;
  min-height: 80px;
  transition: border-color 0.15s;
}

.form-textarea:focus { outline: none; border-color: var(--accent); }
.form-textarea::placeholder { color: var(--fg-dim); }

.setup-submit {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
}

.setup-submit:hover { background: #00c98d; }
.setup-submit:disabled { opacity: 0.5; cursor: not-allowed; }

/* Webhook info box */
.info-box {
  padding: 16px 20px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 8px;
  margin-top: 24px;
}

.info-box-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 6px;
}

.info-box-url {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--fg);
  word-break: break-all;
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--fg);
  z-index: 1000;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: var(--accent); color: var(--accent); }
.toast.error { border-color: #ef4444; color: #ef4444; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--fg-dim);
}

.empty-state-icon { font-size: 2.5rem; margin-bottom: 16px; opacity: 0.3; }
.empty-state h3 { font-size: 1rem; font-weight: 500; color: var(--fg-muted); margin-bottom: 8px; }
.empty-state p { font-size: 0.875rem; }

/* Responsive */
@media (max-width: 900px) {
  .dash-layout { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .detail-panel { position: static; }
  .lead-list { max-height: 320px; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .app-inner { padding: 20px 16px; }
}
