/* ─── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f8fafc;
  --surface:   #ffffff;
  --surface2:  #f1f5f9;
  --border:    #e2e8f0;
  --border2:   #cbd5e1;
  --accent:    #4f6ef7;
  --accent2:   #7c3aed;
  --teal:      #0891b2;
  --green:     #059669;
  --amber:     #d97706;
  --red:       #dc2626;
  --text:      #0f172a;
  --text-muted:#475569;
  --text-dim:  #94a3b8;
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 4px 24px rgba(15,23,42,.08);
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* Arabic mode */
[lang="ar"] body, body.rtl {
  font-family: 'IBM Plex Sans Arabic', 'Inter', system-ui, sans-serif;
  direction: rtl;
  text-align: right;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: 'Fira Code', monospace; font-size: .85em; color: var(--teal); }

/* ─── Grid background ────────────────────────────────────────── */
.grid-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(6,44,110,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(6,44,110,.03) 1px, transparent 1px);
  background-size: 40px 40px;
}

/* ─── Header ─────────────────────────────────────────────────── */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(248,250,252,.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2rem; height: 64px;
  gap: 1rem;
}
.logo { display: flex; align-items: center; gap: .6rem; font-size: 1.15rem; flex-shrink: 0; }
.logo-wide { height: 22px; object-fit: contain; opacity: .85; filter: none; }
[data-theme="dark"] .logo-wide, body:not(.light) .logo-wide { filter: brightness(0) invert(1); opacity: .75; }
.logo-icon { font-size: 1.4rem; color: var(--accent); }
.logo-text { color: var(--text-muted); letter-spacing: -.02em; }
.logo-text strong { color: var(--text); }
.header-nav { display: flex; gap: 1rem; }
.header-actions {
  display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0;
}
.btn-back {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.8rem; font-weight: 600; color: var(--text-muted);
  padding: 0.35rem 0.85rem; border: 1px solid var(--border2);
  border-radius: 6px; background: var(--surface);
  text-decoration: none; transition: all .2s;
}
.btn-back:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
.btn-consult {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.8rem; font-weight: 700; color: #fff;
  padding: 0.35rem 0.9rem; border-radius: 6px;
  background: linear-gradient(135deg, #25d366, #128c7e);
  text-decoration: none; transition: opacity .2s;
}
.btn-consult:hover { opacity: .88; text-decoration: none; }
.btn-lang {
  font-size: 0.78rem; font-weight: 700; color: var(--accent);
  padding: 0.3rem 0.7rem; border: 1px solid var(--accent);
  border-radius: 6px; background: transparent; cursor: pointer;
  font-family: 'IBM Plex Sans Arabic', sans-serif;
  transition: all .2s;
}
.btn-lang:hover { background: var(--accent); color: #fff; }
.nav-link {
  font-size: .875rem; font-weight: 500; color: var(--text-muted);
  padding: .3rem .6rem; border-radius: 6px; transition: color .2s, background .2s;
}
.nav-link:hover, .nav-link.active {
  color: var(--text); background: rgba(79,110,247,.15);
  text-decoration: none;
}

/* ─── Main ───────────────────────────────────────────────────── */
.main-content {
  position: relative; z-index: 1;
  max-width: 1100px; margin: 0 auto;
  padding: 3rem 2rem 6rem;
}
.hidden { display: none !important; }

/* ─── Hero / Input Panel ─────────────────────────────────────── */
.hero-panel { text-align: center; }
.hero-text { margin-bottom: 2.5rem; }
.hero-text h1 {
  font-size: clamp(1.8rem, 4.5vw, 2.8rem);
  font-weight: 700; letter-spacing: -.03em;
  background: linear-gradient(135deg, #1e293b 30%, var(--accent) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: .75rem;
}
.hero-sub { font-size: 1rem; color: var(--text-muted); max-width: 580px; margin: 0 auto; line-height: 1.65; }

/* Input card */
.input-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 2rem 2.5rem;
  max-width: 680px; margin: 0 auto 2rem;
  box-shadow: var(--shadow);
}
.input-row {
  display: flex; gap: 1rem; align-items: stretch;
}
.domain-wrap {
  flex: 1; display: flex; align-items: center;
  background: var(--surface2);
  border: 1.5px solid var(--border2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color .2s;
}
.domain-wrap:focus-within { border-color: var(--accent); }
.domain-prefix {
  padding: 0 .75rem; color: var(--text-dim); font-size: .875rem;
  white-space: nowrap; border-right: 1px solid var(--border2);
  line-height: 44px;
}
#domain-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-size: 1rem; padding: 0 1rem;
  font-family: 'Inter', sans-serif;
  height: 44px;
}
#domain-input::placeholder { color: var(--text-dim); }
.btn-audit {
  display: flex; align-items: center; gap: .5rem;
  padding: 0 1.75rem; height: 44px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; border: none; border-radius: var(--radius-sm);
  font-size: .95rem; font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: opacity .2s, transform .15s;
}
.btn-audit:hover { opacity: .9; transform: translateY(-1px); }
.btn-audit:active { transform: translateY(0); }
.btn-audit:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-icon { font-size: 1.1rem; }
.input-hint { margin-top: .75rem; font-size: .8rem; color: var(--text-dim); text-align: left; }

/* Criteria pills */
.criteria-pills {
  display: flex; flex-wrap: wrap; gap: .6rem;
  justify-content: center; max-width: 700px; margin: 0 auto;
}
.pill {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 999px;
  padding: .35rem .9rem; font-size: .8rem; color: var(--text-muted);
  transition: border-color .2s;
}
.pill:hover { border-color: var(--accent); color: var(--text); }
.pill-icon { font-size: 1rem; }

/* ─── Progress Panel ─────────────────────────────────────────── */
.progress-panel { max-width: 680px; margin: 0 auto; }
.progress-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 2.5rem;
  box-shadow: var(--shadow);
}
.progress-header {
  display: flex; align-items: center; gap: 1.25rem; margin-bottom: 2rem;
}
.pulse-ring {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(79,110,247,.1);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.pulse-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.35); opacity: .6; }
}
.progress-header h2 { font-size: 1.15rem; font-weight: 600; }
.step-label { font-size: .875rem; color: var(--accent); margin-top: .15rem; }

.progress-bar-wrap {
  background: var(--surface2);
  border-radius: 999px; height: 6px; overflow: hidden;
  margin-bottom: 2rem;
}
.progress-bar {
  height: 100%; border-radius: 999px; width: 5%;
  background: linear-gradient(90deg, var(--accent), var(--teal));
  transition: width .4s ease;
}

.progress-steps { display: flex; flex-direction: column; gap: .6rem; }
.step-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .9rem;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  font-size: .875rem; color: var(--text-muted);
  border: 1px solid transparent;
  transition: all .3s;
}
.step-item.active {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(79,110,247,.08);
}
.step-item.done {
  border-color: rgba(16,185,129,.3);
  color: var(--green);
  background: rgba(16,185,129,.06);
}
.step-item.error {
  border-color: rgba(239,68,68,.3);
  color: var(--red);
  background: rgba(239,68,68,.06);
}
.step-icon { font-size: 1rem; width: 20px; text-align: center; }

/* ─── Results Panel ──────────────────────────────────────────── */

/* Score hero */
.score-hero {
  display: flex; align-items: center; gap: 3rem;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 2.5rem 3rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.score-ring-wrap { position: relative; width: 140px; height: 140px; flex-shrink: 0; }
.score-ring { width: 140px; height: 140px; transform: rotate(-90deg); }
.ring-bg  { fill: none; stroke: var(--surface2); stroke-width: 10; }
.ring-fill {
  fill: none; stroke-width: 10;
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 1.2s cubic-bezier(.4,0,.2,1), stroke .5s;
}
.score-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.score-num  { font-size: 2.4rem; font-weight: 700; line-height: 1; }
.score-label { font-size: .75rem; color: var(--text-muted); }

.score-meta { flex: 1; min-width: 220px; }
.score-meta h2 { font-size: 1.5rem; font-weight: 700; margin-bottom: .3rem; }
#result-pages { font-size: .875rem; color: var(--text-muted); margin-bottom: 1rem; }
.score-grade {
  display: inline-block;
  padding: .3rem 1rem; border-radius: 999px;
  font-size: .9rem; font-weight: 700;
  margin-bottom: 1.25rem;
  background: rgba(79,110,247,.15);
  color: var(--accent);
}
.score-grade.grade-A { background: rgba(16,185,129,.15); color: var(--green); }
.score-grade.grade-B { background: rgba(6,182,212,.15);  color: var(--teal); }
.score-grade.grade-C { background: rgba(245,158,11,.15); color: var(--amber); }
.score-grade.grade-D { background: rgba(239,68,68,.15);  color: var(--red); }

.result-actions { display: flex; gap: .75rem; flex-wrap: wrap; }
.btn-secondary {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.2rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 600; cursor: pointer;
  border: none; text-decoration: none;
  transition: opacity .2s, transform .15s;
}
.btn-secondary:hover { opacity: .9; transform: translateY(-1px); text-decoration: none; }
.btn-outline {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.2rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 500; cursor: pointer;
  transition: border-color .2s, color .2s;
}
.btn-outline:hover { border-color: var(--accent); color: var(--text); }

/* Criteria grid */
.criteria-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}
.crit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: border-color .25s;
}
.crit-card:hover { border-color: var(--border2); }

.crit-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.crit-title { display: flex; align-items: center; gap: .6rem; font-size: .95rem; font-weight: 600; }
.crit-emoji { font-size: 1.2rem; }
.crit-score-badge {
  font-size: .8rem; font-weight: 700;
  padding: .25rem .65rem; border-radius: 999px;
}
.badge-green { background: rgba(16,185,129,.15); color: var(--green); }
.badge-teal  { background: rgba(6,182,212,.15);  color: var(--teal); }
.badge-amber { background: rgba(245,158,11,.15); color: var(--amber); }
.badge-red   { background: rgba(239,68,68,.15);  color: var(--red); }
.badge-blue  { background: rgba(79,110,247,.15); color: var(--accent); }

.crit-bar-wrap {
  background: var(--surface2); border-radius: 999px;
  height: 4px; overflow: hidden; margin-bottom: 1rem;
}
.crit-bar { height: 100%; border-radius: 999px; transition: width 1s ease; }
.bar-green { background: var(--green); }
.bar-teal  { background: var(--teal); }
.bar-amber { background: var(--amber); }
.bar-red   { background: var(--red); }
.bar-blue  { background: var(--accent); }

.crit-stats { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stat-item { display: flex; flex-direction: column; gap: .15rem; }
.stat-val  { font-size: 1.2rem; font-weight: 700; }
.stat-key  { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

.crit-issues { display: flex; flex-direction: column; gap: .45rem; }
.issue-item {
  display: flex; align-items: flex-start; gap: .5rem;
  font-size: .8rem; color: var(--text-muted); line-height: 1.5;
}
.issue-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; margin-top: .45rem;
}
.dot-red    { background: var(--red); }
.dot-amber  { background: var(--amber); }
.dot-green  { background: var(--green); }
.dot-blue   { background: var(--accent); }

.crit-tags { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .75rem; }
.kw-tag {
  font-size: .75rem; padding: .2rem .55rem; border-radius: 4px;
  background: rgba(79,110,247,.12); color: var(--accent);
  border: 1px solid rgba(79,110,247,.2);
}
.kw-tag.ar { background: rgba(124,58,237,.12); color: #a78bfa; border-color: rgba(124,58,237,.2); }

/* ─── Link Panels (URLs / Internal / External) ───────────────── */
.link-panels { display: flex; flex-direction: column; gap: .5rem; margin-top: .85rem; }

.link-section { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }

.link-toggle {
  width: 100%; display: flex; align-items: center; gap: .5rem;
  padding: .6rem .85rem; background: var(--surface2);
  border: none; cursor: pointer; color: var(--text-muted);
  font-size: .8rem; font-weight: 600; text-align: left;
  transition: background .2s, color .2s;
}
.link-toggle:hover { background: var(--border); color: var(--text); }

.link-count {
  margin-left: auto; margin-right: .3rem;
  background: rgba(79,110,247,.18); color: var(--accent);
  font-size: .72rem; font-weight: 700;
  padding: .1rem .5rem; border-radius: 999px;
}

.toggle-arrow { font-size: .65rem; color: var(--text-dim); }

.link-panel {
  overflow-y: auto;
  max-height: 260px;
  border-top: 1px solid var(--border);
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
}
.link-panel::-webkit-scrollbar { width: 5px; }
.link-panel::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

.link-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .38rem .85rem;
  border-bottom: 1px solid var(--border);
  font-size: .75rem;
}
.link-row:last-child { border-bottom: none; }
.link-row:hover { background: rgba(255,255,255,.03); }

.link-status-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}

.link-url {
  flex: 1; color: var(--text-muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  transition: color .15s;
}
.link-url:hover { color: var(--accent); text-decoration: none; }

.link-badge {
  flex-shrink: 0; font-size: .68rem; font-weight: 700;
  padding: .1rem .45rem; border-radius: 4px;
}

.link-empty {
  padding: .6rem .85rem; font-size: .8rem; color: var(--text-dim);
  background: var(--surface2);
}

.link-viewmore {
  width: 100%; padding: .45rem .85rem;
  background: none; border: none; border-top: 1px solid var(--border);
  color: var(--accent); font-size: .76rem; font-weight: 600;
  cursor: pointer; text-align: center;
  transition: background .15s, color .15s;
}
.link-viewmore:hover { background: rgba(79,110,247,.08); }

/* ─── History Panel ──────────────────────────────────────────── */
.section-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 1.5rem; }
.history-list { display: flex; flex-direction: column; gap: .75rem; }
.empty-msg { color: var(--text-muted); font-size: .95rem; }
.history-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  gap: 1rem; flex-wrap: wrap;
  transition: border-color .2s;
}
.history-item:hover { border-color: var(--border2); }
.hi-domain { font-weight: 600; font-size: .95rem; }
.hi-meta   { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }
.hi-score  { font-size: 1.4rem; font-weight: 700; color: var(--accent); flex-shrink: 0; }
.hi-actions { display: flex; gap: .5rem; }
.btn-xs {
  padding: .3rem .7rem; border-radius: 6px; font-size: .78rem; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border2); background: var(--surface2);
  color: var(--text-muted); transition: all .2s;
}
.btn-xs:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Footer ─────────────────────────────────────────────────── */
.site-footer {
  position: relative; z-index: 1; text-align: center;
  padding: 1.5rem; border-top: 1px solid var(--border);
  font-size: .78rem; color: var(--text-dim);
}

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .btn-back span, .btn-consult span { display: none; }
  .btn-back::after { content: '←'; }
  .btn-consult::after { content: '💬'; }
}
@media (max-width: 640px) {
  .main-content { padding: 2rem 1rem 4rem; }
  .input-row { flex-direction: column; }
  .btn-audit { width: 100%; justify-content: center; }
  .score-hero { flex-direction: column; align-items: flex-start; gap: 1.5rem; }
  .header-inner { padding: 0 1rem; }
  .input-card { padding: 1.5rem; }
  .header-actions { gap: 0.4rem; }
}

/* RTL overrides */
[dir="rtl"] .domain-prefix { border-right: none; border-left: 1px solid var(--border2); }
[dir="rtl"] .input-hint { text-align: right; }
[dir="rtl"] .btn-back::after { content: '→'; }
[dir="rtl"] .result-actions { flex-direction: row-reverse; }
[dir="rtl"] .crit-stats { flex-direction: row-reverse; }
