/*
  Dark theme, responsive layout, RTL/LTR support
  ثيم داكن، تصميم متجاوب، دعم الاتجاه يمين-إلى-يسار ويسار-إلى-يمين
*/

:root {
  --bg: #0f1115;
  --bg-elev: #161a22;
  --text: #e6e6e6;
  --muted: #a5adcb;
  --primary: #6aa6ff;
  --secondary: #39465e;
  --accent: #22c55e;
  --danger: #ef4444;
  --border: #232735;
  --border-radius: 12px;
  --padding-sm: 0.5rem;
  --padding-md: 1rem;
  --padding-lg: 1.5rem;
  --gap-sm: 0.5rem;
  --gap-md: 1rem;
  --gap-lg: 1.5rem;
}

/* Light theme variables */
:root.theme-light {
  --bg: #f7f8fa;
  --bg-elev: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --primary: #2563eb;
  --secondary: #e2e8f0;
  --accent: #16a34a;
  --danger: #dc2626;
  --border: #d4dbe6;
}

* { 
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
}

html, body {
  height: 100%;
  -webkit-text-size-adjust: 100%; /* Prevent font scaling in landscape on iOS */
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.5;
  transition: background 0.25s ease, color 0.25s ease;
  overflow-x: hidden; /* Prevent horizontal scroll */
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: var(--padding-md);
  width: 100%;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--padding-md);
  flex-wrap: wrap;
}

.brand { 
  display: flex; 
  align-items: center; 
  gap: var(--gap-sm);
}
.header-actions { 
  display: flex; 
  align-items: center; 
  gap: var(--gap-sm);
}

.app-title {
  margin: 0;
  font-size: 1.5rem;
  word-break: break-word; /* Prevent text overflow on small screens */
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  padding: var(--padding-md);
  margin-bottom: var(--padding-md);
  width: 100%;
}

.section-title {
  margin-top: 0;
  margin-bottom: var(--padding-md);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap-md);
}

@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .grid { 
    grid-template-columns: 1fr;
    gap: var(--gap-sm);
  }

  .card {
    padding: var(--padding-sm);
    border-radius: calc(var(--border-radius) * 0.8);
  }

  .app-title {
    font-size: 1.25rem;
  }
}

@media (max-width: 400px) {
  .container {
    padding: var(--padding-sm);
  }

  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--gap-sm);
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
}

.form-field label { 
  display: block; 
  margin-bottom: calc(var(--padding-sm) * 0.7);
  font-weight: 500;
}
.form-field input, .form-field select {
  width: 100%;
  padding: calc(var(--padding-sm) * 1.2) calc(var(--padding-sm) * 1.4);
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* Prevent zoom on iOS */
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-field input:focus, .form-field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(106, 166, 255, 0.2);
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: calc(var(--padding-sm) * 0.7) 0 0;
  line-height: 1.4;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-sm);
  margin-top: var(--padding-md);
}

.btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: calc(var(--padding-sm) * 1.2) calc(var(--padding-sm) * 1.8);
  color: var(--text);
  background: #121722;
  cursor: pointer;
  font-size: 16px; /* Prevent zoom on iOS */
  font-weight: 500;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px; /* Minimum touch target size */
}

/* Fix for Font Awesome icons */
.btn i {
  font-size: 1.2rem;
  margin: 0;
}

.btn:hover { 
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

/* Touch feedback for buttons */
.btn.touch-active {
  opacity: 0.8;
  transform: scale(0.98);
}

.btn-primary { 
  background: var(--primary); 
  color: #edf2ff; 
  border-color: #4b82d9; 
}
.btn-secondary { 
  background: var(--secondary); 
  color: var(--text); 
}
.btn-accent { 
  background: var(--accent); 
  color: #f0fdf4; 
  border-color: #169a48; 
}
.btn-danger { 
  background: var(--danger); 
  color: #fee2e2; 
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap-md);
}

@media (max-width: 900px) {
  .results-grid { 
    grid-template-columns: 1fr;
    gap: var(--gap-sm);
  }
}

.result-item {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: var(--padding-md);
  transition: transform 0.2s ease;
}

.result-item:hover {
  transform: translateY(-2px);
}

.result-label { 
  color: var(--muted); 
  font-size: 0.95rem;
  margin-bottom: calc(var(--padding-sm) * 0.7);
}
.result-value { 
  font-weight: 600; 
  font-size: 1.3rem; 
  margin-top: 0;
  word-break: break-all; /* Prevent overflow with long numbers */
}

@media (max-width: 600px) {
  .result-value {
    font-size: 1.1rem;
  }
}

/* Screen reader only */
.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;
}

/* RTL/LTR tweaks using dir attribute on html */
html[dir="rtl"] body { direction: rtl; }
html[dir="rtl"] .grid, html[dir="rtl"] .results-grid { direction: rtl; }

/* Copy button special look */
#btnCopy {
  font-weight: 700;
  position: relative;
  overflow: hidden;
}

/* Animation for copy button */
#btnCopy.copied {
  animation: copySuccess 0.8s ease;
}

@keyframes copySuccess {
  0% {
    background-color: var(--accent);
    transform: scale(1);
  }
  50% {
    background-color: var(--accent);
    transform: scale(1.05);
  }
  100% {
    background-color: var(--secondary);
    transform: scale(1);
  }
}

/* Ripple effect for copy button */
#btnCopy .ripple {
  position: absolute;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.6);
  transform: scale(0);
  animation: ripple 0.6s linear;
}

@keyframes ripple {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

.example-card p {
  color: var(--muted);
  line-height: 1.6;
}

/* Improve touch targets for mobile */
@media (hover: none) {
  .btn {
    padding: calc(var(--padding-sm) * 1.4) calc(var(--padding-sm) * 2);
  }

  .form-field input, .form-field select {
    padding: calc(var(--padding-sm) * 1.4);
  }
}