/* Jumeira Automation — design system */

:root {
  --brand: #0866ff;
  --brand-dark: #0450cc;
  --brand-soft: #e8f1ff;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e4e9f0;
  --line-soft: #eef2f7;
  --bg: #f6f8fb;
  --card: #ffffff;
  --success: #16a34a;
  --success-soft: #e7f7ee;
  --warn: #d97706;
  --warn-soft: #fef4e6;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.015em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 0.75rem; }
small { font-size: 0.82rem; }

.muted { color: var(--muted); }
.ink-soft { color: var(--ink-soft); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em; }

/* ---------- App shell ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #6b4bff);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
  flex: 0 0 34px;
}
.brand-text { font-weight: 680; font-size: 0.95rem; letter-spacing: -0.01em; }
.brand-text span { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 500; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); font-weight: 600; padding: 14px 10px 6px;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-weight: 520; font-size: 0.92rem;
  text-decoration: none; transition: background 0.12s, color 0.12s;
}
.nav a:hover { background: var(--line-soft); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.nav a svg { width: 18px; height: 18px; flex: 0 0 18px; }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); }
.user-chip:hover { background: var(--line-soft); }
.user-chip .who { min-width: 0; }
.user-chip .who strong { display: block; font-size: 0.86rem; font-weight: 600; }
.user-chip .who small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 14px 28px; display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .spacer { flex: 1; }

.content { padding: 28px; max-width: 1180px; width: 100%; }
.content.wide { max-width: 1400px; }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.page-head .spacer { flex: 1; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- Cards ---------- */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px 22px; }
.card + .card { margin-top: 18px; }
.card-head {
  padding: 16px 22px; border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 12px;
}
.card-head .spacer { flex: 1; }
.card-body { padding: 20px 22px; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 22px; align-items: start; }

.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Stats ---------- */

.stat { padding: 18px 20px; }
.stat .label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; }
.stat .hint { font-size: 0.82rem; color: var(--muted); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--brand); color: #fff;
  font-family: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s, transform 0.06s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--brand-dark); color: #fff; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn-disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; }

.btn-ghost { background: var(--card); border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { background: var(--line-soft); color: var(--ink); }
.btn-soft { background: var(--brand-soft); color: var(--brand-dark); }
.btn-soft:hover { background: #d9e8ff; color: var(--brand-dark); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-danger-ghost { background: var(--card); border-color: var(--line); color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 11px; font-size: 0.82rem; border-radius: 8px; }
.btn-lg { padding: 12px 22px; font-size: 0.96rem; }
.btn-block { width: 100%; }
.btn-fb { background: #1877f2; }
.btn-fb:hover { background: #0f5fd0; }

.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--card);
  color: var(--muted); cursor: pointer; transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--line-soft); color: var(--ink); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); border-color: #f6cfcf; }
.icon-btn svg { width: 16px; height: 16px; }

/* ---------- Forms ---------- */

.field { margin-bottom: 16px; }
.label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.help { font-size: 0.8rem; color: var(--muted); margin-top: 5px; }

.input, .textarea, .select {
  width: 100%; padding: 10px 12px; font-family: inherit; font-size: 0.92rem;
  color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(8, 102, 255, 0.12);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input-error { border-color: var(--danger); }
.error-text { color: var(--danger); font-size: 0.82rem; margin-top: 5px; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 40px; height: 23px; border-radius: 999px; background: #cbd5e1;
  position: relative; transition: background 0.15s; flex: 0 0 40px;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px;
  border-radius: 50%; background: #fff; transition: transform 0.15s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .track { background: var(--success); }
.switch input:checked + .track::after { transform: translateX(17px); }

/* ---------- Chips / phrases ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--brand-soft); color: var(--brand-dark);
  padding: 5px 8px 5px 11px; border-radius: 999px;
  font-size: 0.85rem; font-weight: 550;
}
.chip button {
  border: none; background: transparent; color: inherit; cursor: pointer;
  opacity: 0.6; padding: 0; line-height: 1; font-size: 1rem;
}
.chip button:hover { opacity: 1; }
.chip-input {
  border: none; outline: none; font-family: inherit; font-size: 0.9rem;
  padding: 6px 4px; min-width: 160px; flex: 1; background: transparent; color: var(--ink);
}

/* ---------- Badges & pills ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 0.76rem; font-weight: 600; letter-spacing: 0.01em;
  background: var(--line-soft); color: var(--ink-soft);
}
.badge-success { background: var(--success-soft); color: #15803d; }
.badge-warn { background: var(--warn-soft); color: #b45309; }
.badge-danger { background: var(--danger-soft); color: #b91c1c; }
.badge-brand { background: var(--brand-soft); color: var(--brand-dark); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.pill {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 6px 12px 6px 8px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--card); font-size: 0.86rem; font-weight: 550;
}

/* ---------- Avatars ---------- */

.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 38px;
  object-fit: cover; background: var(--line-soft);
  display: grid; place-items: center; font-size: 0.8rem; font-weight: 650; color: var(--muted);
  overflow: hidden;
}
.avatar-sm { width: 28px; height: 28px; flex-basis: 28px; font-size: 0.7rem; }
.avatar-lg { width: 52px; height: 52px; flex-basis: 52px; font-size: 1rem; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Tables & lists ---------- */

.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 600; padding: 10px 22px; border-bottom: 1px solid var(--line);
  background: #fafbfd;
}
.table td { padding: 14px 22px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fbfcfe; }

.list-row {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 22px; border-bottom: 1px solid var(--line-soft);
}
.list-row:last-child { border-bottom: none; }
.list-row .spacer { flex: 1; min-width: 0; }

/* ---------- Empty state ---------- */

.empty { padding: 56px 24px; text-align: center; }
.empty-art {
  width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 18px;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center;
}
.empty-art svg { width: 30px; height: 30px; }
.empty h3 { margin-bottom: 6px; }
.empty p { color: var(--muted); max-width: 420px; margin: 0 auto 20px; }

/* ---------- Alerts ---------- */

.alert {
  display: flex; gap: 11px; padding: 13px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--card);
  font-size: 0.89rem; margin-bottom: 18px; align-items: flex-start;
}
.alert svg { width: 18px; height: 18px; flex: 0 0 18px; margin-top: 1px; }
.alert-success { background: var(--success-soft); border-color: #bfe8d0; color: #14532d; }
.alert-error { background: var(--danger-soft); border-color: #f6cfcf; color: #7f1d1d; }
.alert-warn { background: var(--warn-soft); border-color: #f6dcb0; color: #78350f; }
.alert-info { background: var(--brand-soft); border-color: #cadeff; color: #0b3f8f; }

/* ---------- Toast ---------- */

.toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 90; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 0.88rem; font-weight: 500;
  display: flex; align-items: center; gap: 10px;
  animation: toast-in 0.18s ease-out;
}
.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Auth ---------- */

.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #e8f1ff 0%, var(--bg) 55%);
}
.auth-card { width: 100%; max-width: 410px; padding: 32px; }
.auth-brand { display: flex; align-items: center; gap: 11px; justify-content: center; margin-bottom: 24px; }

/* ---------- Steps builder ---------- */

.steps { display: flex; flex-direction: column; gap: 12px; }
.step {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); overflow: hidden;
}
.step.dragging { opacity: 0.45; }
.step.drop-target { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(8, 102, 255, 0.1); }
.step-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; background: #fafbfd; border-bottom: 1px solid var(--line-soft);
}
.step-head .spacer { flex: 1; }
.step-grip { cursor: grab; color: #94a3b8; display: grid; place-items: center; }
.step-grip:active { cursor: grabbing; }
.step-grip svg { width: 16px; height: 16px; }
.step-num {
  width: 22px; height: 22px; border-radius: 7px; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-size: 0.72rem; font-weight: 700; flex: 0 0 22px;
}
.step-kind { font-size: 0.85rem; font-weight: 600; }
.step-body { padding: 14px; }

.delay-row { display: flex; align-items: center; gap: 8px; }
.delay-row .input { width: 90px; }

.token-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.token {
  font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem;
  background: var(--line-soft); color: var(--ink-soft);
  padding: 3px 7px; border-radius: 6px; border: 1px solid var(--line);
  cursor: pointer;
}
.token:hover { background: var(--brand-soft); color: var(--brand-dark); border-color: #cadeff; }

.add-step { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.drop-zone {
  border: 1.5px dashed var(--line); border-radius: var(--radius-sm);
  padding: 18px; text-align: center; color: var(--muted); font-size: 0.86rem;
  cursor: pointer; transition: border-color 0.12s, background 0.12s;
}
.drop-zone:hover { border-color: var(--brand); background: #fafcff; }
.step-image { max-width: 100%; border-radius: var(--radius-sm); display: block; }

/* ---------- Messenger preview ---------- */

.preview-wrap { position: sticky; top: 92px; }
.phone {
  width: 340px; margin: 0 auto; border-radius: 32px; background: #fff;
  border: 9px solid #1c2434; box-shadow: var(--shadow-lg); overflow: hidden;
}
.phone-bar {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft); background: #fff;
}
.phone-bar .back { color: #0866ff; font-size: 1.1rem; line-height: 1; }
.phone-bar strong { font-size: 0.9rem; }
.phone-body {
  padding: 16px 12px; background: #fff; min-height: 380px; max-height: 60vh;
  overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
}
.bubble-group { display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px; }
.bubble {
  max-width: 78%; padding: 9px 13px; font-size: 0.88rem; line-height: 1.4;
  border-radius: 18px; white-space: pre-wrap; word-break: break-word;
}
.bubble-in { background: #f0f2f5; color: #050505; align-self: flex-start; border-bottom-left-radius: 5px; }
.bubble-out { background: #0866ff; color: #fff; align-self: flex-end; border-bottom-right-radius: 5px; }
.bubble-img { padding: 0; overflow: hidden; background: #f0f2f5; align-self: flex-start; max-width: 68%; }
.bubble-img img { display: block; width: 100%; }
.bubble-meta { font-size: 0.7rem; color: var(--muted); align-self: flex-start; padding-left: 6px; }
.typing { display: inline-flex; gap: 3px; align-items: center; padding: 11px 14px; background: #f0f2f5; border-radius: 18px; align-self: flex-start; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: #9aa3af; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.35; } 30% { opacity: 1; } }

/* ---------- Conversation log ---------- */

.thread { display: flex; flex-direction: column; gap: 16px; }
.thread-item { display: flex; gap: 13px; }
.thread-item .body { flex: 1; min-width: 0; }
.thread-msg {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 11px 14px; background: var(--card); font-size: 0.9rem;
  white-space: pre-wrap; word-break: break-word;
}
.thread-msg.out { background: #fafbfd; }
.thread-msg.failed { border-color: #f6cfcf; background: var(--danger-soft); }
.thread-msg img { max-width: 220px; border-radius: 8px; display: block; }
.thread-meta { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; color: var(--muted); margin-top: 5px; flex-wrap: wrap; }
.step-line { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

/* ---------- Public pages ---------- */

.doc { max-width: 760px; margin: 0 auto; padding: 48px 24px 80px; }
.doc h1 { margin-bottom: 8px; }
.doc h2 { margin: 30px 0 10px; }
.doc p, .doc li { color: var(--ink-soft); }
.doc ul { padding-left: 20px; }

/* ---------- Responsive ---------- */

@media (max-width: 1080px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .preview-wrap { position: static; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    flex-direction: row; align-items: center; gap: 8px; overflow-x: auto; padding: 12px;
  }
  .brand { padding: 0 12px 0 4px; }
  .brand-text { display: none; }
  .nav { flex-direction: row; }
  .nav-label, .sidebar-footer { display: none; }
  .content, .topbar { padding: 18px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .phone { width: 100%; }
}

/* RTL groundwork for the Arabic dashboard in a later phase. */
[dir="rtl"] .sidebar { border-right: none; border-left: 1px solid var(--line); }
[dir="rtl"] .bubble-in { border-bottom-left-radius: 18px; border-bottom-right-radius: 5px; }
[dir="rtl"] .doc ul { padding-left: 0; padding-right: 20px; }
