:root {
  --ink: #0e1116;
  --ink-soft: #3a4150;
  --muted: #6b7180;
  --line: #e6e2d8;
  --bg: #fbf9f4;
  --paper: #ffffff;
  --teal: #1f6f6f;
  --teal-deep: #0f4646;
  --teal-soft: #e8f1f0;
  --gold: #b8893a;
  --gold-soft: #fbf6e8;
  --red: #b83a3a;
  --green: #2d7a4a;
  --amber: #c98a13;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Tajawal', system-ui, sans-serif;
  color: var(--ink); background: var(--bg);
  line-height: 1.5; font-size: 15px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 28px;
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-deep) 100%);
  color: #fff;
  border-bottom: 4px solid var(--gold);
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--gold); display: flex; align-items: center; justify-content: center;
  font-family: 'Amiri', serif; font-weight: 700; font-size: 32px; color: var(--teal-deep);
}
.brand h1 { font-family: 'Amiri', serif; font-size: 28px; margin: 0; line-height: 1; }
.brand .tag { font-size: 12px; opacity: 0.85; margin-top: 4px; color: #f4d795; }
.env-badge {
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3);
  padding: 6px 14px; border-radius: 999px; font-size: 12px; font-weight: 700;
  letter-spacing: 1px;
}

.layout {
  display: grid; grid-template-columns: 1fr 1.2fr;
  gap: 24px; padding: 24px 28px;
  max-width: 1400px; margin: 0 auto;
  min-height: calc(100vh - 160px);
}

.upload-card, .samples-card, .preview-card,
.status-card, .result-card {
  background: var(--paper);
  border: 1px solid var(--line); border-radius: 12px;
  margin-bottom: 18px; box-shadow: 0 2px 12px rgba(15,70,70,0.04);
}

.drop-zone {
  padding: 48px 24px; text-align: center;
  border: 2px dashed var(--line); border-radius: 10px; margin: 14px;
  cursor: pointer; transition: all 0.2s;
  background: var(--bg);
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--teal); background: var(--teal-soft);
}
.drop-icon { font-size: 42px; margin-bottom: 10px; }
.drop-title { font-weight: 700; font-size: 16px; color: var(--ink); }
.drop-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }

.samples-card { padding: 16px; }
.samples-title { font-size: 13px; color: var(--muted); margin-bottom: 12px; font-weight: 500; }
.samples-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.sample-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper); cursor: pointer; text-align: right;
  font-family: inherit; transition: all 0.15s;
}
.sample-btn:hover {
  border-color: var(--teal); background: var(--teal-soft);
  transform: translateY(-1px);
}
.sample-btn .lbl { font-size: 14px; font-weight: 700; color: var(--ink); }
.sample-btn .sub { font-size: 11px; color: var(--muted); letter-spacing: 0.5px; }

.preview-card { padding: 14px; }
.preview-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.preview-name { font-size: 13px; color: var(--muted); }
.reset-btn {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 12px; cursor: pointer; font-family: inherit; font-size: 12px;
}
.reset-btn:hover { background: var(--gold-soft); border-color: var(--gold); }
#previewImg { width: 100%; border-radius: 8px; display: block; max-height: 500px; object-fit: contain; background: var(--bg); }

.status-card { padding: 28px 20px; }
.status-empty {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  color: var(--muted); padding: 32px 12px; text-align: center;
}
.status-icon { font-size: 32px; opacity: 0.5; }
.status-empty .status-icon.spinning {
  display: inline-block; animation: spin 1s linear infinite; color: var(--teal); opacity: 1;
}
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.status-error {
  background: #fef7f6; border: 1px solid #f0cfcc; color: var(--red);
  padding: 14px 16px; border-radius: 8px; font-size: 14px;
}

.result-card { padding: 0; overflow: hidden; }

.result-head {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--gold-soft); border-bottom: 1px solid var(--line);
}
.result-meta { padding: 12px 14px; border-left: 1px solid var(--line); }
.result-meta:last-child { border-left: 0; }
.meta-label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; letter-spacing: 0.5px; }
.meta-value { font-size: 14px; font-weight: 700; color: var(--ink); }
.confidence-pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px;
}
.conf-high { background: #d8efde; color: var(--green); }
.conf-med { background: #faecc4; color: var(--amber); }
.conf-low { background: #f4d4d1; color: var(--red); }

.section-title {
  font-size: 13px; color: var(--muted); font-weight: 700;
  letter-spacing: 1px; padding: 14px 18px 6px;
}

.fields-section { padding: 0 0 12px; }
.fields-list { display: grid; gap: 0; }
.field-row {
  display: grid; grid-template-columns: 200px 1fr 70px;
  align-items: center; padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  gap: 12px;
}
.field-row:last-child { border-bottom: 0; }
.field-row:hover { background: var(--bg); }
.field-name { color: var(--muted); font-size: 12px; font-weight: 500; }
.field-val { color: var(--ink); font-weight: 500; word-break: break-word; }
.field-val.null { color: #b8b8b8; font-style: italic; }
.field-val.array { font-family: 'JetBrains Mono', monospace; font-size: 13px; }
.field-conf {
  text-align: center; font-size: 11px; font-weight: 700;
  padding: 3px 0; border-radius: 999px;
}

.raw-section, .json-section { padding: 12px 18px; border-top: 1px solid var(--line); }
.raw-section summary, .json-section summary {
  cursor: pointer; font-size: 13px; color: var(--muted); font-weight: 700;
  padding: 6px 0;
}
.raw-text, .json-out {
  font-family: 'JetBrains Mono', monospace; font-size: 12px;
  background: var(--bg); padding: 14px; border-radius: 8px;
  max-height: 280px; overflow: auto; margin-top: 10px;
  white-space: pre-wrap; word-break: break-word;
  color: var(--ink-soft); direction: ltr; text-align: left;
}
.copy-btn {
  margin-top: 8px; background: var(--teal); color: #fff;
  border: 0; padding: 6px 14px; border-radius: 6px;
  font-family: inherit; font-size: 12px; cursor: pointer;
}
.copy-btn:hover { background: var(--teal-deep); }

.notes {
  background: var(--gold-soft); border-right: 3px solid var(--gold);
  padding: 12px 18px; margin: 0 18px 16px; border-radius: 6px;
  font-size: 13px; color: var(--ink-soft);
}

.footer {
  text-align: center; padding: 18px 24px;
  font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--line); background: var(--paper);
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 12px;
}
.footer-links { display: flex; gap: 18px; }
.footer a { color: var(--teal); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .samples-grid { grid-template-columns: 1fr; }
  .result-head { grid-template-columns: repeat(2, 1fr); }
  .result-meta { border-bottom: 1px solid var(--line); }
  .field-row { grid-template-columns: 1fr; gap: 4px; padding: 12px 16px; }
  .field-conf { justify-self: start; }
}
