/* ==========================================================================
   Diario de Trading — sistema de diseño
   Paleta pensada para uso de tarde/noche en un teléfono de gama baja:
   base tinta azulada oscura, acento bronce (no verde/rojo neón),
   verde y rojo reservados solo para resultado de operaciones.
   ========================================================================== */

:root {
  --bg: #14171c;
  --surface: #1b1f26;
  --surface-hi: #232833;
  --border: #2b303a;
  --text: #ece9e2;
  --text-muted: #8f929b;
  --accent: #c9a24b;
  --accent-soft: rgba(201, 162, 75, 0.14);
  --profit: #4e9b6e;
  --profit-soft: rgba(78, 155, 110, 0.14);
  --loss: #b8664f;
  --loss-soft: rgba(184, 102, 79, 0.15);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: 84px; /* espacio para la nav inferior */
  min-height: 100vh;
}

h1, h2, h3, p, ul, li { margin: 0; padding: 0; list-style: none; }

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 8px;
}

.page-header {
  padding: 4px 0 18px;
}

.page-header .eyebrow {
  color: var(--text-muted);
  font-size: 13px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ---------- Botones y controles ---------- */

button {
  font-family: var(--font);
  cursor: pointer;
}

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  background: var(--surface-hi);
  color: var(--text);
  transition: transform 0.08s ease;
}
.btn:active { transform: scale(0.97); }

.btn-accent {
  background: var(--accent);
  color: #1a1408;
}

.btn-block { width: 100%; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.btn-icon {
  background: var(--surface-hi);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Toggle profit / no profit (par de botones tipo segmented) */
.result-toggle {
  display: flex;
  gap: 8px;
}
.result-toggle button {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 11px 8px;
  font-size: 14px;
  font-weight: 600;
}
.result-toggle button[data-active="true"][data-val="profit"] {
  background: var(--profit-soft);
  border-color: var(--profit);
  color: var(--profit);
}
.result-toggle button[data-active="true"][data-val="no_profit"] {
  background: var(--loss-soft);
  border-color: var(--loss);
  color: var(--loss);
}

/* ---------- Formularios ---------- */

.field {
  margin-bottom: 12px;
}

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

.field-row {
  display: flex;
  gap: 8px;
}
.field-row > .field { flex: 1; margin-bottom: 12px; }

input[type="text"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="password"],
textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 15px;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}
input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { resize: vertical; min-height: 60px; }

.input-with-btn {
  display: flex;
  gap: 8px;
}
.input-with-btn input { flex: 1; }

/* ---------- Tarjetas / secciones ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.card + .card { margin-top: 14px; }

.card h2 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
}

/* ---------- Bento (home: notas / frases / reglas) ---------- */

.bento {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}
.bento .card:nth-child(1) { grid-column: 1 / -1; } /* Frases: ancho completo, protagonista */
.bento .card:nth-child(2),
.bento .card:nth-child(3) { grid-column: span 1; }

.bento-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.bento-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
}
.bento-item span { flex: 1; word-break: break-word; }
.bento-item button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
}
.bento-add {
  display: flex;
  gap: 6px;
}
.bento-add input {
  flex: 1;
  font-size: 13px;
  padding: 8px 10px;
}
.bento-add button {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font-weight: 700;
}

.frase-destacada {
  font-size: 17px;
  line-height: 1.45;
  color: var(--accent);
  font-weight: 600;
  padding: 4px 0 14px;
}

/* ---------- Nav inferior ---------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
}
.tabbar a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 0 2px;
  border-radius: var(--radius-sm);
}
.tabbar a .ic { display: block; font-size: 19px; margin-bottom: 2px; }
.tabbar a.active { color: var(--accent); }

/* ---------- Chips de periodo ---------- */

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 16px;
}
.chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
}
.chip[data-active="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Grid de operaciones ---------- */

.trades-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.trade-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 13px;
}
.trade-tile[data-resultado="profit"] { border-left-color: var(--profit); }
.trade-tile[data-resultado="no_profit"] { border-left-color: var(--loss); }
.trade-tile .fecha { color: var(--text-muted); font-size: 12px; }
.trade-tile .mercado { font-weight: 700; margin: 3px 0 6px; word-break: break-word; }
.trade-tile .beneficio {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 15px;
}
.trade-tile[data-resultado="profit"] .beneficio { color: var(--profit); }
.trade-tile[data-resultado="no_profit"] .beneficio { color: var(--loss); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px 20px;
}

.fab {
  position: fixed;
  right: 18px;
  bottom: 96px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1408;
  font-size: 26px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  z-index: 30;
}

/* ---------- Estadísticas ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}
.stat-tile .valor {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stat-tile .etiqueta {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}
.stat-tile.positivo .valor { color: var(--profit); }
.stat-tile.negativo .valor { color: var(--loss); }

.equity-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.equity-wrap h2 { font-size: 14px; color: var(--text-muted); margin-bottom: 10px; font-weight: 600; }
.equity-wrap svg { width: 100%; height: auto; display: block; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 15, 0.72);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.open { display: flex; }

.modal-sheet {
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  overflow-y: auto;
}
.modal-sheet h2 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.modal-actions .btn { flex: 1; }

.modal-center {
  align-items: center;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 26px 22px;
  width: 88%;
  max-width: 340px;
  text-align: center;
}
.modal-card h2 { margin-bottom: 6px; }
.modal-card p { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }
.error-msg {
  color: var(--loss);
  font-size: 13px;
  margin-top: 8px;
  min-height: 16px;
}

@media (min-width: 480px) {
  .bento { grid-template-columns: 1fr 1fr 1fr; }
  .bento .card:nth-child(1) { grid-column: 1 / -1; }
  .trades-grid { grid-template-columns: 1fr 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr 1fr; }
}
