/* ================================================================
   Simulator Studio — design system
   ================================================================ */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-3: #e9ecf1;
  --border: #e3e7ed;
  --border-strong: #cfd5de;
  --text: #0f1728;
  --text-2: #344054;
  --muted: #667085;
  --faint: #98a2b3;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --primary-text: #ffffff;

  --wa: #00a884;
  --wa-soft: #e3f7f1;
  --sqs: #e8830c;
  --sqs-soft: #fdf1e2;

  --success: #079455;
  --success-soft: #e5f6ee;
  --warn: #dc6803;
  --warn-soft: #fef3e6;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --info: #1570ef;
  --info-soft: #e8f1fe;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px -2px rgba(16, 24, 40, 0.08), 0 2px 4px -2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 20px 40px -12px rgba(16, 24, 40, 0.22);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --topbar-h: 56px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0e14;
    --surface: #121620;
    --surface-2: #181d29;
    --surface-3: #212736;
    --border: #252c3b;
    --border-strong: #343d50;
    --text: #e8ebf1;
    --text-2: #c5cbd6;
    --muted: #8d97a9;
    --faint: #667085;
    --primary: #7c74ff;
    --primary-hover: #8f88ff;
    --primary-soft: #232155;
    --wa-soft: #0d2e27;
    --sqs-soft: #33230d;
    --success-soft: #0e2a1d;
    --warn-soft: #33220d;
    --danger-soft: #3a1512;
    --info-soft: #102340;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 14px -2px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b0e14;
  --surface: #121620;
  --surface-2: #181d29;
  --surface-3: #212736;
  --border: #252c3b;
  --border-strong: #343d50;
  --text: #e8ebf1;
  --text-2: #c5cbd6;
  --muted: #8d97a9;
  --faint: #667085;
  --primary: #7c74ff;
  --primary-hover: #8f88ff;
  --primary-soft: #232155;
  --wa-soft: #0d2e27;
  --sqs-soft: #33230d;
  --success-soft: #0e2a1d;
  --warn-soft: #33220d;
  --danger-soft: #3a1512;
  --info-soft: #102340;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
p { margin: 0; }

code, .mono { font-family: var(--mono); font-size: 12.5px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ─── Icons ───────────────────────────────────────────── */
.icon { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 22px; height: 22px; }

/* ─── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-weight: 550; font-size: 13.5px;
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  user-select: none;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: var(--primary-text); box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.93); }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover:not(:disabled) { filter: brightness(0.97); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-lg { height: 42px; padding: 0 18px; font-size: 14.5px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Forms ───────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 11px;
  font: inherit; font-size: 13.5px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea { height: auto; min-height: 90px; padding: 9px 11px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input-lg { height: 42px; font-size: 14.5px; }

.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 20px; cursor: pointer; transition: background 0.2s; }
.switch span::before { content: ''; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: var(--shadow-sm); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ─── Badges / pills ──────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2);
}
.badge-wa { background: var(--wa-soft); color: var(--wa); }
.badge-sqs { background: var(--sqs-soft); color: var(--sqs); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex-shrink: 0; }
.dot.live { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.dot.down { background: var(--danger); }

/* ─── Cards / panels ──────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.panel-title { font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

.kv { display: flex; flex-direction: column; gap: 4px; }
.kv-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.copy-field {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 6px 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); font-family: var(--mono); font-size: 12px; color: var(--text);
}
.copy-field span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.code-block {
  margin: 0; padding: 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 12px; line-height: 1.55; color: var(--text);
  white-space: pre-wrap; word-break: break-word; overflow: auto; max-height: 420px;
}

.divider { height: 1px; background: var(--border); border: none; margin: 4px 0; }

/* ─── Topbar ──────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h); padding: 0 16px;
  display: flex; align-items: center; gap: 14px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #9b5cf6); color: #fff;
  box-shadow: 0 4px 10px -2px color-mix(in srgb, var(--primary) 50%, transparent);
}
.brand-mark .icon { width: 17px; height: 17px; }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--muted); font-size: 13.5px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); text-decoration: none; }
.crumbs .sep { color: var(--faint); }
.crumbs .current { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.user-menu { position: relative; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 12.5px;
  border: none; cursor: pointer; font-family: inherit;
}
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
  min-width: 220px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.menu-header { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-header .name { font-weight: 600; }
.menu-header .email { font-size: 12.5px; color: var(--muted); }
.menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border: none; background: none; border-radius: var(--radius-sm);
  font: inherit; font-size: 13.5px; color: var(--text-2); cursor: pointer; text-align: left;
}
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.menu-item.danger { color: var(--danger); }

/* ─── Modal ───────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(8, 12, 20, 0.5); backdrop-filter: blur(2px);
  animation: fade-in 0.15s ease;
}
.modal {
  width: 100%; max-width: 480px; max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); animation: pop-in 0.18s ease;
}
.modal.wide { max-width: 640px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 4px; }
.modal-head h3 { font-size: 16.5px; }
.modal-head p { margin-top: 3px; font-size: 13px; color: var(--muted); }
.modal-head .icon-btn { margin: -4px -8px 0 auto; }
.modal-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } }

/* ─── Toasts ──────────────────────────────────────────── */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  display: flex; align-items: center; gap: 10px; max-width: 380px;
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--text); color: var(--surface);
  font-size: 13.5px; box-shadow: var(--shadow-lg);
  animation: toast-in 0.2s ease;
}
.toast .icon { width: 16px; height: 16px; }
.toast.success .icon { color: #32d583; }
.toast.error .icon { color: #f97066; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: all 0.2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ─── Tabs ────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: var(--radius-sm); }
.tab {
  flex: 1; height: 30px; border: none; border-radius: 5px; background: none;
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ─── Empty states ────────────────────────────────────── */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 40px 20px; text-align: center; color: var(--muted); }
.empty .empty-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); margin-bottom: 4px; }
.empty h4 { color: var(--text); font-size: 15px; }
.empty p { font-size: 13px; max-width: 320px; }

/* ─── Scrollbars ──────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

@media (max-width: 640px) {
  .field-row { grid-template-columns: 1fr; }
  .toasts { left: 16px; right: 16px; align-items: stretch; }
  .toast { max-width: none; }
  .crumbs .hide-sm { display: none; }
}

@media (max-width: 640px) { .hide-sm-brand { display: none; } }
