/* ===== Reset & Variables ===== */
:root {
  --green:        #16a34a;
  --green-dark:   #15803d;
  --green-light:  #dcfce7;
  --green-bg:     #f0fdf4;
  --red:          #dc2626;
  --red-light:    #fef2f2;
  --amber:        #d97706;
  --amber-light:  #fffbeb;
  --amber-border: #fde68a;
  --border:       #d1fae5;
  --text:         #1a2e1a;
  --muted:        #4b6e4b;
  --surface:      #ffffff;
  --radius:       14px;
  --radius-sm:    8px;
  --radius-xs:    6px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--green-bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

[lang="ar"] body, body.rtl {
  font-family: 'Tajawal', system-ui, sans-serif;
}

.hidden { display: none !important; }

/* ===== Disclaimer Bar ===== */
.disclaimer-bar {
  background: var(--amber-light);
  border-bottom: 1.5px solid var(--amber-border);
  padding: 10px 24px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.87rem;
  color: #78350f;
  font-weight: 500;
  line-height: 1.5;
}
.disc-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }

/* ===== Header ===== */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 8px rgba(0,0,0,.06);
  position: sticky; top: 0; z-index: 100;
}
.header-inner {
  max-width: 1100px; margin: 0 auto; padding: 13px 24px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon { font-size: 1.9rem; }
.logo-title { font-size: 1.15rem; font-weight: 700; color: var(--green-dark); }
.logo-subtitle { font-size: 0.73rem; color: var(--muted); margin-top: 1px; }

.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.badge {
  font-size: 0.71rem; font-weight: 600; padding: 4px 10px;
  border-radius: 999px; white-space: nowrap;
}
.badge-ai      { background: #dbeafe; color: #1e40af; }
.badge-explain { background: var(--green-light); color: var(--green-dark); }

/* Language Button */
.lang-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface);
  border: 2px solid var(--green);
  color: var(--green);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.83rem; font-weight: 700;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, transform 0.12s;
  font-family: inherit;
  user-select: none;
}
.lang-btn:hover { background: var(--green); color: #fff; }
.lang-btn:active { transform: scale(0.95); }
.lang-flag { font-size: 1rem; }

/* ===== Hero ===== */
.hero {
  max-width: 1100px; margin: 24px auto 0; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; flex-wrap: wrap;
}
.hero-text h2 { font-size: 1.55rem; font-weight: 700; color: var(--green-dark); }
.hero-text p  { margin-top: 7px; color: var(--muted); font-size: 0.95rem; max-width: 460px; line-height: 1.6; }
.hero-stats { display: flex; gap: 28px; }
.stat { text-align: center; }
.stat-value { display: block; font-size: 1.55rem; font-weight: 700; color: var(--green); }
.stat-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ===== Main ===== */
.main { flex: 1; max-width: 1100px; margin: 0 auto; padding: 20px 24px 40px; width: 100%; }

/* ===== Grid ===== */
.content-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 18px; margin-top: 18px;
}
@media(max-width:720px) { .content-grid { grid-template-columns: 1fr; } }

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 14px rgba(0,0,0,.06);
  padding: 24px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; gap: 8px; flex-wrap: wrap;
}
.card-header h3 { font-size: 1.05rem; font-weight: 600; }
.card-hint { font-size: 0.73rem; color: var(--muted); }

/* ===== Upload Card ===== */
.upload-card { display: flex; flex-direction: column; gap: 16px; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--green-bg);
  min-height: 190px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative; overflow: hidden;
  transition: border-color 0.2s, background 0.2s;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--green);
  background: var(--green-light);
}
.dropzone-idle { text-align: center; padding: 20px; pointer-events: none; }
.drop-icon { font-size: 2.4rem; margin-bottom: 10px; }
.drop-main { font-size: 0.97rem; font-weight: 500; color: var(--text); }
.drop-main .link { color: var(--green); text-decoration: underline; cursor: pointer; }
.drop-sub  { font-size: 0.78rem; color: var(--muted); margin-top: 5px; }

.dropzone-preview {
  width: 100%; height: 190px;
  display: flex; align-items: center; justify-content: center;
}
.dropzone-preview img {
  max-width: 100%; max-height: 100%;
  object-fit: contain; border-radius: var(--radius-sm);
}
.remove-btn {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,.45); color: #fff; border: none;
  border-radius: 50%; width: 28px; height: 28px;
  font-size: 0.85rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.18s, transform 0.12s;
  font-family: inherit;
}
.remove-btn:hover { background: var(--red); }
.remove-btn:active { transform: scale(0.9); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; padding: 12px 22px;
  border-radius: var(--radius-sm); border: none;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  transition: background 0.18s, transform 0.12s, box-shadow 0.18s, opacity 0.18s;
  width: 100%; font-family: inherit;
  position: relative; overflow: hidden;
}
.btn:active:not(:disabled) { transform: scale(0.97); }

.btn-primary {
  background: var(--green); color: #fff;
  box-shadow: 0 3px 10px rgba(22,163,74,.35);
}
.btn-primary:hover:not(:disabled) {
  background: var(--green-dark);
  box-shadow: 0 4px 16px rgba(22,163,74,.45);
}
.btn-primary:disabled { opacity: 0.42; cursor: not-allowed; }

.btn-secondary {
  background: var(--green-light); color: var(--green-dark);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: #bbf7d0; }

/* Button ripple */
.btn::after {
  content: ''; position: absolute;
  border-radius: 50%; background: rgba(255,255,255,.35);
  width: 0; height: 0;
  transform: translate(-50%,-50%);
  transition: width 0.4s ease, height 0.4s ease, opacity 0.4s ease;
  opacity: 0;
}
.btn.ripple::after {
  width: 300px; height: 300px; opacity: 1;
}

.btn-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* Tips */
.upload-tips { font-size: 0.8rem; color: var(--muted); line-height: 1.65; }
.upload-tips p { font-weight: 600; margin-bottom: 4px; }
.upload-tips ul { padding-left: 16px; }

/* ===== Result Card ===== */
.result-card { display: flex; flex-direction: column; min-height: 300px; }

.result-idle {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--muted); text-align: center; gap: 14px;
}
.idle-icon { font-size: 3rem; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }

.result-loading {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; text-align: center;
}
.loading-sub { font-size: 0.8rem; color: var(--muted); }

.spinner-large {
  width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid var(--border);
  border-top-color: var(--green);
  animation: spin 0.85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-success { display: flex; flex-direction: column; gap: 16px; }

/* Classification banner */
.class-banner {
  border-radius: var(--radius-sm); padding: 16px 18px;
  display: flex; align-items: center; gap: 14px;
  animation: fadeSlide 0.35s ease;
}
@keyframes fadeSlide { from{opacity:0;transform:translateY(-8px)} to{opacity:1;transform:translateY(0)} }
.class-banner.healthy  { background: #f0fdf4; border: 1.5px solid #86efac; }
.class-banner.infected { background: var(--red-light); border: 1.5px solid #fca5a5; }
.banner-icon { font-size: 2rem; }
.banner-label { font-size: 1.2rem; font-weight: 700; }
.class-banner.healthy  .banner-label { color: #15803d; }
.class-banner.infected .banner-label { color: var(--red); }
.banner-conf { font-size: 0.88rem; color: var(--muted); margin-top: 2px; }

/* Probability bars */
.prob-section h4 {
  font-size: 0.78rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px;
}
.prob-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.prob-label { font-size: 0.85rem; font-weight: 500; width: 65px; flex-shrink: 0; }
.prob-track { flex: 1; background: var(--green-bg); border-radius: 999px; height: 10px; overflow: hidden; }
.prob-fill { height: 100%; border-radius: 999px; width: 0; transition: width 0.7s cubic-bezier(.4,0,.2,1); }
.fill-healthy  { background: #22c55e; }
.fill-infected { background: var(--red); }
.prob-val { font-size: 0.82rem; font-weight: 700; width: 46px; text-align: right; flex-shrink: 0; }

.timing-row { font-size: 0.8rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }

.warn-box {
  background: var(--amber-light); border: 1px solid var(--amber-border);
  border-radius: var(--radius-xs); padding: 10px 13px;
  font-size: 0.82rem; color: #78350f;
}

/* ===== Feedback Card ===== */
.feedback-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  background: var(--green-bg);
  display: flex; flex-direction: column; gap: 12px;
  animation: fadeSlide 0.4s ease 0.1s both;
}
.fb-question { font-size: 0.92rem; font-weight: 600; color: var(--text); }

.fb-btns { display: flex; gap: 10px; }

.fb-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 0.88rem; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: background 0.18s, border-color 0.18s, transform 0.12s, color 0.18s;
  color: var(--text);
  position: relative; overflow: hidden;
}
.fb-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.fb-btn:active { transform: scale(0.96); }

.fb-yes:hover { background: #f0fdf4; border-color: #22c55e; color: #15803d; }
.fb-no:hover  { background: var(--red-light); border-color: var(--red); color: var(--red); }

.fb-btn.selected-yes {
  background: #f0fdf4; border-color: #22c55e; color: #15803d;
  animation: pulse-green 0.4s ease;
}
.fb-btn.selected-no {
  background: var(--red-light); border-color: var(--red); color: var(--red);
  animation: pulse-red 0.4s ease;
}
@keyframes pulse-green { 0%{box-shadow:0 0 0 0 rgba(34,197,94,.5)} 100%{box-shadow:0 0 0 8px rgba(34,197,94,0)} }
@keyframes pulse-red   { 0%{box-shadow:0 0 0 0 rgba(220,38,38,.5)} 100%{box-shadow:0 0 0 8px rgba(220,38,38,0)} }

.fb-thumb { font-size: 1.1rem; transition: transform 0.2s; }
.fb-btn:hover .fb-thumb { transform: scale(1.25) rotate(-8deg); }

/* Training progress bar */
.fb-training {
  display: flex; flex-direction: column; gap: 6px;
  animation: fadeSlide 0.3s ease;
}
.fb-train-label { font-size: 0.83rem; font-weight: 600; color: var(--green-dark); }
.fb-train-track {
  height: 10px; background: var(--border); border-radius: 999px; overflow: hidden;
}
.fb-train-fill {
  height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--green), #22c55e);
  transition: width 0.1s linear;
  position: relative;
}
.fb-train-fill::after {
  content: ''; position: absolute; right: 0; top: 0; bottom: 0;
  width: 20px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.5));
  animation: shimmer 1s infinite;
}
@keyframes shimmer { 0%{opacity:0} 50%{opacity:1} 100%{opacity:0} }
.fb-train-pct { font-size: 0.78rem; font-weight: 700; color: var(--green); text-align: right; }

.fb-done {
  display: flex; align-items: center; gap: 8px;
  background: var(--green-light); border: 1px solid #86efac;
  border-radius: var(--radius-xs); padding: 10px 13px;
  font-size: 0.88rem; font-weight: 600; color: var(--green-dark);
  animation: fadeSlide 0.35s ease;
}
.fb-done-icon { font-size: 1.1rem; }

/* ===== Error ===== */
.result-error {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; text-align: center;
}
.err-icon { font-size: 2rem; }
.err-msg  { color: var(--red); font-size: 0.9rem; max-width: 260px; }

/* ===== Grad-CAM ===== */
.gradcam-card { margin-top: 18px; }
.gradcam-body { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: start; }
@media(max-width:720px) { .gradcam-body { grid-template-columns: 1fr; } }
.gradcam-img { width: 100%; border-radius: var(--radius-sm); box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.gradcam-legend { min-width: 200px; font-size: 0.81rem; }
.leg-title { font-weight: 600; margin-bottom: 10px; }
.leg-row { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.leg-dot { width: 13px; height: 13px; border-radius: 50%; flex-shrink: 0; }
.leg-dot.red    { background: #ef4444; }
.leg-dot.yellow { background: #f59e0b; }
.leg-dot.blue   { background: #3b82f6; }
.leg-note {
  margin-top: 12px; color: var(--muted); font-style: italic;
  border-top: 1px solid var(--border); padding-top: 10px; line-height: 1.5;
}

/* ===== Footer ===== */
.footer {
  text-align: center; padding: 20px 24px;
  font-size: 0.79rem; color: var(--muted);
  border-top: 1px solid var(--border);
}
.footer-sub { margin-top: 3px; font-size: 0.71rem; }

/* ===== RTL ===== */
[dir="rtl"] .header-inner       { flex-direction: row-reverse; }
[dir="rtl"] .logo                { flex-direction: row-reverse; }
[dir="rtl"] .header-right        { flex-direction: row-reverse; }
[dir="rtl"] .hero                { flex-direction: row-reverse; }
[dir="rtl"] .prob-row            { flex-direction: row-reverse; }
[dir="rtl"] .prob-val            { text-align: left; }
[dir="rtl"] .class-banner        { flex-direction: row-reverse; }
[dir="rtl"] .fb-btns             { flex-direction: row-reverse; }
[dir="rtl"] .leg-row             { flex-direction: row-reverse; }
[dir="rtl"] .timing-row          { flex-direction: row-reverse; }
[dir="rtl"] .disclaimer-bar      { flex-direction: row-reverse; }
[dir="rtl"] .upload-tips ul      { padding-left: 0; padding-right: 16px; }
[dir="rtl"] .remove-btn          { right: auto; left: 8px; }
[dir="rtl"] .fb-train-fill::after { right: auto; left: 0; }
[dir="rtl"] .fb-train-pct        { text-align: left; }

/* ===== Backend integration additions ===== */
.fb-note {
  font-size: 0.76rem; color: var(--muted); line-height: 1.5; margin-top: -4px;
}
.footer-link { color: var(--green-dark); text-decoration: underline; font-weight: 600; }
.footer-link:hover { color: var(--green); }
.stat-ci { display: block; font-size: 0.62rem; color: var(--muted); margin-top: 2px; font-weight: 500; }
.threshold-note { font-size: 0.76rem; color: var(--muted); margin-top: 6px; }
