@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Design Tokens ── */
:root {
  --bg-page: #f5f7fb;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-soft: #f8fafc;

  --border-card: #e5e9f2;
  --border-input: #d9dee9;
  --border-focus: #2563eb;

  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-label: #475569;
  --text-muted: #94a3b8;
  --text-white: #ffffff;

  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-800: #1e40af;

  --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
  --shadow-card: 0 1px 3px 0 rgba(15, 23, 42, 0.06), 0 1px 2px -1px rgba(15, 23, 42, 0.04);

  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
  --radius-xl: 0.75rem;

  --transition: all 150ms ease;
}

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

/* ── Body ── */
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.4;
}

/* ── Main Container ── */
.main {
  max-width: 56rem;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding-bottom: 0.5rem;
}

.brand-logo {
  width: 3rem;
  height: 3rem;
  object-fit: contain;
  border-radius: 0.5rem;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; gap: 0.125rem; }

.page-title {
  font-size: 1.375rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.brand-subtitle .dot {
  color: var(--text-muted);
  margin: 0 0.25rem;
}

/* ── Card ── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-card);
  padding: 0.75rem 0.875rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  min-width: 0;
  overflow: visible;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-card);
  margin-bottom: 0;
  flex-wrap: wrap;
  min-width: 0;
}

.card-title { min-width: 0; }

.card-title {
  font-size: 0.6875rem;
  font-weight: 800;
  color: var(--blue-800);
  display: inline-flex;
  align-items: center;
  gap: 0.4375rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.card-title svg {
  width: 0.9375rem;
  height: 0.9375rem;
  color: var(--blue-600);
  stroke-width: 2.25;
}

/* ── Field (label + control) ── */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3125rem;
}

.field-label {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-label);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field-control {
  display: flex;
  align-items: stretch;
  gap: 0.375rem;
}

.field-control > .input-field,
.field-control > .input-with-prefix,
.field-control > .result-display {
  flex: 0 0 8rem;
  width: 8rem;
  min-width: 0;
}

.field-control > .custom-select {
  flex: 0 0 6.5rem;
}

/* ── Input ── */
.input-field {
  width: 100%;
  padding: 0.5rem 0.625rem;
  font-size: 0.875rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  outline: none;
  transition: var(--transition);
  font-variant-numeric: tabular-nums;
  height: 2.25rem;
}

.input-field:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.input-field::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

/* ── Input with currency prefix ── */
.input-with-prefix {
  position: relative;
  display: flex;
  align-items: center;
}

.input-prefix {
  position: absolute;
  left: 0.625rem;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--text-secondary);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.input-field.with-prefix {
  padding-left: 1.625rem;
}

/* ── Custom Select ── */
.custom-select {
  position: relative;
}

.select-selected {
  height: 2.25rem;
  padding: 0 1.75rem 0 0.625rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-soft);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 0.875rem;
  transition: var(--transition);
}

.select-selected:hover { border-color: var(--blue-600); }

.select-selected.select-arrow-active {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  background-color: var(--bg-input);
}

.select-items {
  position: absolute;
  background-color: var(--bg-card);
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  z-index: 99;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  min-width: 100%;
}

.select-hide { display: none; }

.select-items div {
  padding: 0.4375rem 0.625rem;
  font-size: 0.8125rem;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  transition: background-color 120ms;
}

.select-items div:hover {
  background-color: var(--blue-50);
  color: var(--blue-800);
}

.same-as-selected {
  background-color: var(--bg-soft);
  font-weight: 600;
  color: var(--blue-800);
}

/* ── Result Display (Precio & Rendimiento) ── */
.result-display {
  display: flex;
  align-items: center;
  height: 2.25rem;
  padding: 0 0.625rem;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-soft);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.result-display.has-value {
  color: var(--blue-800);
  background: var(--blue-50);
  border-color: var(--blue-100);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.08);
}

/* ── Two columns (Datos + Precio) ── */
.two-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  align-items: stretch;
}

/* Resultados (compact) + Rendimiento (wider converter) */
.two-columns-uneven {
  grid-template-columns: minmax(0, 20rem) minmax(0, 1fr);
}

/* ── Currency Toggle ── */
.currency-toggle {
  display: inline-flex;
  background: var(--bg-soft);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 2px;
}

.currency-toggle button {
  appearance: none;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 0.1875rem 0.625rem;
  border-radius: calc(var(--radius-md) - 2px);
  cursor: pointer;
  transition: var(--transition);
  min-width: 1.75rem;
  line-height: 1;
}

.currency-toggle button:hover { color: var(--blue-700); }

.currency-toggle button.active {
  background: var(--blue-600);
  color: var(--text-white);
  box-shadow: var(--shadow-sm);
}

/* ── Matrix Table (Resultados) ── */
.matrix-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8125rem;
}

.matrix-table thead th {
  padding: 0.4375rem 0.75rem;
  font-size: 0.6875rem;
  font-weight: 800;
  color: var(--blue-800);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-align: right;
  border-bottom: 1.5px solid var(--border-card);
}

.matrix-table thead th:first-child { text-align: left; }

.matrix-table tbody th {
  padding: 0.5rem 0.75rem;
  font-weight: 800;
  font-size: 0.6875rem;
  color: var(--text-label);
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border-card);
  width: 1%;
  white-space: nowrap;
}

.matrix-table tbody td {
  padding: 0.5rem 0.75rem;
  text-align: right;
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--border-card);
}

.matrix-table tbody td.has-value { color: var(--blue-800); }

.matrix-table tbody tr:last-child th,
.matrix-table tbody tr:last-child td { border-bottom: none; }

.matrix-table tbody tr:first-child th { border-top-left-radius: var(--radius-md); }
.matrix-table tbody tr:last-child th { border-bottom-left-radius: var(--radius-md); }

/* ── Converter Block (Rendimiento) ── */
.converter-block {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  gap: 0.75rem;
}

.converter-col {
  display: flex;
  flex-direction: column;
  gap: 0.3125rem;
  min-width: 0;
}

/* Dentro del converter-col, inputs y selects se reparten la columna */
.converter-col .field-control > .input-field,
.converter-col .field-control > .result-display {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
}

.converter-col .field-control > .custom-select {
  flex: 0 0 5.5rem;
}

.converter-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue-600);
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  width: 2rem;
  height: 2.25rem;
  border-radius: var(--radius-md);
  flex-shrink: 0;
  margin-bottom: 0;
}

.converter-divider svg { width: 1rem; height: 1rem; }

/* ── Responsive (mobile-first focus — this app is used mostly on phones) ── */
@media (max-width: 720px) {
  body { font-size: 15px; }

  .main {
    padding: 0.75rem 0.75rem 2rem;
    gap: 0.625rem;
  }

  .page-header { gap: 0.625rem; padding-bottom: 0.25rem; }
  .brand-logo { width: 2.5rem; height: 2.5rem; }
  .page-title { font-size: 1.125rem; }
  .brand-subtitle { font-size: 0.75rem; }

  .card {
    padding: 0.875rem 0.875rem;
    gap: 0.625rem;
    border-radius: 0.625rem;
  }

  .card-head { padding-bottom: 0.5rem; }
  .card-title { font-size: 0.8125rem; }

  .two-columns,
  .two-columns-uneven { grid-template-columns: 1fr; gap: 0.625rem; }

  /* Larger touch targets on mobile */
  .input-field,
  .select-selected,
  .result-display {
    height: 2.625rem;
    font-size: 0.9375rem;
  }

  .input-field { padding: 0.5rem 0.75rem; }
  .select-selected { padding: 0 1.875rem 0 0.75rem; font-size: 0.875rem; }
  .input-field.with-prefix { padding-left: 1.75rem; }
  .input-prefix { left: 0.75rem; font-size: 0.875rem; }

  .select-items div { padding: 0.625rem 0.75rem; font-size: 0.875rem; }

  .field-label { font-size: 0.6875rem; }

  .field-control { gap: 0.5rem; }
  .field-control > .input-field,
  .field-control > .input-with-prefix,
  .field-control > .result-display {
    flex: 1 1 auto;
    width: auto;
  }
  .field-control > .custom-select { flex: 0 0 7.5rem; }

  /* Currency toggle bigger tap area */
  .currency-toggle button {
    padding: 0.3125rem 0.75rem;
    font-size: 0.8125rem;
    min-width: 2rem;
  }

  /* Matrix table: keep compact but readable */
  .matrix-table thead th { padding: 0.5rem 0.625rem; font-size: 0.6875rem; }
  .matrix-table tbody th,
  .matrix-table tbody td { padding: 0.625rem; font-size: 0.875rem; }

  /* Converter stacks vertical with centered arrow */
  .converter-block {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .converter-divider {
    justify-self: center;
    transform: rotate(90deg);
    width: 2.25rem;
    height: 2rem;
    margin: 0.125rem 0;
  }
}

/* Very small phones */
@media (max-width: 360px) {
  .main { padding: 0.5rem 0.5rem 2rem; }
  .card { padding: 0.75rem; }
  .field-control > .custom-select { flex: 0 0 5.25rem; }
}
