:root {
  /* --- CSS Variables & Theming --- */
  --primary: #0e2a47; 
  --secondary: #FF3B3B; 
  --bg-body: #22143D;
  --card-bg: #ffffff;
  --text-main: #1f2937;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --input-bg: #f9fafb;
  --result-bg: #fafafa;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --radius: 16px;
  --tooltip-bg: #2d3748;
  --tooltip-text: #ffffff;
}

/* Dark Theme Override */
body.dark-theme {
  --primary: #ffffff; 
  --secondary: #ff5c5c; 
  --bg-body: #121212;
  --card-bg: #1e1e1e;
  --text-main: #e5e7eb;
  --text-muted: #9ca3af;
  --border: #374151;
  --input-bg: #2d2d2d;
  --result-bg: #252525;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  --tooltip-bg: #ffffff;
  --tooltip-text: #1f2937;
}

/* RTL Specific Adjustments */
html[dir="rtl"] { font-family: 'Cairo', sans-serif; }

* { box-sizing: border-box; font-family: 'Cairo', sans-serif; transition: background-color 0.3s, color 0.3s, border-color 0.3s; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-body);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  font-size: 16px;
}

/* --- Layout & Container --- */
.container {
  width: 95%; /* Mobile first */
  max-width: 1400px;
  margin: 20px auto;
  padding: 0 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Desktop adjustments */
@media (min-width: 1024px) {
  .container { width: 85%; margin: 40px auto; }
}
@media (min-width: 1400px) {
  .container { width: 70vw; }
}

/* --- Header --- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #af2638;
}

.brand-group { display: flex; align-items: center; gap: 10px; }
.logo-img { height: 40px; width: auto; object-fit: contain; }

.header-controls { display: flex; gap: 10px; align-items: center; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 40px; 
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}
.icon-btn:hover { color: #af2638; border-color: #af2638; }
.icon-btn svg { width: 22px; height: 22px; }

/* --- Main Card --- */
.converter-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr; 
  overflow: hidden;
  position: relative;
}

/* Desktop Grid: Side by Side */
@media (min-width: 900px) {
  .converter-card {
    grid-template-columns: 1.2fr 1fr;
    min-height: 520px;
  }
}

/* --- Input Section --- */
.input-section {
  padding: 25px 20px;
  border-bottom: 1px solid var(--border);
}

@media (min-width: 900px) {
  .input-section {
    padding: 50px;
    border-bottom: none;
    border-inline-end: 1px solid var(--border);
  }
}

.form-group { margin-bottom: 20px; }

label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

select, input[type="number"] {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text-main);
  outline: none;
  font-weight: 500;
  appearance: none;
}

select:focus, input:focus { border-color: var(--secondary); }

.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: rgba(255, 59, 59, 0.05);
  border-radius: 8px;
  border: 1px solid rgba(255, 59, 59, 0.2);
  cursor: pointer;
  color: var(--text-main);
  font-size: 14px;
}

input[type="checkbox"] { accent-color: var(--secondary); width: 20px; height: 20px; }

.actions { display: flex; flex-direction: column; gap: 12px; margin-top: 30px; }

@media (min-width: 480px) {
  .actions { flex-direction: row; }
}

.btn {
  padding: 16px 20px;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-size: 15px;
  width: 100%;
  display: flex; align-items: center; justify-content: center;
}

.btn-primary { background: var(--secondary); color: white; flex: 2;}
.btn-primary:hover { opacity: 0.9; }

.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-main); flex: 1; }
.btn-ghost:hover { background: var(--input-bg); }

/* --- Right Section: Results --- */
.result-section {
  background: var(--result-bg);
  padding: 25px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

@media (min-width: 900px) {
  .result-section { padding: 50px; }
}

.conversion-card {
  background: var(--card-bg);
  padding: 25px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 25px;
  position: relative;
  text-align: center;
}
@media (min-width: 900px) { .conversion-card { text-align: left; } html[dir="rtl"] .conversion-card { text-align: right; } }

.result-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--secondary); font-weight: 700; }

.result-value {
  font-size: clamp(32px, 5vw, 46px);
  font-weight: 700;
  color: var(--primary);
  margin: 10px 0;
  line-height: 1.1;
  cursor: pointer;
  word-break: break-word;
}
.result-value:hover { opacity: 0.7; }
.result-value:active { transform: scale(0.98); }

.copy-feedback {
  position: absolute;
  top: 10px; right: 10px;
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(5px);
  transition: all 0.2s ease;
  pointer-events: none;
}
.copy-feedback.show { opacity: 1; transform: translateY(0); }
html[dir="rtl"] .copy-feedback { right: auto; left: 10px; }

.result-sub { font-size: 13px; color: var(--text-muted); }

.info-list { list-style: none; padding: 0; margin: 0; }
.info-list li {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.info-list li:last-child { border-bottom: none; }
.info-list span { font-weight: 600; color: var(--primary); text-align: end; }

/* --- Overlays --- */
.overlay-container {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(2px);
  padding: 20px;
  text-align: center;
}
body.dark-theme .overlay-container { background: rgba(30,30,30,0.85); }
.overlay-container.active { opacity: 1; pointer-events: all; }

.spinner {
  width: 40px; height: 40px; margin-bottom: 20px;
  border: 4px solid var(--border);
  border-top: 4px solid var(--secondary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.critical-error-box { display: none; color: var(--secondary); max-width: 90%; }
.overlay-container.failed .spinner { display: none; }
.overlay-container.failed .critical-error-box { display: block; }
.error-icon { font-size: 40px; margin-bottom: 10px; }
.error-title { font-size: 18px; font-weight: 700; margin-bottom: 5px; }
.error-desc { font-size: 14px; color: var(--text-main); }

/* Footer */
footer {
  text-align: center;
  padding: 20px;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: auto;
}
footer p { margin: 5px 0; }
footer a { color: var(--secondary); text-decoration: none; font-weight: 600; }
footer a:hover { text-decoration: underline; }
