/* ------------------------------------------------------------------
   SMS Lead Extractor – design system
   Neutral surfaces, one accent, soft status tints, generous spacing.
   ------------------------------------------------------------------ */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eef3ff;
  --success: #15803d; --success-soft: #ecfdf3;
  --warning: #b45309; --warning-soft: #fff7e6;
  --danger:  #b91c1c; --danger-soft:  #fef2f2;
  --info:    #0e7490; --info-soft:    #ecfeff;
  --purple:  #6d28d9; --purple-soft:  #f3efff;
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 6px 20px -8px rgba(16, 24, 40, .18);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-feature-settings: "cv11", "ss01", "tnum"; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .86em; direction: ltr; unicode-bidi: embed; color: var(--text-2); background: var(--surface-2); padding: .05rem .3rem; border-radius: 4px; }
pre code { background: none; padding: 0; }
h1, h2, h3, h4, h5, h6 { letter-spacing: -.01em; color: var(--text); }

/* ---------------------------------------------------------------- shell */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: var(--surface); border-inline-end: 1px solid var(--border); position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 1rem .9rem; display: flex; flex-direction: column; gap: .25rem; z-index: 1030; }
.brand { display: flex; align-items: center; gap: .65rem; padding: .35rem .5rem 1rem; color: var(--text); font-weight: 700; font-size: 1.02rem; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; color: var(--text); }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), #7c3aed); color: #fff; display: grid; place-items: center; font-size: 1.05rem; box-shadow: var(--shadow-sm); }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: .72rem; letter-spacing: 0; }
.nav-section { margin-top: .9rem; padding: 0 .6rem .3rem; font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.nav-link-side { display: flex; align-items: center; gap: .7rem; padding: .5rem .65rem; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 500; font-size: .92rem; }
.nav-link-side i { font-size: 1.05rem; color: var(--muted); width: 1.2rem; text-align: center; }
.nav-link-side:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link-side.active { background: var(--accent-soft); color: var(--accent); }
.nav-link-side.active i { color: var(--accent); }
.sidebar-footer { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); font-size: .78rem; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar-h); background: rgba(255,255,255,.85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 1rem; padding: 0 1.5rem; position: sticky; top: 0; z-index: 1020; }
.topbar .search { flex: 1; max-width: 520px; }
.topbar .search .form-control { padding-inline-start: 2.4rem; }
.topbar .search i { position: absolute; inset-inline-start: .9rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.user-chip { display: flex; align-items: center; gap: .6rem; color: var(--text-2); font-weight: 500; padding: .3rem; padding-inline-end: .5rem; border-radius: 999px; }
.user-chip:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.content { padding: 1.6rem 1.75rem 3rem; max-width: 1480px; width: 100%; margin: 0 auto; }
.sidebar-toggle { display: none; }
@media (max-width: 991.98px) {
  .sidebar { position: fixed; inset-inline-start: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open::after { content: ""; position: fixed; inset: 0; background: rgba(17, 24, 39, .35); z-index: 1025; }
  .sidebar-toggle { display: inline-flex; }
  .content { padding: 1.1rem 1rem 2.5rem; }
}

/* ---------------------------------------------------------------- page header */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-title { font-size: 1.45rem; font-weight: 700; margin: 0; }
.page-subtitle { margin: .2rem 0 0; color: var(--muted); font-size: .92rem; max-width: 70ch; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.eyebrow { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

/* ---------------------------------------------------------------- cards */
.card { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); background: var(--surface); }
.card-header { background: transparent; border-bottom: 1px solid var(--border); padding: .85rem 1.15rem; font-weight: 600; font-size: .95rem; display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.card-header .text-muted, .card-header small { font-weight: 400; }
.card-body { padding: 1.15rem; }
.card-footer { background: transparent; border-top: 1px solid var(--border); padding: .7rem 1.15rem; }
.card-soft { background: var(--surface-2); border-style: dashed; box-shadow: none; }
.card.accent { border-color: #c7d7fe; background: linear-gradient(180deg, #fbfcff, #fff); }

/* ---------------------------------------------------------------- stat tiles */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: .75rem; }
.stat-tile { display: flex; align-items: center; gap: .85rem; padding: .9rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease; }
a.stat-tile:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow); border-color: var(--border-strong); color: var(--text); }
.stat-tile .icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-size: 1.1rem; background: var(--accent-soft); color: var(--accent); flex: 0 0 auto; }
.stat-tile .icon.green { background: var(--success-soft); color: var(--success); }
.stat-tile .icon.amber { background: var(--warning-soft); color: var(--warning); }
.stat-tile .icon.red { background: var(--danger-soft); color: var(--danger); }
.stat-tile .icon.teal { background: var(--info-soft); color: var(--info); }
.stat-tile .icon.purple { background: var(--purple-soft); color: var(--purple); }
.stat-tile .value { font-size: 1.35rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-tile .label { font-size: .78rem; color: var(--muted); margin-top: .1rem; }

/* ---------------------------------------------------------------- pills & badges */
.badge { font-weight: 600; font-size: .72rem; padding: .3em .6em; border-radius: 999px; letter-spacing: .01em; }
.badge.text-bg-primary   { background: var(--accent-soft)  !important; color: var(--accent)  !important; }
.badge.text-bg-success   { background: var(--success-soft) !important; color: var(--success) !important; }
.badge.text-bg-warning   { background: var(--warning-soft) !important; color: var(--warning) !important; }
.badge.text-bg-danger    { background: var(--danger-soft)  !important; color: var(--danger)  !important; }
.badge.text-bg-info      { background: var(--info-soft)    !important; color: var(--info)    !important; }
.badge.text-bg-secondary { background: #f1f3f5 !important; color: var(--text-2) !important; }
.badge.text-bg-light     { background: var(--surface) !important; color: var(--text-2) !important; border: 1px solid var(--border); }
.badge.text-bg-dark      { background: var(--purple-soft) !important; color: var(--purple) !important; }
.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .65rem; border-radius: 999px; font-size: .78rem; font-weight: 500; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); }
.pill .x { border: 0; background: none; color: var(--muted); padding: 0 0 0 .1rem; line-height: 1; font-size: 1rem; }
.pill .x:hover { color: var(--danger); }
.pill.tag { background: var(--surface); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--border-strong); }

/* ---------------------------------------------------------------- buttons & forms */
.btn { border-radius: var(--radius-sm); font-weight: 500; padding: .45rem .9rem; font-size: .9rem; }
.btn-sm { padding: .3rem .65rem; font-size: .82rem; border-radius: 7px; }
.btn-lg { padding: .7rem 1.2rem; font-size: 1rem; border-radius: 10px; }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-outline-primary { color: var(--accent); border-color: #c7d7fe; }
.btn-outline-primary:hover { background: var(--accent-soft); color: var(--accent); border-color: #a9c0fb; }
.btn-outline-secondary { color: var(--text-2); border-color: var(--border-strong); background: var(--surface); }
.btn-outline-secondary:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-outline-danger { color: var(--danger); border-color: #fecaca; }
.btn-outline-danger:hover { background: var(--danger-soft); color: var(--danger); border-color: #fca5a5; }
.btn-outline-success { color: var(--success); border-color: #bbf7d0; }
.btn-outline-success:hover { background: var(--success-soft); color: var(--success); border-color: #86efac; }
.btn-warning { background: #f59e0b; border-color: #f59e0b; color: #1f2937; }
.btn-warning:hover { background: #d97706; border-color: #d97706; color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.form-control, .form-select { border-radius: var(--radius-sm); border-color: var(--border-strong); font-size: .92rem; color: var(--text); }
.form-control:focus, .form-select:focus { border-color: #93b4fd; box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
.form-control-sm, .form-select-sm { border-radius: 7px; font-size: .85rem; }
.form-control-lg { border-radius: 10px; font-size: 1.05rem; }
.form-label { font-size: .82rem; font-weight: 500; color: var(--text-2); margin-bottom: .3rem; }
.form-text { font-size: .8rem; color: var(--muted); }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }

/* ---------------------------------------------------------------- filter bar */
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem .75rem; padding: .85rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; }
.filter-field { display: flex; flex-direction: column; gap: .25rem; min-width: 7rem; }
.filter-field > label { font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.filter-bar .form-check { margin-bottom: .35rem; }
.filter-actions { display: flex; gap: .4rem; align-items: center; margin-inline-start: auto; }

/* ---------------------------------------------------------------- tables */
.table { --bs-table-hover-bg: #f8fafc; margin-bottom: 0; font-size: .9rem; }
.table > :not(caption) > * > * { padding: .7rem .9rem; border-bottom-color: var(--border); vertical-align: middle; }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tbody tr:last-child > * { border-bottom: 0; }
.card > .table, .card > .table-responsive > .table { border-radius: var(--radius); overflow: hidden; }
.table .num { font-variant-numeric: tabular-nums; text-align: end; }
.table-secondary { --bs-table-bg: #f8f9fa; color: var(--muted); }
.empty { padding: 2.2rem 1rem; text-align: center; color: var(--muted); }
.empty i { font-size: 1.8rem; display: block; margin-bottom: .4rem; color: var(--border-strong); }

/* ---------------------------------------------------------------- SMS content */
.sms-body { white-space: pre-wrap; word-break: break-word; direction: rtl; text-align: right; unicode-bidi: plaintext; font-size: 1rem; line-height: 1.65; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .75rem 1rem; color: var(--text); }
textarea.sms-body-input { direction: rtl; unicode-bidi: plaintext; font-size: 1rem; line-height: 1.65; min-height: 6.5rem; background: var(--surface-2); border-radius: 10px; }
textarea.sms-body-input:focus { background: var(--surface); }
textarea.regex-input, .regex-pattern { font-family: var(--mono); direction: ltr; unicode-bidi: plaintext; font-size: .86rem; word-break: break-all; white-space: pre-wrap; }
.regex-pattern { background: #0f172a; color: #e2e8f0; border-radius: 10px; padding: .9rem 1rem; margin: 0; line-height: 1.6; }

/* ---------------------------------------------------------------- message cards */
.message-card { border-radius: var(--radius); }
.message-card .card-header { padding: .75rem 1.15rem; flex-wrap: wrap; font-weight: 500; }
.message-card .meta { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .6rem; font-size: .84rem; color: var(--muted); }
.message-card .meta strong { color: var(--text); font-weight: 600; }
.source-chip { display: inline-flex; align-items: center; gap: .45rem; font-weight: 600; color: var(--text); }
.source-chip .avatar { width: 28px; height: 28px; font-size: .75rem; border-radius: 8px; }
.message-card.border-info { border-color: #a5f3fc; }
.message-card.border-success { border-color: #86efac; }
.message-card.border-secondary { opacity: .85; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.analysis-panel { border-top: 1px dashed var(--border-strong); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.fact-chip { display: inline-flex; align-items: center; gap: .3rem; margin: 0 0 .3rem; margin-inline-end: .3rem; padding: .22rem .6rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: .84rem; }
.fact-chip .conf { color: var(--muted); font-size: .76em; font-variant-numeric: tabular-nums; }
.fact-chip.inferred { border-style: dashed; color: var(--text-2); }

/* ---------------------------------------------------------------- profile */
.profile-hero { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; padding: 1.25rem 1.4rem; border-radius: var(--radius); background: linear-gradient(135deg, #0f172a 0%, #1e293b 55%, #1e3a8a 100%); color: #fff; margin-bottom: 1.25rem; box-shadow: var(--shadow); }
.profile-hero .number { font-size: 1.9rem; font-weight: 700; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.profile-hero .name { font-size: 1.15rem; opacity: .95; }
.profile-hero .meta { color: rgba(255,255,255,.72); font-size: .85rem; }
.profile-hero .btn-light { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff; }
.profile-hero .btn-light:hover { background: rgba(255,255,255,.22); color: #fff; }
.score-ring { --p: 0; width: 76px; height: 76px; border-radius: 50%; background: conic-gradient(#60a5fa calc(var(--p) * 1%), rgba(255,255,255,.15) 0); display: grid; place-items: center; flex: 0 0 auto; }
.score-ring > div { width: 60px; height: 60px; border-radius: 50%; background: #0f172a; display: grid; place-items: center; text-align: center; line-height: 1; }
.score-ring b { font-size: 1.25rem; }
.score-ring small { font-size: .62rem; opacity: .75; text-transform: uppercase; letter-spacing: .05em; }
.kv { display: grid; grid-template-columns: 9rem 1fr; gap: .45rem 1rem; font-size: .92rem; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; }
.fact-list { list-style: none; margin: 0; padding: 0; }
.fact-list li { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px dashed var(--border); }
.fact-list li:last-child { border-bottom: 0; }
.evidence-btn { flex: 1; text-align: start; background: none; border: 0; padding: .15rem .35rem; border-radius: 6px; color: var(--text); font-size: .92rem; }
.evidence-btn:hover { background: var(--accent-soft); color: var(--accent); }
.evidence-btn .type { color: var(--muted); font-size: .78rem; }
.conf-badge { font-variant-numeric: tabular-nums; min-width: 2.9rem; justify-content: center; }
.section-title { display: flex; align-items: center; gap: .5rem; font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 .5rem; }
.section-title .count { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 .45rem; font-size: .72rem; color: var(--text-2); }
.timeline { position: relative; padding-inline-start: 1.4rem; }
.timeline::before { content: ""; position: absolute; inset-inline-start: .45rem; top: .4rem; bottom: .4rem; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding: .4rem 0 1.1rem; }
.timeline-item::before { content: ""; position: absolute; inset-inline-start: -1.4rem; top: .85rem; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border-strong); margin-inline-start: .11rem; }
.timeline-item.extracted::before { border-color: var(--accent); background: var(--accent); }
.timeline-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .4rem .8rem; font-size: .86rem; margin-bottom: .4rem; }
.timeline-head .when { font-weight: 600; color: var(--text); }

/* ---------------------------------------------------------------- misc */
.list-group-item { border-color: var(--border); padding: .7rem 1.15rem; font-size: .9rem; }
.alert { border-radius: var(--radius-sm); border: 1px solid transparent; font-size: .9rem; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: #bbf7d0; }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: #fde68a; }
.alert-info { background: var(--info-soft); color: var(--info); border-color: #a5f3fc; }
.alert-secondary { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
.dropdown-menu { border-radius: 10px; border-color: var(--border); box-shadow: var(--shadow); padding: .4rem; }
.dropdown-item { border-radius: 6px; font-size: .9rem; padding: .45rem .7rem; }
.modal-content { border-radius: var(--radius); border: 0; box-shadow: var(--shadow); }
.bar-chart { display: flex; align-items: flex-end; gap: 3px; height: 90px; }
.bar-chart div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; opacity: .85; min-height: 3px; }
details > summary { cursor: pointer; color: var(--accent); font-size: .85rem; list-style: none; }
details > summary::before { content: "›"; display: inline-block; margin-inline-end: .3rem; transition: transform .15s; }
details[open] > summary::before { transform: rotate(90deg); }
.auth-page { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 10% -10%, #dbe7ff 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #ede9fe 0%, transparent 55%), var(--bg); padding: 1rem; }
.auth-card { width: 100%; max-width: 400px; }
footer.app-footer { color: var(--muted); font-size: .78rem; padding: 1rem 1.75rem; border-top: 1px solid var(--border); }

/* ---------------------------------------------------------------- right-to-left (Arabic) */
[dir="rtl"] { --font: "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Kufi Arabic", "IBM Plex Sans Arabic", system-ui, -apple-system, Roboto, Arial, sans-serif; }
[dir="rtl"] body { font-feature-settings: normal; letter-spacing: 0; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, [dir="rtl"] h4, [dir="rtl"] h5, [dir="rtl"] h6, [dir="rtl"] .eyebrow, [dir="rtl"] .section-title, [dir="rtl"] .nav-section { letter-spacing: 0; }
[dir="rtl"] details > summary::before { content: "‹"; }
[dir="rtl"] details[open] > summary::before { transform: rotate(-90deg); }
[dir="rtl"] .flip-rtl { transform: scaleX(-1); display: inline-block; }
/* Technical identifiers stay left-to-right inside Arabic text. */
[dir="rtl"] code, [dir="rtl"] .mono, [dir="rtl"] pre, [dir="rtl"] .regex-pattern, [dir="rtl"] .regex-input, [dir="rtl"] input[type="number"], [dir="rtl"] input[type="date"], [dir="rtl"] input[type="email"], [dir="rtl"] input[type="url"] { direction: ltr; unicode-bidi: isolate; }
[dir="rtl"] input[type="number"], [dir="rtl"] input[type="date"] { text-align: end; }
.lang-switcher .dropdown-item form { margin: 0; }
