*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f4;
  --bg-tertiary: #eeede9;
  --text-primary: #1a1a18;
  --text-secondary: #6b6b67;
  --text-tertiary: #9e9e99;
  --border-light: rgba(0,0,0,0.12);
  --border-mid: rgba(0,0,0,0.22);
  --radius-md: 8px;
  --radius-lg: 12px;
  --blue: #FF6200;
  --orange-light: #FFF0E6;
  --orange-dark: #D35400;
  --orange-glow: rgba(255, 98, 0, 0.15);
  --blue-mid: #FF8A3D;
  --green: #0F6E56;
  --green-light: #E1F5EE;
  --red: #A32D2D;
  --red-light: #FCEBEB;
  --amber: #854F0B;
  --amber-light: #FAEEDA;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #121212;
    --bg-secondary: #1E1E1E;
    --bg-tertiary: #333330;
    --text-primary: #f0efea;
    --text-secondary: #a0a09a;
    --text-tertiary: #6b6b67;
    --border-light: rgba(255,255,255,0.1);
    --border-mid: rgba(255,255,255,0.2);
    --blue: #FF8A3D;
    --orange-light: #2A1A0F;
    --orange-dark: #FFB366;
    --orange-glow: rgba(255, 138, 61, 0.3);
    --blue-mid: #FF6200;
    --green: #5DCAA5;
    --green-light: #04342C;
    --red: #F09595;
    --red-light: #501313;
    --amber: #EF9F27;
    --amber-light: #412402;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
}

.wrap { width: 100%; max-width: 520px; }

/* Header */
.header { text-align: center; margin-bottom: 1.5rem; }
.header h1 { font-size: 22px; font-weight: 500; color: var(--text-primary); margin-bottom: 4px; }
.header > p { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }

/* Status bar */
.status-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-secondary);
  border: 0.5px solid var(--border-light);
  border-radius: 99px;
  padding: 4px 12px 4px 8px;
  font-size: 12px;
  color: var(--text-secondary);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
  transition: background 0.3s;
}
.status-dot.loading { background: var(--amber); animation: pulse 1s infinite; }
.status-dot.ok      { background: var(--green); }
.status-dot.error   { background: var(--red); }
.status-dot.manual  { background: var(--blue-mid); }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

.refresh-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary); font-size: 16px; line-height: 1;
  padding: 0 0 0 4px;
  transition: transform 0.3s;
}
.refresh-btn:hover { color: var(--blue-mid); }
.refresh-btn.spinning { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Skeleton loader */
.skeleton {
  display: inline-block;
  width: 70px; height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--border-light) 25%, var(--bg-tertiary) 50%, var(--border-light) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Rate badges */
.rates-bar { display: flex; gap: 8px; margin-bottom: 1.25rem; }
.rate-badge {
  flex: 1; padding: 8px;
  border: 0.5px solid var(--border-mid);
  border-radius: var(--radius-md);
  text-align: center; cursor: pointer;
  background: var(--bg-secondary);
  transition: background 0.15s, border-color 0.15s;
}
.rate-badge:hover { background: var(--bg-tertiary); }
.rate-badge.active { background: var(--blue-light); border-color: var(--blue-mid); }
.rate-badge .rb-name { font-size: 11px; color: var(--text-secondary); }
.rate-badge .rb-val { font-size: 13px; font-weight: 500; color: var(--text-primary); margin-top: 2px; min-height: 18px; }
.rate-badge.active .rb-name { color: var(--blue); }
.rate-badge.active .rb-val { color: var(--blue-dark); }

/* Card */
.card {
  background: var(--bg-primary);
  border: 0.5px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.input-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; display: block; }

/* Selector */
.selector { display: flex; gap: 6px; margin-bottom: 1rem; flex-wrap: wrap; }
.sel-btn {
  flex: 1; padding: 8px 4px; font-size: 13px;
  border: 0.5px solid var(--border-mid);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer; transition: all 0.15s;
  min-width: 70px;
}
.sel-btn:hover { background: var(--bg-tertiary); }
.sel-btn.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* Input */
.input-group { margin-bottom: 1rem; }
.input-row { display: flex; align-items: center; gap: 10px; }
.currency-tag { font-size: 14px; font-weight: 500; color: var(--text-secondary); min-width: 50px; }

/* --- OPTIMIZACIÓN DE INPUTS --- */
input[type="number"] {
  flex: 1; width: 100%;
  padding: 8px 12px; font-size: 16px;
  border: 0.5px solid var(--border-mid);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none; transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}

input[type="number"]:focus { border-color: var(--blue-mid); box-shadow: 0 0 0 3px rgba(55,138,221,0.15); }

.hidden { display: none !important; }

.reset-action-container {
  display: flex;
  justify-content: center;
  width: 100%;
  margin-top: 10px;
  margin-bottom: 5px;
}

.reset-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: none;
  text-decoration: none;
  color: var(--blue-mid);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  margin: 0;
  transition: opacity 0.2s;
}

.reset-btn span {
  font-size: 14px;
}

.reset-btn:hover { opacity: 0.8; filter: brightness(1.1); }

.divider {
  clear: both;
  border: none;
  border-top: 0.5px solid var(--border-light);
  margin: 1rem 0;
  margin-top: 0 !important;
}

/* Results */
.results-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.result-card { background: var(--bg-secondary); border-radius: var(--radius-md); padding: 12px 14px; }
.result-card.full { grid-column: 1 / -1; }
.rc-label { font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.rc-value { font-size: 22px; font-weight: 500; color: var(--text-primary); }
.rc-sub { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }

/* Footer */
.rates-footer { margin-top: 1rem; text-align: center; }
.rates-footer p { font-size: 12px; color: var(--text-tertiary); margin-bottom: 6px; }
.rates-footer strong { color: var(--text-secondary); font-weight: 500; }
.edit-rates-btn {
  font-size: 12px; color: var(--blue-mid);
  background: none; border: none; cursor: pointer; text-decoration: underline;
}

/* Edit panel */
.edit-panel {
  background: var(--bg-primary);
  border: 0.5px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.25rem; margin-bottom: 1rem;
  display: none;
}
.edit-panel.open { display: block; }
.edit-panel h3 { font-size: 14px; font-weight: 500; color: var(--text-primary); margin-bottom: 4px; }
.edit-note { font-size: 12px; color: var(--text-tertiary); margin-bottom: 1rem; }
.edit-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.edit-row label { font-size: 13px; color: var(--text-secondary); flex: 1; }
.edit-row input { width: 140px; flex: none; }

.save-btn {
  width: 100%; padding: 10px;
  background: var(--blue); color: #fff;
  border: none; border-radius: var(--radius-md);
  font-size: 14px; font-weight: 500;
  cursor: pointer; margin-top: 4px; transition: opacity 0.15s;
}
.save-btn:hover { opacity: 0.88; }

.empty-msg { color: var(--text-tertiary); font-size: 13px; grid-column: 1 / -1; padding: 4px 0; }

/* App Logo */
.app-logo {
  width: 64px;
  height: auto;
  margin-bottom: 12px;
  border-radius: var(--radius-md);
}

/* Error banner */
.error-banner {
  background: var(--red-light);
  border: 0.5px solid var(--red);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--red);
  margin-bottom: 1rem;
  display: none;
}
.error-banner.visible { display: block; }

@media (max-width: 400px) {
  .selector { gap: 4px; }
  .sel-btn { font-size: 12px; padding: 7px 2px; }
  .rates-bar { gap: 6px; }
  .rate-badge { padding: 6px 4px; }
  .rate-badge .rb-name { font-size: 10px; }
}

/* --- SECCIÓN DE ENLACES Y FOOTER --- */
.bcv-link { color: inherit; font-weight: 500; text-decoration: none; }
.bcv-link:hover { text-decoration: underline; }

.feedback-container { margin-top: 12px; }

.btn-feedback {
  display: inline-block;
  background-color: var(--blue);
  color: #ffffff;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: opacity 0.2s ease;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

.btn-feedback:hover { opacity: 0.9; color: #ffffff; }

@media (prefers-color-scheme: dark) {
  .btn-feedback { background-color: var(--blue-mid); }
}

/* --- COMPONENTES DE MONEDA (Iconos y Alineación) --- */
.rb-name, .sel-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.badge-icon, .coin-icon {
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.badge-icon {
  width: 14px;
  height: 14px;
  opacity: 0.8;
}

.coin-icon {
  width: 20px;
  height: 20px;
}

.rate-badge.active .badge-icon { opacity: 1; }

@media (max-width: 400px) {
  .sel-btn { gap: 4px; font-size: 11px; }
  .coin-icon { width: 16px; height: 16px; }
}
