/* ============================================================
   Uyghur OCR — main stylesheet
   UTF-8, RTL-aware, responsive, accessible
   ============================================================ */

/* ── UKIJ Tuz Kitab — Uyghur Arabic script font ───────────── */
@font-face {
  font-family: "UKIJ Tuz Kitab";
  src: url("../fonts/UKIJTuzKitab.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg:       #ffffff;
  --surface:  #f7f8fa;
  --border:   #e5e7eb;
  --text:     #1f2328;
  --muted:    #57606a;
  --accent:   #3b82d4;
  --accent-h: #2563b8;
  --danger:   #d93025;
  --success:  #1a7f37;
  --warning:  #9a6700;
  --radius:   8px;
  --shadow:   0 1px 4px rgba(0,0,0,.08);
  --font:     -apple-system, "Segoe UI", system-ui, sans-serif;
  --font-uyghur: "UKIJ Tuz Kitab", "UKIJ Tuz", "Alkatip", serif;
}

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

html { font-size: 15px; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Layout ────────────────────────────────────────────────── */
.page-wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px 64px;
}

/* ── Header ────────────────────────────────────────────────── */
.site-header {
  padding: 24px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.site-header-text { flex: 1; min-width: 0; }

.site-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.site-header .subtitle {
  font-size: .85rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ── UI language switcher ───────────────────────────────────── */
.ui-lang-switcher {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.ui-lang-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--muted);
  font-size: .8rem;
  cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
  white-space: nowrap;
  font-family: var(--font);
}

.ui-lang-btn:hover { border-color: var(--accent); color: var(--accent); }
.ui-lang-btn.active {
  border-color: var(--accent);
  background: #eff6ff;
  color: var(--accent-h);
  font-weight: 600;
}
.ui-lang-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* When Uyghur Arabic UI is active: use UKIJ font for page chrome */
:root[lang="ug"][dir="rtl"] body {
  font-family: var(--font-uyghur);
  font-size: 16px;
}

/* Uyghur Arabic UI: card titles, buttons, labels use UKIJ font */
:root[lang="ug"][dir="rtl"] .card-title,
:root[lang="ug"][dir="rtl"] .btn,
:root[lang="ug"][dir="rtl"] .lang-label,
:root[lang="ug"][dir="rtl"] .hint-text,
:root[lang="ug"][dir="rtl"] .drop-text,
:root[lang="ug"][dir="rtl"] .subtitle,
:root[lang="ug"][dir="rtl"] h1,
:root[lang="ug"][dir="rtl"] h2 {
  font-family: var(--font-uyghur);
}

/* Uyghur Arabic: switcher buttons themselves stay in their own fonts */
.ui-lang-btn[data-uilang="ug-Arab"] { font-family: var(--font-uyghur); font-size: .85rem; }
.ui-lang-btn[data-uilang="ug-Latn"] { font-family: var(--font); }
.ui-lang-btn[data-uilang="en"]      { font-family: var(--font); }

/* ── Card ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 12px;
}

/* ── Drop zone ─────────────────────────────────────────────── */
#drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--bg);
  position: relative;
}

#drop-zone:hover,
#drop-zone.drag-over {
  border-color: var(--accent);
  background: #eff6ff;
}

#drop-zone .drop-icon {
  font-size: 2.2rem;
  line-height: 1;
  margin-bottom: 10px;
  color: var(--muted);
}

#drop-zone .drop-text {
  color: var(--muted);
  font-size: .9rem;
}

#drop-zone .drop-text strong {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

#drop-zone .drop-hint {
  margin-top: 6px;
  font-size: .78rem;
  color: var(--muted);
}

#file-input { display: none; }

/* ── File list ─────────────────────────────────────────────── */
#file-list {
  list-style: none;
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: .88rem;
}

.file-item .file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.file-item .file-size {
  color: var(--muted);
  font-size: .8rem;
  white-space: nowrap;
}

.file-item .remove-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}
.file-item .remove-btn:hover { color: var(--danger); background: #fef2f2; }
.file-item .remove-btn:focus-visible { outline: 2px solid var(--accent); }

/* ── URL input row ─────────────────────────────────────────── */
.url-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}

.url-row input[type="url"],
.url-row input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}
.url-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.hint-text {
  margin-top: 8px;
  font-size: .78rem;
  color: var(--muted);
}

/* ── Language selector ─────────────────────────────────────── */
.lang-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.lang-option {
  display: none; /* hidden radio */
}

.lang-label {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: .85rem;
  cursor: pointer;
  background: var(--bg);
  transition: border-color .12s, background .12s;
  white-space: nowrap;
}

.lang-option:checked + .lang-label {
  border-color: var(--accent);
  background: #eff6ff;
  color: var(--accent-h);
  font-weight: 600;
}

.lang-label:hover {
  border-color: var(--accent);
}

.lang-option:focus-visible + .lang-label {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: .9rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-h); border-color: var(--accent-h); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface); }
.btn-secondary:disabled { opacity: .45; cursor: not-allowed; }

.btn-sm {
  padding: 5px 11px;
  font-size: .82rem;
}

.btn-danger {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}
.btn-danger:hover { background: #fee2e2; }

.action-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

#recognize-btn {
  font-size: 1rem;
  padding: 11px 28px;
}

/* ── Progress / status ─────────────────────────────────────── */
#status-area {
  margin: 12px 0;
}

.progress-bar-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width .3s ease;
  width: 0%;
}

.status-text {
  font-size: .85rem;
  color: var(--muted);
}

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: .88rem;
  margin-bottom: 12px;
  border: 1px solid transparent;
}
.alert-error   { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: var(--warning); }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }

/* ── Results ───────────────────────────────────────────────── */
#results-section {
  margin-top: 28px;
}

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

.results-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.result-file {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}

.result-file-header {
  background: var(--surface);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.result-file-name {
  font-weight: 600;
  font-size: .92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 360px;
}

.result-file-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.result-page {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.result-page:last-child { border-bottom: none; }

.result-page-label {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-page-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.result-textarea {
  width: 100%;
  min-height: 120px;
  max-height: 480px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  font-family: var(--font);
  line-height: 1.7;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
}

.result-textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* RTL textarea for Uyghur — right-aligned, UKIJ Tuz Kitab font */
.result-textarea[dir="rtl"] {
  font-family: var(--font-uyghur);
  font-size: 1.05rem;
  line-height: 2;
  direction: rtl;
  text-align: right;
  unicode-bidi: embed;
}

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: .92rem;
}

/* ── Spinner ───────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Hidden utility ────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 600px) {
  .card { padding: 16px; }
  .url-row { flex-direction: column; }
  .action-row { flex-direction: column; align-items: stretch; }
  #recognize-btn { width: 100%; justify-content: center; }
  .results-header { flex-direction: column; align-items: flex-start; }
  .result-file-header { flex-direction: column; align-items: flex-start; }
  .result-file-name { max-width: 100%; }
}

/* ── Focus-visible polyfill fallback ───────────────────────── */
:focus:not(:focus-visible) { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
