/* ── Language Detection Tool ────────────────────────────────────────────────── */
:root {
  --ld-brand: #1e1e2f;
  --ld-teal: #00dfd8;
  --ld-teal-dim: rgba(0, 223, 216, 0.12);
  --ld-border: #e5e7eb;
  --ld-surface: #f8fafc;
  --ld-muted: #6b7280;
  --ld-success: #10b981;
  --ld-warn: #f59e0b;
  --ld-danger: #ef4444;
  --ld-card: #ffffff;
  --ld-ink: #111827;
}

/* ── Detect Button States ─────────────────────────────────────────────────── */
#detectBtn {
  position: relative;
  overflow: hidden;
  transition: all 0.2s ease;
}

#detectBtn.detecting {
  opacity: 0.85;
  pointer-events: none;
}

#detectBtn.detecting::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.15) 50%,
    transparent 100%
  );
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* ── Text Stats Bar ───────────────────────────────────────────────────────── */
.text-stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--ld-surface);
  border: 1px solid var(--ld-border);
  border-radius: 10px;
  font-size: 0.82rem;
  color: var(--ld-muted);
}

.text-stats-bar .stat-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.text-stats-bar .stat-item strong {
  color: var(--ld-ink);
  font-weight: 700;
  font-size: 0.9rem;
}

/* ── Dropzone ─────────────────────────────────────────────────────────────── */
#dropZone {
  position: relative;
  transition:
    border-color 0.2s,
    background 0.2s;
}

#dropZone.drag-over {
  border-color: var(--ld-teal) !important;
  background: var(--ld-teal-dim) !important;
}

/* ── Direction Indicator ──────────────────────────────────────────────────── */
.dir-indicator {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  display: inline-block;
  margin-top: 6px;
  transition: all 0.3s;
}

.dir-ltr {
  background: rgba(99, 102, 241, 0.1);
  color: #6366f1;
}
.dir-rtl {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}
.dir-ttb {
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
}

/* ── Sample Menu ──────────────────────────────────────────────────────────── */
#sampleMenu {
  position: absolute;
  z-index: 50;
  top: calc(100% + 6px);
  left: 0;
  background: white;
  border: 1px solid var(--ld-border);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
  padding: 6px;
  min-width: 210px;
  max-height: 340px;
  overflow-y: auto;
}

.sample-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ld-ink);
  cursor: pointer;
  border: none;
  background: none;
  transition: background 0.15s;
}

.sample-item:hover {
  background: var(--ld-teal-dim);
  color: var(--ld-brand);
}

/* ── Results Placeholder ──────────────────────────────────────────────────── */
#resultsPlaceholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.placeholder-icon {
  font-size: 3.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.placeholder-text {
  color: var(--ld-muted);
  font-size: 0.95rem;
}

/* ── Primary Result Card ──────────────────────────────────────────────────── */
.primary-card {
  background: linear-gradient(135deg, #1e1e2f 0%, #2d2d4e 100%);
  border-radius: 16px;
  padding: 24px;
  color: white;
  position: relative;
  overflow: hidden;
}

.primary-card::before {
  content: "";
  position: absolute;
  top: -30px;
  right: -30px;
  width: 100px;
  height: 100px;
  background: radial-gradient(
    circle,
    rgba(0, 223, 216, 0.15) 0%,
    transparent 70%
  );
  border-radius: 50%;
}

#primaryFlag {
  font-size: 3rem;
  line-height: 1;
  display: block;
  margin-bottom: 8px;
}

#primaryName {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.1;
}

#primaryNative {
  font-size: 1rem;
  opacity: 0.7;
  margin-top: 2px;
}

.confidence-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}

.confidence-label {
  font-size: 0.8rem;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#primaryConfidence {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--ld-teal);
}

.conf-bar-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
  margin-top: 8px;
  overflow: hidden;
}

#primaryBar {
  height: 100%;
  border-radius: 3px;
  width: 0%;
  transition: width 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

.meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
}

.meta-chip {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  letter-spacing: 0.02em;
}

.meta-chip.dir-rtl {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.3);
}
.meta-chip.dir-ltr {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.3);
}
.meta-chip.dir-ttb {
  background: rgba(245, 158, 11, 0.2);
  border-color: rgba(245, 158, 11, 0.3);
}

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs-header {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--ld-border);
  margin-bottom: 16px;
}

.tab-btn {
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  background: none;
  color: var(--ld-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: all 0.15s;
  border-radius: 4px 4px 0 0;
}

.tab-btn:hover {
  color: var(--ld-ink);
}
.tab-btn.active {
  color: var(--ld-brand);
  border-bottom-color: var(--ld-brand);
}

/* ── Alt Language Items ───────────────────────────────────────────────────── */
.alt-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--ld-border);
}

.alt-item:last-child {
  border-bottom: none;
}

.alt-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.alt-flag {
  font-size: 1.3rem;
}
.alt-name {
  font-weight: 700;
  font-size: 0.95rem;
  flex: 1;
}
.alt-native {
  font-size: 0.8rem;
  color: var(--ld-muted);
}
.alt-pct {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ld-ink);
  min-width: 40px;
  text-align: right;
}

.alt-bar-track {
  height: 5px;
  background: #f1f5f9;
  border-radius: 3px;
  overflow: hidden;
}

.alt-bar-fill {
  height: 100%;
  border-radius: 3px;
  width: 0%;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.no-alt {
  color: var(--ld-muted);
  font-size: 0.88rem;
  text-align: center;
  padding: 16px;
}

/* ── Script Analysis ──────────────────────────────────────────────────────── */
.script-item {
  margin-bottom: 10px;
}

.script-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.script-name {
  font-weight: 600;
  color: var(--ld-ink);
}
.script-count {
  color: var(--ld-muted);
  font-size: 0.8rem;
}

.script-bar-track {
  height: 6px;
  background: #f1f5f9;
  border-radius: 3px;
  overflow: hidden;
}

.script-bar-fill {
  height: 100%;
  border-radius: 3px;
  width: 0%;
  transition: width 0.6s ease;
}

.unicode-blocks-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--ld-border);
}

.unicode-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1.5px solid;
  background: transparent;
}

/* ── Batch Results ────────────────────────────────────────────────────────── */
.batch-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: var(--ld-surface);
  margin-bottom: 6px;
  border: 1px solid var(--ld-border);
}

.batch-num {
  min-width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--ld-brand);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.batch-content {
  flex: 1;
  min-width: 0;
}
.batch-text {
  font-size: 0.82rem;
  color: var(--ld-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.batch-lang {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ld-muted);
}
.batch-conf {
  font-weight: 700;
  color: var(--ld-teal);
  margin-left: 4px;
  background: var(--ld-teal-dim);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 0.75rem;
}

/* ── History ──────────────────────────────────────────────────────────────── */
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--ld-border);
  background: var(--ld-surface);
  margin-bottom: 6px;
  transition: all 0.15s;
}

.history-item:hover {
  border-color: var(--ld-teal);
  background: var(--ld-teal-dim);
}

.history-flag {
  font-size: 1.5rem;
  flex-shrink: 0;
}
.history-info {
  flex: 1;
  min-width: 0;
}
.history-lang {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ld-ink);
}
.history-conf {
  font-size: 0.78rem;
  color: var(--ld-teal);
  font-weight: 600;
  margin-left: 4px;
}
.history-text {
  font-size: 0.78rem;
  color: var(--ld-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-time {
  font-size: 0.72rem;
  color: var(--ld-muted);
  flex-shrink: 0;
}

/* ── Structure Analysis ───────────────────────────────────────────────────── */
.structure-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

@media (min-width: 640px) {
  .structure-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.structure-stat {
  background: var(--ld-surface);
  border: 1px solid var(--ld-border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.stat-val {
  display: block;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--ld-brand);
}
.stat-label {
  display: block;
  font-size: 0.72rem;
  color: var(--ld-muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.top-words-label {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ld-muted);
  margin-bottom: 8px;
}

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

.word-chip {
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  color: #3730a3;
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 0.8rem;
}

.word-chip strong {
  color: var(--ld-brand);
  font-weight: 800;
  margin-left: 3px;
}

/* ── Export Buttons ───────────────────────────────────────────────────────── */
.export-btn.success {
  background: var(--ld-success) !important;
  border-color: var(--ld-success) !important;
  color: white !important;
}

/* ── Toggle Switch ────────────────────────────────────────────────────────── */
.toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ld-ink);
  cursor: pointer;
}

.toggle-switch {
  position: relative;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 11px;
  transition: background 0.2s;
  cursor: pointer;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-track {
  background: var(--ld-teal);
}
.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(16px);
}

/* ── Confidence Color Classes ─────────────────────────────────────────────── */
.conf-high {
  color: var(--ld-teal);
}
.conf-med {
  color: var(--ld-warn);
}
.conf-low {
  color: var(--ld-danger);
}

/* ── Section Transitions ──────────────────────────────────────────────────── */
#resultsPanel {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .primary-card {
    padding: 18px;
  }
  #primaryName {
    font-size: 1.3rem;
  }
  #primaryFlag {
    font-size: 2.4rem;
  }
  .meta-chip {
    font-size: 0.7rem;
    padding: 2px 8px;
  }
  .tabs-header {
    overflow-x: auto;
  }
  .tab-btn {
    white-space: nowrap;
    padding: 8px 12px;
  }
}
