/* ألوان سمائية زاهية ومريحة للعين، وخطوط النظام فقط (لا خطوط خارجية) */
:root {
  --bg: #eef7ff;
  --card: #ffffff;
  --text: #1e2b3a;
  --muted: #55667a;
  --line: #d2e6f5;
  --primary: #0284c7;
  --primary-dark: #0369a1;
  --primary-soft: #e3f3fd;
  --accent: #14b8a6;
  --shadow: 0 4px 18px rgba(2, 132, 199, 0.08);
  --danger: #a73d36;
  --danger-soft: #fbecea;
  --ok: #2d7650;
  --font: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg) linear-gradient(180deg, #d9effd 0%, #eef7ff 280px, #f7fbff 60%, #ffffff 100%) no-repeat;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.8;
}

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.head { text-align: center; margin-bottom: 20px; }
.head h1 { margin: 0 0 6px; font-size: clamp(26px, 5vw, 34px); color: var(--primary-dark); }
.sub { margin: 0; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  margin-bottom: 16px;
}
.card-title { margin: 0 0 14px; font-size: 20px; }

.dropzone {
  border: 2px dashed #7cc4ec;
  background: var(--primary-soft);
  border-radius: 16px;
  padding: 28px 16px;
  text-align: center;
  transition: background .15s, border-color .15s;
}
.dropzone.is-over { background: #cdeafc; border-color: var(--primary); }
.drop-main { margin: 0; font-size: 19px; font-weight: 600; }
.drop-or { margin: 4px 0 10px; color: var(--muted); }
.drop-hint { margin: 14px auto 0; max-width: 46ch; color: var(--muted); font-size: 15px; }

.btn {
  font: inherit;
  min-height: 48px;
  padding: 8px 22px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn:focus-visible, .dropzone:focus-within { outline: 3px solid #f0b429; outline-offset: 2px; }
.btn-primary { background: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); }

.busy { margin: 14px 0 0; color: var(--muted); }
.error {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #efc5c1;
  font-weight: 600;
}

.canvas-wrap {
  background: #e6f2fb;
  border-radius: 14px;
  padding: 8px;
  text-align: center;
  overflow: auto;
}
.canvas-wrap.zoomed { max-height: 75vh; }
.canvas-wrap.zoomed .stack { max-width: none; cursor: grab; }
.canvas-wrap.zoomed #preview { max-width: none; width: 100%; }
.canvas-wrap.pixelated canvas { image-rendering: pixelated; }
.stack { user-select: none; -webkit-user-select: none; }
.stack.tool, .canvas-wrap.zoomed .stack { touch-action: none; }
.zoom-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; }
.btn-sm { min-height: 40px; padding: 4px 14px; width: auto; }
.check-inline { margin: 0; margin-inline-start: 12px; }
.log-privacy { display: block; font-weight: 400; font-size: 13px; line-height: 1.6; color: var(--muted); }
.log-store { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 4px; margin: 12px 0 0; }
.view-label { font-weight: 600; }
.healthy-only { display: none; }
.type-note { margin: 8px 0 0; font-weight: 600; color: var(--primary-dark); }
.type-note.warn { color: #9a5b00; }
.type-note.ask { color: var(--danger); }
body.mode-healthy .healthy-only { display: revert; }
body.mode-healthy .plaque-only { display: none !important; }
.jaw-table-wrap { overflow-x: auto; margin: 4px 0 12px; }
.jaw-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.jaw-table th, .jaw-table td { border: 1px solid var(--line); padding: 6px 8px; text-align: center; }
.jaw-table th { background: var(--primary-soft); }
.jaw-table tr.total td { font-weight: 700; background: var(--bg); }
.stain-box { margin: 0 0 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.stain-box .clean-note { margin: 6px 0 0; }
.view-select { font: inherit; min-height: 40px; padding: 4px 10px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--text); }
.zoom-label { color: var(--muted); font-weight: 600; min-width: 4em; }
.stack { position: relative; display: inline-block; max-width: 100%; line-height: 0; vertical-align: middle; }
#preview { max-width: 100%; height: auto; border-radius: 8px; display: block; }
.picking { cursor: crosshair; }
.sample-box { margin: 0 0 14px; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 8px; pointer-events: none; }

.info { margin: 12px 0 4px; color: var(--ok); font-weight: 600; }
.clean-note { margin: 0 0 12px; color: var(--muted); font-size: 15px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

.result-box { text-align: center; background: var(--primary-soft); border-radius: 14px; padding: 14px 12px; margin-bottom: 14px; }
.result-label { margin: 0; color: var(--muted); }
.result-percent { margin: 0; font-size: clamp(36px, 9vw, 56px); font-weight: 700; color: var(--primary-dark); line-height: 1.3; }
.result-counts { margin: 0; color: var(--muted); font-size: 15px; }

.check { display: flex; align-items: center; gap: 10px; margin: 4px 0 8px; cursor: pointer; }
.check input { width: 20px; height: 20px; }
.legend { list-style: none; margin: 0 0 12px; padding: 0; color: var(--muted); font-size: 15px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: middle; margin-inline-end: 4px; }
.swatch-tooth { background: #61a68b; }
.swatch-plaque { background: #dc3228; }
.formula { margin: 0 0 14px; padding: 10px 12px; background: var(--bg); border-radius: 10px; font-size: 15px; color: var(--text); }

.groups { display: grid; gap: 14px; margin-bottom: 8px; }
@media (min-width: 720px) { .groups { grid-template-columns: 1fr 1fr; } }
.group { border: 1px solid var(--line); border-radius: 14px; padding: 8px 14px 12px; margin: 0; min-width: 0; }
.group legend { padding: 0 8px; font-weight: 600; }
.slider-row { display: grid; grid-template-columns: 8.5em 1fr 3em; align-items: center; gap: 10px; margin-top: 6px; }
.slider-row label { font-size: 15px; }
.slider-row input[type="range"] { width: 100%; direction: ltr; accent-color: var(--primary); }
.slider-value { text-align: center; font-variant-numeric: tabular-nums; color: var(--primary-dark); font-weight: 600; }
@media (max-width: 480px) { .slider-row { grid-template-columns: 7em 1fr 2.6em; gap: 6px; } }

.engine { margin: 0 0 8px; text-align: center; color: var(--muted); font-size: 14px; }
.engine.ok { color: var(--ok); }
.engine.fail { color: var(--danger); }

.foot { text-align: center; color: var(--muted); font-size: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.foot p { margin: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (max-width: 480px) {
  body { font-size: 16px; }
  .card { padding: 16px; }
  .dropzone { padding: 22px 12px; }
  .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .dropzone { transition: none; }
}

/* لمسات الواجهة الزاهية */
.card { box-shadow: var(--shadow); border-color: #ddeefa; }
.head h1 { background: linear-gradient(90deg, var(--primary-dark), var(--primary) 55%, var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.btn-primary { background: linear-gradient(180deg, #0ea5e9, var(--primary)); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled, .btn-ghost:disabled { opacity: .55; cursor: not-allowed; }
.result-box { background: linear-gradient(135deg, #e3f3fd, #e8fbf7); border: 1px solid #cfe9fa; }
.stain-box { background: #f4faff; }
.jaw-table th { background: #e3f3fd; }

/* الموبايل: أزرار التكبير بسطر واحد بدل كل زر بسطر */
@media (max-width: 480px) {
  .zoom-bar .btn { width: auto; flex: 1 1 0; padding: 4px 8px; }
  .zoom-bar .zoom-label { min-width: 3em; }
}

/* مقارنة قبل وبعد */
.cmp-grid { display: grid; gap: 14px; margin: 10px 0; }
@media (min-width: 720px) { .cmp-grid { grid-template-columns: 1fr 1fr; } }
.cmp-slot { border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: #f8fcff; min-width: 0; }
.cmp-title { margin: 0 0 8px; font-size: 18px; color: var(--primary-dark); }
.cmp-label { display: block; margin: 0 0 10px; font-weight: 700; color: var(--primary-dark); }
.cmp-label span { display: block; margin-bottom: 5px; }
.cmp-label input { display: block; width: 100%; box-sizing: border-box; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; font: inherit; font-weight: 400; color: inherit; background: #fff; }
.cmp-canvas { display: block; width: 100%; height: auto; border-radius: 10px; margin: 8px 0; background: #e6f2fb; }
.cmp-res { margin: 4px 0 8px; font-weight: 700; color: var(--primary-dark); }
.cmp-summary { margin: 8px 0 12px; }
.cmp-headline { margin: 0 0 10px; padding: 12px 14px; border-radius: 12px; font-size: 19px; font-weight: 700;
  background: linear-gradient(135deg, #e3f3fd, #e8fbf7); border: 1px solid #cfe9fa; color: var(--text); }
.cmp-headline.better { border-color: #9be3c4; }
.cmp-headline.worse { border-color: #f2c1bc; }
.edit-banner { margin: 0 0 12px; padding: 10px 12px; border-radius: 12px; background: #fff6e0; border: 1px solid #f3d48a; }
.edit-banner p { margin: 0 0 6px; font-weight: 600; color: #7a4f00; }

/* سجل النتائج */
.log-form { display: grid; gap: 10px; margin: 8px 0 4px; }
@media (min-width: 720px) { .log-form { grid-template-columns: 1fr 2fr; } }
.log-field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.log-field input { font: inherit; min-height: 42px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--text); }
.log-field input:focus-visible { outline: 3px solid #f0b429; outline-offset: 1px; }
.type-note.ok { color: var(--ok); }
.log-del { font: inherit; font-size: 14px; padding: 2px 10px; border-radius: 8px; border: 1px solid #efc5c1; background: #fff; color: var(--danger); cursor: pointer; }

/* ترتيب مساحة العمل: الصورة جنب التحليل على الشاشات العريضة، والصورة تبقى ثابتة وأنت تنزل */
.sub-title { margin: 4px 0 8px; font-size: 17px; color: var(--primary-dark); }
.thresholds { margin: 0 0 14px; padding: 10px 12px; border: 1px solid #cfe9fa; border-radius: 14px; background: #f7fbff; }
details.help { margin: 6px 0 10px; }
details.help > summary { cursor: pointer; color: var(--primary-dark); font-weight: 600; font-size: 15px; }
details.help > summary:focus-visible { outline: 3px solid #f0b429; outline-offset: 2px; }
details.help .clean-note { margin-top: 6px; }
@media (min-width: 1200px) {
  .page { max-width: 1500px; }
  .page > .card, .page > .head, .page > .engine, .page > .foot { max-width: 1000px; margin-inline: auto; }
  .page > .card { margin-bottom: 16px; }
  .workspace { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(420px, 1fr); gap: 16px; align-items: start; }
  .workspace > #result { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; margin-bottom: 16px; }
  .workspace .groups { grid-template-columns: 1fr; }
  .workspace .slider-row { grid-template-columns: 8em 1fr 3em; }
}

/* النتيجة فوق الصورة مباشرة، حتى تبين وأنت تحرّك العتبات */
.live-result { margin: 0 0 8px; padding: 6px 12px; border-radius: 10px; background: #e3f3fd; border: 1px solid #cfe9fa;
  font-weight: 700; color: var(--primary-dark); text-align: center; }

.type-help { margin: 6px 0; padding-inline-start: 20px; }
.type-help li { margin-bottom: 4px; }

/* ممحاة اللثة */
.erase-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0 0 8px; padding: 8px 10px; border: 1px solid #f3c7e6; border-radius: 12px; background: #fff5fb; }
.erase-panel .clean-note { flex-basis: 100%; margin: 0; }
.erase-size { display: flex; align-items: center; gap: 8px; font-weight: 600; flex: 1 1 240px; }
.erase-size input { flex: 1; min-width: 100px; direction: ltr; accent-color: #d6249f; }
#erase-tool[aria-pressed="true"] { background: #d6249f; border-color: #d6249f; color: #fff; }
.canvas-wrap .stack.erasing, .canvas-wrap .stack.erasing canvas { cursor: crosshair; touch-action: none; }
@media (max-width: 520px) { #stain-mode { width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; } }
.erase-ring.brush { border-color: #00e676; }
.erase-ring.brush-plaque { border-color: #ff3b30; }
.erase-ring { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 1px #000; border-radius: 50%; pointer-events: none; transform: translate(-50%, -50%); }

/* تذييل: معلومات المطوّر والتواصل */
.credit { max-width: 560px; margin: 16px auto 0; padding: 18px 20px; text-align: center; background: #fff; border: 1px solid var(--line); border-top: 3px solid var(--primary); border-radius: 14px; }
.credit p { margin: 0; }
.credit-by { font-size: 16px; color: var(--text); }
.credit-name { font-weight: 800; color: var(--primary-dark); white-space: nowrap; }
.credit-contact { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 8px; margin-top: 8px !important; font-size: 14px; color: var(--text); }
.credit-mail { font-weight: 700; color: var(--primary-dark); text-decoration: none; overflow-wrap: anywhere; }
.credit-mail:hover { text-decoration: underline; }
.credit-mail:focus-visible { outline: 3px solid #f0b429; outline-offset: 2px; border-radius: 4px; }

/* زر اللغة بزاوية أعلى الصفحة */
.head { position: relative; }
.lang-btn { position: absolute; top: 0; inset-inline-end: 0; font: inherit; font-size: 14px; font-weight: 700; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--primary-dark); cursor: pointer; }
.lang-btn:hover { background: var(--primary-soft); }
.lang-btn:focus-visible { outline: 3px solid #f0b429; outline-offset: 2px; }
@media (max-width: 600px) { .head { padding-top: 40px; } }

/* عن المنصة */
.about-lead { margin: 0 0 10px; line-height: 1.8; }
.about-points { margin: 0 0 10px; padding-inline-start: 20px; line-height: 1.8; }
.about-points li { margin: 4px 0; }
.about-private strong { color: var(--primary-dark); }
.about-note { margin: 0; padding: 8px 12px; border-radius: 10px; background: var(--primary-soft); font-size: 14px; color: var(--text); }

/* صفحات الشرح (المنهجية) */
.foot-links { margin-top: 8px !important; }
.foot a, .doc-back a, .doc-langs a { color: var(--primary-dark); font-weight: 700; text-decoration: none; }
.foot a:hover, .doc-back a:hover, .doc-langs a:hover { text-decoration: underline; }
.doc-back, .doc-langs { margin: 0 0 8px; font-size: 14px; }
.doc-langs { margin-top: 10px; }
.doc h3 { margin: 22px 0 8px; font-size: 18px; color: var(--primary-dark); }
.doc p, .doc li { line-height: 1.8; }
.doc ul { padding-inline-start: 22px; }
.doc-note { padding: 10px 14px; border-radius: 10px; background: #fff8e6; border: 1px solid #f3dfa6; }
.doc-formula { padding: 10px 14px; border-radius: 10px; background: var(--primary-soft); font-weight: 700; text-align: center; }
.doc-cite { padding: 10px 14px; border-radius: 10px; background: #f4f8fb; border: 1px solid var(--line); text-align: start; overflow-wrap: anywhere; }
.doc-table td, .doc-table th { white-space: normal; }
.doc-page > .card { max-width: 1000px; margin-inline: auto; }
.nowrap { white-space: nowrap; }
.app-version { margin-top: 6px !important; font-size: 13px; color: var(--muted); }
