/* Pingdesk — dark SaaS dashboard. Original design. */

:root {
  --bg: #0b0f14;
  --panel: #111821;
  --panel-2: #16202b;
  --panel-3: #1b2632;
  --border: #22303f;
  --border-soft: #1b2632;
  --text: #e9eef5;
  --muted: #8fa0b5;
  --muted-2: #66788e;
  --accent: #2dd4bf;
  --accent-strong: #5eead4;
  --accent-dim: rgba(45, 212, 191, 0.12);
  --accent-border: rgba(45, 212, 191, 0.35);
  --danger: #f87171;
  --danger-dim: rgba(248, 113, 113, 0.12);
  --warn: #fbbf24;
  --info: #60a5fa;
  --ok: #34d399;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #0ea5e9);
  color: #06251f;
}
.logo-name { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.nav { display: flex; flex-direction: column; gap: 4px; padding: 16px 12px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--accent-dim); color: var(--accent-strong); }
.nav a.active svg { color: var(--accent); }
.sidebar-foot {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border-soft);
  color: var(--muted-2);
  font-size: 12px;
}
.api-dot { display: flex; align-items: center; gap: 8px; }
.api-dot span:first-child {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn);
}
.api-dot.ok span:first-child { background: var(--ok); }
.api-dot.bad span:first-child { background: var(--danger); }

.main { flex: 1; min-width: 0; padding: 28px 32px 48px; max-width: 1240px; }

/* ---------- Page headers ---------- */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #06251f;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--panel-2); filter: none; }
.btn-danger {
  background: var(--danger-dim);
  border-color: rgba(248, 113, 113, 0.35);
  color: var(--danger);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.2); filter: none; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
select { appearance: none; cursor: pointer; }
textarea { resize: vertical; min-height: 90px; }
label.field { display: block; margin-bottom: 16px; }
label.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
label.field > span em { font-style: normal; font-weight: 400; color: var(--muted-2); }

/* toggle switch */
.toggle-row { display: flex; align-items: center; gap: 12px; }
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .track {
  position: absolute; inset: 0;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.2s;
  cursor: pointer;
}
.toggle .track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.2s, background 0.2s;
}
.toggle input:checked + .track { background: var(--accent-dim); border-color: var(--accent-border); }
.toggle input:checked + .track::after { transform: translateX(20px); background: var(--accent); }

/* ---------- Cards / panels ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.15s, transform 0.1s;
}
.card:hover { border-color: var(--border); }
.card-click { cursor: pointer; text-decoration: none; color: inherit; display: block; }
.card-click:hover { transform: translateY(-2px); border-color: var(--accent-border); }
.card h3 { margin: 0 0 4px; font-size: 16px; letter-spacing: -0.01em; }
.card .sub { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.card .meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; font-size: 13px; color: var(--muted); }
.card .desc {
  color: var(--muted);
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 8px 0 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 24px;
}
.panel + .panel { margin-top: 16px; }
.panel h2 { margin: 0 0 16px; font-size: 16px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
}
.pill.active, .pill.open, .pill.done { background: rgba(52, 211, 153, 0.12); color: var(--ok); border-color: rgba(52, 211, 153, 0.3); }
.pill.inactive, .pill.closed { background: rgba(143, 160, 181, 0.12); color: var(--muted); border-color: rgba(143, 160, 181, 0.3); }
.pill.pending, .pill.sending { background: rgba(251, 191, 36, 0.12); color: var(--warn); border-color: rgba(251, 191, 36, 0.3); }
.pill.draft { background: rgba(143, 160, 181, 0.12); color: var(--muted); border-color: rgba(143, 160, 181, 0.3); }
.pill.failed { background: var(--danger-dim); color: var(--danger); border-color: rgba(248, 113, 113, 0.3); }
.pill .pulse { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- States ---------- */
.state {
  text-align: center;
  padding: 56px 24px;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.state h3 { color: var(--text); margin: 0 0 8px; font-size: 16px; }
.state p { margin: 0 0 16px; font-size: 13px; }
.state .big { font-size: 40px; margin-bottom: 12px; }
.error-box {
  background: var(--danger-dim);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fca5a5;
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}
.error-box p { margin: 0 0 10px; }
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--panel-2) 25%, var(--panel-3) 50%, var(--panel-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.loading-list .skeleton { height: 76px; margin-bottom: 12px; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
  max-width: 340px;
}
.toast {
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: slidein 0.25s ease;
}
.toast.error { border-left-color: var(--danger); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Inbox ---------- */
.inbox { display: flex; gap: 16px; height: calc(100vh - 170px); min-height: 520px; }
.inbox-list {
  width: 340px;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.inbox-filters { padding: 14px; border-bottom: 1px solid var(--border-soft); display: flex; flex-direction: column; gap: 10px; }
.inbox-filters .row { display: flex; gap: 8px; }
.inbox-filters select { flex: 1; }
.conv-rows { overflow-y: auto; flex: 1; }
.conv-row {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border-soft);
  padding: 14px 16px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: background 0.12s;
}
.conv-row:hover { background: var(--panel-2); }
.conv-row.selected { background: var(--accent-dim); box-shadow: inset 3px 0 0 var(--accent); }
.conv-row .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.conv-row .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-row .time { font-size: 12px; color: var(--muted-2); flex-shrink: 0; }
.conv-row .phone { font-size: 12px; color: var(--muted-2); margin-bottom: 4px; }
.conv-row .preview {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 8px;
}
.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #06251f;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.status-dot.open { background: var(--ok); }
.status-dot.pending { background: var(--warn); }
.status-dot.closed { background: var(--muted-2); }

.thread {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.thread-head { padding: 14px 18px; border-bottom: 1px solid var(--border-soft); }
.thread-head .who { display: flex; align-items: center; gap: 10px; }
.thread-head .who h2 { margin: 0; font-size: 16px; }
.thread-head .who .phone { color: var(--muted-2); font-size: 13px; }
.thread-meta {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--panel-2);
  flex-wrap: wrap;
}
.thread-meta .field { flex: 1 1 140px; margin: 0; }
.thread-meta .field.note { flex: 2 1 220px; }
.thread-meta .field > span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.messages { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; }
.msg.in { justify-content: flex-start; }
.msg.out { justify-content: flex-end; }
.bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.in .bubble { background: var(--panel-3); border: 1px solid var(--border-soft); border-bottom-left-radius: 4px; }
.msg.out .bubble { background: var(--accent-dim); border: 1px solid var(--accent-border); border-bottom-right-radius: 4px; }
.bubble .meta-line { display: block; font-size: 11px; color: var(--muted-2); margin-top: 6px; text-align: right; }
.composer { padding: 14px 18px; border-top: 1px solid var(--border-soft); display: flex; gap: 10px; }
.composer textarea { min-height: 44px; max-height: 140px; }
.thread-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted-2); }

/* ---------- Broadcasts ---------- */
.progress { height: 6px; background: var(--panel-3); border-radius: 999px; overflow: hidden; margin-top: 12px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s; }
.contact-pick {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 6px;
}
.contact-pick label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.contact-pick label:hover { background: var(--panel-2); }
.contact-pick input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.contact-pick .phone { color: var(--muted-2); margin-left: auto; font-family: var(--mono); font-size: 12px; }
.pick-tools { display: flex; gap: 12px; margin-bottom: 8px; font-size: 13px; }
.pick-tools button { background: none; border: none; color: var(--accent-strong); cursor: pointer; font: inherit; padding: 0; }
.pick-tools button:hover { text-decoration: underline; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; background: var(--panel-2); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
td .mono { font-family: var(--mono); font-size: 13px; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  margin: 1px 4px 1px 0;
  border-radius: 999px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 7, 11, 0.7);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: var(--shadow);
  animation: slidein 0.2s ease;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 { margin: 0; font-size: 17px; }

.badge-count {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .sidebar { width: 72px; }
  .logo-name, .nav a span, .sidebar-foot { display: none; }
  .logo { justify-content: center; padding: 16px 8px; }
  .nav a { justify-content: center; }
  .inbox { flex-direction: column; height: auto; }
  .inbox-list { width: 100%; max-height: 420px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Auth / login ---------- */
.login-wrap {
  min-height: calc(100vh - 220px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 400px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
.login-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.login-card .btn[type="submit"] { width: 100%; }

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 0;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}
.sidebar-user .who { min-width: 0; flex: 1; }
.sidebar-user strong {
  display: block;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user .biz {
  display: block;
  font-size: 12px;
  color: var(--muted-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav a[hidden], #sidebarUser[hidden] { display: none; }

/* ---------- Fieldsets (agent builder) ---------- */
.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 16px 2px;
  margin: 0 0 16px;
}
.fieldset legend {
  padding: 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.fieldset .field:last-child { margin-bottom: 14px; }

input[type="range"] {
  width: 100%;
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--accent);
}
input[type="range"]:focus { box-shadow: none; border: none; }

.hint { color: var(--muted-2); font-size: 13px; margin: 0 0 12px; }
.num-add {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 0 10px;
  align-items: end;
  margin-top: 4px;
}
.num-add .field { margin-bottom: 14px; }

/* Brain usage card (Users view) */
.muted { color: var(--muted-2); font-size: 13px; margin: 0 0 8px; }
.usage-num { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; }
.usage-num span { font-size: 15px; font-weight: 400; color: var(--muted-2); }
#usagePanel { margin-bottom: 16px; }

/* ---------- Setup Assistant ---------- */
.setup-wrap { display: flex; flex-direction: column; height: calc(100vh - 235px); min-height: 420px; }
.setup-wrap .thread { flex: 1; }
.action-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.action-chip {
  font-size: 11px; font-weight: 700; line-height: 1;
  padding: 5px 9px; border-radius: 999px;
  background: var(--panel-3); color: var(--ok);
  border: 1px solid var(--ok);
}
.bubble.typing { display: inline-flex; gap: 5px; align-items: center; padding: 14px 16px; }
.bubble.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); animation: setup-blink 1.2s infinite; }
.bubble.typing span:nth-child(2) { animation-delay: 0.2s; }
.bubble.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes setup-blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* Bookings + Integrations */
.notice {
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.3);
  color: var(--warn);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 14px;
}
.btn-row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.check { display: flex !important; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: auto; }
.hint { color: var(--muted); font-size: 13px; }
.hint b { font-family: var(--mono); }
