/* CSR Live Call Console - calm operations console
   Display: Bricolage Grotesque | Body: IBM Plex Sans | Data: IBM Plex Mono */

:root {
  /* ink + neutrals (cool slate) */
  --ink: #14181f;
  --ink-soft: #2b3340;
  --muted: #64748b;
  --muted-soft: #94a3b8;
  --line: #e3e8ef;
  --line-soft: #eef2f6;
  --bg: #eceff4;
  --surface: #ffffff;
  --surface-2: #f7f9fc;

  /* brand: teal */
  --brand: #0d9488;
  --brand-deep: #0f766e;
  --brand-tint: #e6f5f3;

  /* semantic */
  --ok: #047857;
  --ok-tint: #e9f7f0;
  --ok-line: #a7e3c6;
  --warn: #b45309;
  --warn-tint: #fdf3e7;
  --warn-line: #f3d6a8;
  --danger: #be123c;
  --danger-tint: #fdeaef;
  --danger-line: #f4b8c6;

  /* shape + depth */
  --r-sm: 5px;
  --r: 8px;
  --r-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 31, 0.05), 0 1px 1px rgba(20, 24, 31, 0.04);
  --shadow: 0 2px 6px rgba(20, 24, 31, 0.06), 0 4px 14px rgba(20, 24, 31, 0.05);
  --shadow-lg: 0 10px 40px rgba(20, 24, 31, 0.18);

  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.015em; color: var(--ink); }

a { color: var(--brand-deep); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--ink);
  color: #fff;
  padding: 0.7rem 1.4rem;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 1px 0 rgba(255,255,255,0.06) inset, var(--shadow-sm);
}
.topbar .brand {
  font-family: var(--font-display);
  font-weight: 700; font-size: 1.05rem; letter-spacing: -0.02em;
  display: flex; align-items: center; gap: 0.55rem;
}
.topbar .brand::before {
  content: ""; width: 9px; height: 9px; border-radius: 2px;
  background: var(--brand); box-shadow: 0 0 0 3px rgba(13,148,136,0.25);
}
.topbar .user { display: flex; gap: 1.1rem; align-items: center; }
.topbar .user > span { font-size: 0.85rem; color: #cbd5e1; }
.topbar .navlink {
  color: #e2e8f0; text-decoration: none; font-size: 0.85rem; font-weight: 500;
  padding: 0.3rem 0; border-bottom: 2px solid transparent; transition: border-color .15s, color .15s;
}
.topbar .navlink:hover { color: #fff; border-bottom-color: var(--brand); }
.topbar .logout-form { display: inline; margin: 0; }
.topbar .logout-form button {
  background: transparent; border: 1px solid rgba(255,255,255,0.25); color: #e2e8f0;
  padding: 0.28rem 0.8rem; border-radius: var(--r-sm); cursor: pointer; font-size: 0.8rem;
  font-family: var(--font-body); transition: background .15s, border-color .15s;
}
.topbar .logout-form button:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.5); }

.main { padding: 1.6rem; max-width: 1180px; margin: 0 auto; }

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-mini {
  font-family: var(--font-body); font-weight: 600; cursor: pointer;
  border-radius: var(--r-sm); text-decoration: none; text-align: center;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
.btn-primary { background: var(--brand); color: #fff; border: 1px solid var(--brand); padding: 0.55rem 0.95rem; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-deep); border-color: var(--brand-deep); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary { background: var(--surface); color: var(--ink-soft); border: 1px solid var(--line); padding: 0.55rem 0.95rem; }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--muted-soft); }
.btn-mini { padding: 0.3rem 0.65rem; font-size: 0.78rem; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-soft); }
.btn-mini:hover { background: #fff; border-color: var(--muted-soft); }

input, select, textarea { font-family: var(--font-body); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* ---------- Login ---------- */
.login-card {
  background: var(--surface);
  padding: 2.2rem;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  max-width: 380px; margin: 5rem auto;
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.login-card h1 { margin: 0 0 1.2rem; font-size: 1.5rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.82rem; color: var(--muted); font-weight: 500; }
.login-form input {
  padding: 0.65rem 0.8rem; font-size: 1rem; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--surface-2); transition: border-color .15s, background .15s;
}
.login-form input:focus { outline: none; border-color: var(--brand); background: #fff; }
.login-form button { padding: 0.7rem 1rem; background: var(--brand); color: #fff; border: none; border-radius: var(--r-sm); font-size: 1rem; font-weight: 600; cursor: pointer; box-shadow: var(--shadow-sm); }
.login-form button:hover { background: var(--brand-deep); }

.error {
  background: var(--danger-tint); border: 1px solid var(--danger-line); color: var(--danger);
  padding: 0.55rem 0.8rem; border-radius: var(--r-sm); font-size: 0.88rem;
}

/* ---------- Queue / Console ---------- */
.queue-header { display: flex; align-items: baseline; gap: 0.8rem; margin-bottom: 1.1rem; }
.queue-header h1 { margin: 0; font-size: 1.55rem; }
.queue-refresh-hint { color: var(--muted); font-size: 0.8rem; }
.queue-refresh-hint::before { content: "\25CF"; color: var(--brand); font-size: 0.7em; margin-right: 0.35rem; }
.loading, .empty { color: var(--muted); font-style: italic; padding: 1.4rem 0; }

.lead-row {
  display: grid; grid-template-columns: 1fr auto; gap: 1.2rem;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--line); border-radius: var(--r);
  margin-bottom: 0.65rem; background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, border-color .15s;
}
.lead-row:hover { box-shadow: var(--shadow); }
.lead-row.locked-by-me {
  background: linear-gradient(0deg, var(--warn-tint), var(--surface));
  border-color: var(--warn-line);
  box-shadow: 0 0 0 1px var(--warn-line), var(--shadow-sm);
}

.lead-name { display: flex; align-items: baseline; gap: 0.7rem; margin-bottom: 0.4rem; flex-wrap: wrap; }
.lead-name strong { font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; }
.lead-no { font-family: var(--font-mono); color: var(--muted); font-size: 0.8rem; }
.lead-fields { display: flex; gap: 1.4rem; flex-wrap: wrap; font-size: 0.88rem; color: var(--ink-soft); }
.lead-fields .field b { color: var(--muted); font-weight: 500; }
.lead-fields .field { font-variant-numeric: tabular-nums; }
.lead-address { color: var(--ink-soft); font-size: 0.88rem; margin: 0.35rem 0; }
.lead-stats { display: flex; gap: 1.1rem; font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); margin-top: 0.35rem; }

.lead-actions { display: flex; flex-direction: column; gap: 0.45rem; align-items: stretch; min-width: 190px; }
.lead-actions a, .lead-actions button { font-size: 0.88rem; }

.lock-indicator-mine {
  background: var(--warn); color: #fff; padding: 0.32rem 0.65rem;
  border-radius: var(--r-sm); font-size: 0.82rem; font-weight: 600; text-align: center;
}
.stale { background: var(--danger); color: #fff; padding: 1px 6px; border-radius: 3px; font-size: 0.7rem; font-weight: 600; margin-left: 0.35rem; letter-spacing: 0.04em; }
.dup-badge { background: var(--warn-tint); color: var(--warn); border: 1px solid var(--warn-line); padding: 1px 6px; border-radius: 3px; font-size: 0.68rem; font-weight: 600; margin-left: 0.35rem; letter-spacing: 0.04em; }
.voicemail-prompt {
  grid-column: 1 / -1; background: var(--brand-tint); border: 1px solid #b6e1db; color: var(--brand-deep);
  padding: 0.5rem 0.75rem; border-radius: var(--r-sm); font-size: 0.85rem; margin-bottom: 0.5rem;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 24, 31, 0.55); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
  animation: fade .15s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-content {
  background: var(--surface); padding: 1.6rem; border-radius: var(--r-lg);
  width: min(480px, 92vw); box-shadow: var(--shadow-lg);
  animation: rise .25s cubic-bezier(.2,.7,.2,1) both;
}
.modal-content h2 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.modal-subtitle { margin: 0 0 1rem; color: var(--muted); font-size: 0.88rem; }
.modal-subtitle strong { color: var(--ink); }
.modal-content form { display: flex; flex-direction: column; gap: 0.85rem; }
.modal-content .field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.82rem; color: var(--muted); font-weight: 500; }
.modal-content select, .modal-content input[type=datetime-local], .modal-content textarea {
  padding: 0.55rem 0.65rem; border: 1px solid var(--line); border-radius: var(--r-sm);
  font-size: 0.95rem; font-family: inherit; background: var(--surface-2); color: var(--ink);
}
.modal-content select:focus, .modal-content textarea:focus, .modal-content input:focus { outline: none; border-color: var(--brand); background: #fff; }
.modal-content .confirm-row { display: flex; gap: 0.5rem; align-items: center; font-size: 0.9rem; color: var(--ink-soft); }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.4rem; }
#modal-error .error { margin-top: 0.2rem; }

/* lead history in modal */
.lead-history { margin-bottom: 0.8rem; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); }
.lead-history summary { padding: 0.5rem 0.7rem; cursor: pointer; font-size: 0.82rem; font-weight: 600; color: var(--ink-soft); }
.history-list { list-style: none; margin: 0; padding: 0 0.7rem 0.5rem; max-height: 200px; overflow-y: auto; }
.history-item { padding: 0.45rem 0; border-top: 1px solid var(--line-soft); }
.history-head { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.history-disp { font-weight: 600; font-size: 0.85rem; }
.history-meta { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.history-notes { font-size: 0.85rem; color: var(--ink-soft); margin-top: 0.2rem; font-style: italic; }
.history-cb { font-family: var(--font-mono); font-size: 0.72rem; color: var(--warn); margin-top: 0.15rem; }

/* ---------- Dashboard ---------- */
.dash-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.1rem; }
.dash-header h1 { margin: 0; font-size: 1.55rem; }
.dash-filters {
  display: flex; gap: 1rem; align-items: end; background: var(--surface);
  padding: 0.9rem 1.1rem; border-radius: var(--r); margin-bottom: 1rem;
  border: 1px solid var(--line); box-shadow: var(--shadow-sm); flex-wrap: wrap;
}
.dash-filters label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.78rem; color: var(--muted); font-weight: 500; }
.dash-filters select, .dash-filters input { padding: 0.45rem 0.6rem; font-size: 0.92rem; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); }
.dash-range-label { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.9rem; }
.dash-range-label strong { color: var(--ink); }
.dash-section { background: var(--surface); padding: 1.3rem; border-radius: var(--r); margin-bottom: 1rem; border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.dash-section h2 { margin: 0 0 0.9rem; font-size: 1.05rem; display: flex; align-items: center; }

.kpi-grid { display: grid; gap: 0.7rem; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); }
.kpi { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0.75rem 0.85rem; display: flex; flex-direction: column; gap: 0.25rem; }
.kpi-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.kpi-value { font-family: var(--font-mono); font-size: 1.45rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 0.75rem; color: var(--muted); font-weight: 400; }
.kpi-good { background: var(--ok-tint); border-color: var(--ok-line); }
.kpi-good .kpi-value { color: var(--ok); }
.kpi-warn { background: var(--warn-tint); border-color: var(--warn-line); }
.kpi-warn .kpi-value { color: var(--warn); }
.kpi-bad { background: var(--danger-tint); border-color: var(--danger-line); }
.kpi-bad .kpi-value { color: var(--danger); }

.dash-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.dash-table th, .dash-table td { text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--line-soft); }
.dash-table th { background: var(--surface-2); font-weight: 600; color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }
.dash-table td { font-variant-numeric: tabular-nums; }
.dash-table tbody tr:hover { background: var(--surface-2); }

.health-runs { margin-top: 0.8rem; font-size: 0.9rem; }
.health-runs ul { margin: 0.3rem 0; padding-left: 1.2rem; }
.health-runs li { font-family: var(--font-mono); font-size: 0.82rem; }
.last-poll { color: var(--muted); font-family: var(--font-mono); font-size: 0.78rem; margin: 0.5rem 0 0; }

/* ---------- Live agents ---------- */
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-left: 0.45rem; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; box-shadow: 0 0 0 0 rgba(4,120,87,0.4); } 50% { opacity: 0.5; box-shadow: 0 0 0 5px rgba(4,120,87,0); } }
.agent-grid { display: grid; gap: 0.7rem; grid-template-columns: repeat(auto-fill, minmax(245px, 1fr)); }
.agent-card { border: 1px solid var(--line); border-radius: var(--r); padding: 0.85rem; background: var(--surface-2); border-left: 4px solid var(--line); }
.agent-online { border-left-color: var(--ok); background: linear-gradient(90deg, var(--ok-tint), var(--surface-2) 40%); }
.agent-offline { border-left-color: var(--muted-soft); }
.agent-disabled { border-left-color: var(--danger); opacity: 0.6; }
.agent-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.45rem; }
.agent-name { font-family: var(--font-display); font-weight: 600; }
.agent-status { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.agent-status.on { background: var(--ok-tint); color: var(--ok); }
.agent-status.off { background: #eef2f6; color: var(--muted); }
.agent-working { font-size: 0.88rem; color: var(--ink); }
.agent-working strong { font-weight: 600; }
.agent-held { color: var(--muted); font-family: var(--font-mono); font-size: 0.76rem; }
.agent-idle { font-size: 0.85rem; color: var(--muted-soft); font-style: italic; }
.agent-foot { display: flex; justify-content: space-between; gap: 0.5rem; margin-top: 0.55rem; font-size: 0.76rem; color: var(--muted); flex-wrap: wrap; }
.agent-foot span:first-child { font-family: var(--font-mono); }
.agent-last { color: var(--ink-soft); }

/* ---------- Admin users ---------- */
.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.1rem; }
.admin-header h1 { margin: 0; font-size: 1.55rem; }
.admin-create { background: var(--surface); padding: 1.1rem 1.2rem; border-radius: var(--r); border: 1px solid var(--line); margin-bottom: 1rem; box-shadow: var(--shadow-sm); }
.admin-create h2 { margin: 0 0 0.75rem; font-size: 1rem; }
.create-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.create-form input, .create-form select { padding: 0.5rem 0.6rem; border: 1px solid var(--line); border-radius: var(--r-sm); font-size: 0.9rem; background: var(--surface-2); }
.create-form input:focus, .create-form select:focus { outline: none; border-color: var(--brand); background: #fff; }
.create-form input[name=username] { width: 140px; }
.create-form input[name=full_name] { width: 160px; }
.create-form input[name=password] { width: 160px; }

.admin-msg { padding: 0.55rem 0.8rem; border-radius: var(--r-sm); margin-bottom: 0.8rem; font-size: 0.88rem; }
.admin-msg.ok { background: var(--ok-tint); border: 1px solid var(--ok-line); color: var(--ok); }
.admin-msg.err { background: var(--danger-tint); border: 1px solid var(--danger-line); color: var(--danger); }

.admin-table .inline-form { display: inline-flex; gap: 0.3rem; align-items: center; margin: 0; }
.admin-table select, .admin-table input[type=password] { padding: 0.32rem 0.45rem; border: 1px solid var(--line); border-radius: var(--r-sm); font-size: 0.85rem; background: var(--surface-2); }
.admin-table input[type=password] { width: 120px; }
.row-inactive { opacity: 0.5; }
.status-active { color: var(--ok); font-weight: 600; font-size: 0.82rem; }
.status-inactive { color: var(--danger); font-weight: 600; font-size: 0.82rem; }
.you-badge { background: var(--brand); color: #fff; padding: 1px 7px; border-radius: 10px; font-size: 0.68rem; font-weight: 600; }
