:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1c2024;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2f6f4e;
  --accent-soft: #eaf3ee;
  --error: #c0392b;
  --warning: #c77d0a;
  --info: #2b6cb0;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  /* Persian faces first, then whatever the system provides; nothing is fetched. */
  font-family: Vazirmatn, "Vazir", "Sahel", "IRANSans", Tahoma, "DejaVu Sans", sans-serif;
  font-size: 15px;
  line-height: 1.9;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand h1 { margin: 0; font-size: 19px; font-weight: 700; }
.tagline { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.health { font-size: 12.5px; color: var(--muted); text-align: left; }
.health.ok { color: var(--accent); }
.health.bad { color: var(--error); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  padding: 16px 22px 24px;
  align-items: start;
}

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
}

.editor-pane, .issues-pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.editor-pane { padding: 12px; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.tiers { display: flex; gap: 6px; flex-wrap: wrap; }

.tier-toggle {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  color: var(--muted);
}
.tier-toggle[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

button.primary, button.ghost {
  font-family: inherit;
  font-size: 13px;
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:disabled { opacity: .55; cursor: default; }

.samples { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.samples button {
  font-family: inherit; font-size: 12.5px; cursor: pointer;
  border: 1px dashed var(--line); background: #fff; color: var(--muted);
  border-radius: 8px; padding: 5px 10px;
}
.samples button:hover { border-color: var(--accent); color: var(--accent); }

/* The highlight layer sits behind a transparent textarea, so both must lay text out
   identically or the marks drift away from the words they belong to. */
.editor-wrap { position: relative; }

.highlights, #input {
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 100%;
  min-height: 300px;
  font: inherit;
  line-height: 1.9;
  direction: rtl;
  text-align: right;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  tab-size: 4;
  /* Once the textarea overflows it grows a scrollbar and the highlight layer does not,
     leaving the two with different content widths — they then wrap at different points
     and every mark slides off its word. Both scroll always, so both reserve the gutter. */
  overflow-y: scroll;
}

.highlights {
  position: absolute;
  inset: 0;
  overflow-x: hidden;
  color: transparent;
  background: #fff;
  pointer-events: none;
}

#input {
  position: relative;
  /* As an inline-block the textarea sits on a text baseline, leaving descender space
     below it, so .editor-wrap ends up ~8px taller than the textarea. The highlight
     layer stretches to the wrapper, its scroll range no longer matches, and scrolled
     text drifts away from its marks. */
  display: block;
  background: transparent;
  color: var(--ink);
  resize: vertical;
  outline: none;
}
#input:focus { border-color: var(--accent); }

mark {
  background: transparent;
  color: transparent;
  border-radius: 2px;
  padding-bottom: 1px;
}
mark.sev-error   { border-bottom: 2px solid var(--error); background: rgba(192,57,43,.09); }
mark.sev-warning { border-bottom: 2px solid var(--warning); background: rgba(199,125,10,.10); }
mark.sev-info    { border-bottom: 2px dotted var(--info); background: rgba(43,108,176,.08); }
mark.active { background: rgba(47,111,78,.20); }

.statusbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-top: 10px; font-size: 12.5px; color: var(--muted);
}
.consent { display: flex; align-items: center; gap: 6px; margin-inline-start: auto; cursor: pointer; }
.privacy { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

.issues-pane { padding: 12px; position: sticky; top: 16px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.issues-head { display: flex; align-items: center; justify-content: space-between; }
.issues-head h2 { margin: 0; font-size: 15px; }
.badge {
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 1px 10px; font-size: 12.5px; font-weight: 700;
}

.summary { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0; }
.summary span {
  font-size: 11.5px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px;
}

.issues { overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 8px; }
.empty.good { color: var(--accent); font-weight: 600; }

.card {
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  cursor: pointer;
  background: #fff;
}
.card:hover, .card.active { border-color: var(--accent); background: #fbfdfc; }
.card.sev-error   { border-inline-start-color: var(--error); }
.card.sev-warning { border-inline-start-color: var(--warning); }
.card.sev-info    { border-inline-start-color: var(--info); }

.card-head { display: flex; align-items: baseline; gap: 8px; justify-content: space-between; }
.tier-tag { font-size: 11px; color: var(--muted); white-space: nowrap; }
.original { font-weight: 700; }
.card-msg { margin: 5px 0 0; font-size: 12.5px; color: var(--muted); }
.card-src { margin: 4px 0 0; font-size: 11.5px; color: var(--muted); }

.suggestions { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
.suggestion {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  border: 1px solid var(--line); border-radius: 7px; padding: 5px 9px;
  background: #fff; font-family: inherit; font-size: 13.5px; cursor: pointer; text-align: right;
  width: 100%;
}
.suggestion:hover { border-color: var(--accent); background: var(--accent-soft); }
.suggestion .text { font-weight: 600; }
.suggestion .pos { font-size: 11px; color: var(--muted); }
.suggestion .why { font-size: 11.5px; color: var(--muted); width: 100%; }

.toast {
  position: fixed; inset-block-end: 18px; inset-inline-start: 50%;
  transform: translateX(50%);
  background: #23282d; color: #fff; padding: 9px 16px;
  border-radius: 8px; font-size: 13px; opacity: 0;
  transition: opacity .18s; pointer-events: none; z-index: 20;
}
.toast.show { opacity: 1; }
.toast.error { background: var(--error); }
