:root {
  --purple: #4a3b7c;
  --purple-dark: #362c5c;
  --purple-light: #efeaf9;
  --lavender: #c9b8e8;
  --ink: #1a1a1a;
  --muted: #767085;
  --on-primary: #ffffff;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --font-body: "IBM Plex Sans Arabic", "Tajawal", -apple-system, sans-serif;
  --font-label: "Tajawal", -apple-system, sans-serif;
  --brand-accent: #332464;

  --bg: #fcf9f8;
  --blob-1: #c9b8e850;
  --blob-2: #a8d8e850;
  --blob-3: #f3c9e050;

  --glass: rgba(255, 255, 255, 0.62);
  --glass-strong: rgba(255, 255, 255, 0.82);
  --glass-border: rgba(255, 255, 255, 0.6);
  --glass-shadow: 0 8px 32px rgba(74, 59, 124, 0.1);

  --text: var(--ink);
  --text-muted: var(--muted);
  --input-bg: rgba(255, 255, 255, 0.7);
  --border-soft: rgba(74, 59, 124, 0.12);

  --success: #1f9d55;
  --success-bg: #e3f8ea;
  --info: #1c6fd6;
  --info-bg: #e6f1fd;
  --warn: #b5790a;
  --warn-bg: #fdf1dc;
  --neutral-bg: #eef0f3;

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-full: 999px;
}

[data-theme="dark"] {
  /* "Midnight" palette — deep navy rather than neutral black, brighter lavender accent */
  --purple: #ddb7ff;
  --purple-dark: #b76dff;
  --purple-light: #241f3d;
  --lavender: #c4c5dd;
  --ink: #d4e4fa;
  --muted: #9a93ab;
  --on-primary: #490080;
  --brand-accent: #ddb7ff;

  --bg: #051424;
  --blob-1: #b76dff33;
  --blob-2: #2a3f5f66;
  --blob-3: #ddb7ff22;

  --glass: rgba(13, 28, 45, 0.55);
  --glass-strong: rgba(13, 28, 45, 0.8);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);

  --text: var(--ink);
  --text-muted: var(--muted);
  --input-bg: rgba(255, 255, 255, 0.06);
  --border-soft: rgba(255, 255, 255, 0.1);

  --success: #4ade80;
  --success-bg: #123321;
  --info: #60a5fa;
  --info-bg: #10233d;
  --warn: #fbbf24;
  --warn-bg: #3a2c0c;
  --neutral-bg: #201f28;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  line-height: 1.55;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* Glass panels get a subtle top-edge light seam, like glass catching a highlight */
.card, .stat-card, .property-card, .task-card, .login-box {
  position: relative;
}
.card::before, .stat-card::before, .property-card::before, .task-card::before, .login-box::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.35), transparent);
  opacity: 0.6;
  pointer-events: none;
}

/* soft blurred blobs behind the glass, iOS 18-ish */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(38vw 38vw at 8% -5%, var(--blob-1), transparent 60%),
    radial-gradient(34vw 34vw at 100% 15%, var(--blob-2), transparent 60%),
    radial-gradient(40vw 40vw at 15% 100%, var(--blob-3), transparent 60%);
  filter: blur(40px);
}

a { color: var(--purple); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ---------- Topbar ---------- */

.topbar {
  background: var(--glass-strong);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 1px solid var(--glass-border);
  color: var(--text);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 20px;
}

.brand {
  color: var(--brand-accent);
  font-weight: 700;
  font-size: 18px;
  margin-inline-end: auto;
}
.brand:hover { text-decoration: none; opacity: 0.85; }

.nav-toggle-checkbox { display: none; }

.nav-toggle-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 32px;
  height: 32px;
  cursor: pointer;
}
.nav-toggle-btn span {
  display: block;
  height: 2px;
  background: var(--purple);
  border-radius: 2px;
}

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

.nav-links a {
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-family: var(--font-label);
  white-space: nowrap;
}
.nav-links a:hover {
  background: var(--purple-light);
  text-decoration: none;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-inline-start: 6px;
}

.theme-toggle {
  background: var(--input-bg);
  border: 1px solid var(--border-soft);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.link-btn {
  background: transparent;
  color: var(--purple);
  border: none;
  text-decoration: underline;
  padding: 0;
  font-size: 13px;
  cursor: pointer;
}

@media (max-width: 860px) {
  .nav-toggle-btn { display: flex; }
  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    border-top: 1px solid var(--border-soft);
    padding-top: 10px;
  }
  .nav-toggle-checkbox:checked ~ .nav-links { display: flex; }
  .nav-links a { padding: 12px 14px; border-radius: var(--radius-md); }
  .nav-user {
    margin-inline-start: 0;
    justify-content: space-between;
    padding: 10px 4px;
  }
}

/* ---------- Layout ---------- */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(14px, 3vw, 28px);
}

.card {
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: clamp(16px, 3vw, 26px);
  margin-bottom: 18px;
  box-shadow: var(--glass-shadow);
}

.card h3 {
  margin-top: 0;
  font-size: 16px;
  color: var(--purple);
}

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  display: block;
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--glass-shadow);
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease;
}
.stat-card:hover { text-decoration: none; transform: translateY(-2px); }
.stat-card:active { transform: scale(0.98); }

.stat-card .icon { font-size: 22px; margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 700; color: var(--purple); font-family: var(--font-mono); }
.stat-card .label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ---------- Charts ---------- */

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.chart-box { position: relative; height: 260px; }

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-box {
  background: var(--glass-strong);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-border);
  padding: 34px 28px;
  border-radius: 26px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--glass-shadow);
}

.login-box h1 {
  font-size: 21px;
  text-align: center;
  color: var(--purple);
  margin: 0 0 6px;
}
.login-box .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 26px;
}

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

label.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type=text], input[type=tel], input[type=password], select, textarea {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 4px rgba(74, 59, 124, 0.15);
}

button, .btn {
  background: linear-gradient(135deg, var(--purple-dark), var(--purple));
  color: var(--on-primary);
  border: none;
  padding: 12px 20px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: transform 0.12s ease, opacity 0.15s ease;
}
button:hover, .btn:hover { opacity: 0.9; text-decoration: none; }
button:active, .btn:active { transform: scale(0.96); }

.btn-outline {
  background: var(--input-bg);
  color: var(--purple);
  border: 1px solid var(--border-soft);
}

.error {
  color: #c0392b;
  background: var(--warn-bg);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---------- Filter bar ---------- */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 0;
}
.filter-bar .field { display: flex; flex-direction: column; min-width: 150px; flex: 1 1 150px; }
.filter-bar .field label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.filter-bar select, .filter-bar input { margin-bottom: 0; }
.filter-bar .actions { display: flex; gap: 8px; }

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-label);
  background: var(--purple-light);
  color: var(--purple);
  white-space: nowrap;
}

/* AI-generated content gets a small sparkle marker, per design spec */
.badge-ai::before { content: "✨ "; }

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-neutral { background: var(--neutral-bg); color: var(--text-muted); }

/* ---------- Tables ---------- */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: 12px; text-align: right; border-bottom: 1px solid var(--border-soft); font-size: 13.5px; vertical-align: top; }
th { color: var(--text-muted); font-weight: 600; font-size: 12.5px; white-space: nowrap; }
tbody tr:hover { background: var(--purple-light); }

.task-row form { display: inline; }

.empty-state { color: var(--text-muted); text-align: center; padding: 24px 0; }

/* ---------- Chat bubbles (manual entry) ---------- */

.chat-bubble {
  width: fit-content;
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  margin-bottom: 10px;
  font-size: 14px;
  white-space: pre-wrap;
  line-height: 1.5;
}
.chat-user {
  background: var(--purple);
  color: #fff;
  margin-inline-start: auto;
  border-end-end-radius: 4px;
}
.chat-ai {
  background: var(--purple-light);
  color: var(--text);
  margin-inline-end: auto;
  border-end-start-radius: 4px;
}

/* ---------- Expandable table rows ---------- */

.row-clickable { cursor: pointer; }
.detail-row td {
  background: var(--purple-light);
  white-space: pre-wrap;
  font-size: 13px;
  color: var(--text);
  padding: 14px 16px;
}

/* ---------- Bottom tab bar (iOS-style, mobile only) ---------- */

.bottom-nav {
  display: none;
}

@media (max-width: 860px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    inset-inline: 0;
    z-index: 30;
    background: var(--glass-strong);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-top: 1px solid var(--glass-border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 2px;
    color: var(--text-muted);
    font-size: 10.5px;
    border-radius: var(--radius-md);
  }
  .bottom-nav a:hover { text-decoration: none; }
  .bottom-nav a.active { color: var(--purple); }
  .bottom-nav .bn-icon { font-size: 20px; line-height: 1; }

  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
}

/* ---------- Public homepage ---------- */

.hero {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(50vw 50vw at 15% 0%, var(--blob-1), transparent 60%),
    radial-gradient(45vw 45vw at 100% 10%, var(--blob-2), transparent 60%);
}

.search-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  background: var(--glass-strong);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 14px;
  max-width: 700px;
  margin: 0 auto;
  box-shadow: var(--glass-shadow);
}
.search-bar select { margin-bottom: 0; min-width: 130px; flex: 1 1 130px; }
.search-bar button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.section-heading { text-align: center; margin-bottom: 22px; }
.section-heading h2 { font-size: clamp(20px, 3vw, 28px); color: var(--purple); margin: 0 0 6px; }
.section-heading p { color: var(--text-muted); font-size: 14px; margin: 0; }

.property-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.property-card {
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--glass-shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.property-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md, var(--glass-shadow)); }
.property-card--featured { border-color: var(--purple); }

.property-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.property-icon { font-size: 28px; }
.property-title { font-weight: 700; font-size: 15px; }
.property-location { color: var(--text-muted); font-size: 13px; }
.property-location a { margin-inline-start: 4px; }
.property-price { font-size: 17px; font-weight: 700; color: var(--purple); margin-top: 2px; font-family: var(--font-mono); }
.property-meta { display: flex; gap: 12px; color: var(--text-muted); font-size: 12.5px; }
.property-whatsapp-btn {
  margin-top: 10px;
  text-align: center;
  background: #25d366;
  color: #fff;
}
.property-whatsapp-btn:hover { text-decoration: none; opacity: 0.9; }

.reveal { opacity: 0; transform: translateY(16px); transition: opacity 0.5s ease, transform 0.5s ease; }
.reveal.in-view { opacity: 1; transform: none; }

/* ---------- Task cards ---------- */

.task-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.task-card {
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--glass-shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-card-score {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.task-card-score .score-value { font-size: 26px; font-weight: 800; color: var(--purple); font-family: var(--font-mono); }
.task-card-score .score-label { font-size: 11.5px; color: var(--text-muted); }

.task-side {
  background: var(--purple-light);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}
.task-side .task-side-label { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }
.task-side .task-side-main { font-weight: 700; font-size: 14px; }
.task-side .task-side-sub { font-size: 12.5px; color: var(--text-muted); }

.task-reasoning {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.6;
  border-top: 1px dashed var(--border-soft);
  padding-top: 8px;
}

.task-feedback-form { display: flex; flex-wrap: wrap; gap: 6px; }
.task-feedback-form input[type=text] { flex: 1 1 100%; margin-bottom: 0; }
.task-feedback-form button { flex: 1; font-size: 13px; padding: 9px 10px; }
.btn-good { background: var(--success); color: #fff; border: none; }
.btn-bad { background: #c0392b; color: #fff; border: none; }
