:root {
  --azul-oscuro: #0c447c;
  --azul-medio: #185fa5;
  --azul-claro: #e6f1fb;
  --verde: #27500a;
  --verde-bg: #eaf3de;
  --verde-fuerte: #3b6d11;
  --rojo: #791f1f;
  --rojo-bg: #fcebeb;
  --rojo-fuerte: #a32d2d;
  --amber: #633806;
  --amber-bg: #faeeda;
  --morado: #3c3489;
  --morado-bg: #eeedfe;
  --gris-texto: #5f5e5a;
  --gris-claro: #888780;
  --fondo: #f5f5f7;
  --tarjeta: #ffffff;
  --borde: #ececec;
  --negro: #1a1a1a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

.icn { display: inline-block; vertical-align: -0.18em; flex-shrink: 0; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--fondo);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  color: var(--negro);
  overscroll-behavior-y: none;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 78px;
}

/* ---------- Top bar ---------- */
.topbar {
  background: var(--azul-oscuro);
  color: white;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 18px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-row { display: flex; justify-content: space-between; align-items: flex-end; }
.topbar .app-label { font-size: 11px; opacity: 0.65; letter-spacing: 2px; font-weight: 600; margin-bottom: 2px; }
.topbar .screen-name { font-size: 22px; font-weight: 700; }
.ep-badge {
  width: 38px; height: 38px; background: white; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: var(--azul-oscuro); flex-shrink: 0;
}

.formheader {
  background: var(--azul-oscuro);
  color: white;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 16px;
  display: flex; align-items: center; gap: 10px;
  position: sticky; top: 0; z-index: 10;
}
.back-btn {
  width: 30px; height: 30px; background: rgba(255,255,255,0.15); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; border: none; color: white; font-size: 18px; cursor: pointer;
}
.formheader .formtitle { font-size: 18px; font-weight: 700; flex: 1; }

/* ---------- Contenido ---------- */
.content { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- Tarjetas métricas ---------- */
.stats-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.stat-card { background: var(--tarjeta); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stat-num { font-size: 20px; font-weight: 700; color: var(--azul-oscuro); line-height: 1; }
.stat-num.green { color: var(--verde); }
.stat-label { font-size: 10px; color: var(--gris-claro); margin-top: 4px; font-weight: 500; }

.section-title { font-size: 11px; font-weight: 700; color: var(--gris-claro); letter-spacing: 1px; padding: 4px 4px; text-transform: uppercase; }

/* ---------- Tarjetas de orden ---------- */
.order-card {
  background: var(--tarjeta); border-radius: 12px; padding: 11px 13px;
  display: flex; align-items: center; gap: 10px; border: none; width: 100%; text-align: left; cursor: pointer;
}
.order-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--azul-claro);
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--azul-oscuro); flex-shrink: 0;
}
.order-info { flex: 1; min-width: 0; }
.order-name { font-size: 13px; font-weight: 600; color: var(--negro); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-sub { font-size: 11px; color: var(--gris-claro); margin-top: 1px; }
.order-right { text-align: right; flex-shrink: 0; }
.order-amount { font-size: 13px; font-weight: 700; color: var(--azul-oscuro); }
.order-util { font-size: 10px; font-weight: 600; color: var(--verde); margin-top: 1px; }
.status-pill { font-size: 9px; font-weight: 700; padding: 2px 8px; border-radius: 20px; margin-top: 3px; display: inline-block; }
.pill-pendiente { background: var(--amber-bg); color: var(--amber); }
.pill-proceso { background: var(--azul-claro); color: var(--azul-oscuro); }
.pill-listo { background: var(--verde-bg); color: var(--verde); }
.pill-cerrado { background: #e3e1d9; color: #5f5e5a; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--gris-claro); }
.empty-state .icn { font-size: 36px; opacity: 0.4; margin-bottom: 8px; display: block; }
.empty-state p { font-size: 13px; margin: 4px 0; }

/* ---------- Botones ---------- */
.btn-primary {
  background: var(--azul-oscuro); color: white; border: none; border-radius: 12px;
  padding: 13px; text-align: center; font-size: 14px; font-weight: 600; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
}
.btn-primary.green { background: var(--verde-fuerte); }
.btn-primary.red { background: var(--rojo-fuerte); }
.btn-primary:active { opacity: 0.85; }
.btn-secondary {
  background: white; color: var(--azul-oscuro); border: 1px solid var(--azul-oscuro); border-radius: 12px;
  padding: 12px; text-align: center; font-size: 13px; font-weight: 600; width: 100%; cursor: pointer;
}
.fab-add {
  position: fixed; bottom: 88px; right: 18px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--azul-oscuro); color: white; border: none; display: flex; align-items: center;
  justify-content: center; font-size: 26px; box-shadow: 0 4px 14px rgba(12,68,124,0.35); z-index: 15; cursor: pointer;
}

/* ---------- Formularios ---------- */
.form-section { background: var(--tarjeta); border-radius: 12px; overflow: hidden; }
.sec-title { font-size: 10px; font-weight: 700; color: var(--azul-oscuro); letter-spacing: 1px; padding: 8px 13px; background: var(--azul-claro); text-transform: uppercase; }
.sec-title.green { color: var(--verde); background: var(--verde-bg); }
.sec-title.purple { color: var(--morado); background: var(--morado-bg); }
.sec-title.amber { color: var(--amber); background: var(--amber-bg); }
.sec-title.red { color: var(--rojo); background: var(--rojo-bg); }

.form-field { padding: 9px 13px; border-bottom: 1px solid var(--borde); display: flex; flex-direction: column; gap: 4px; }
.form-field:last-child { border-bottom: none; }
.form-field label { font-size: 10px; font-weight: 700; color: var(--gris-claro); letter-spacing: 0.5px; text-transform: uppercase; }
.form-field input, .form-field select, .form-field textarea {
  border: none; font-size: 14px; color: var(--negro); font-family: inherit; padding: 2px 0; background: transparent; width: 100%;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { outline: none; }
.form-field textarea { resize: vertical; min-height: 50px; }
.form-field input::placeholder, .form-field textarea::placeholder { color: #c2c2c2; }

.col2 { display: grid; grid-template-columns: 1fr 1fr; }
.col2 .form-field { border-right: 1px solid var(--borde); }
.col2 .form-field:last-child { border-right: none; }
.col3 { display: grid; grid-template-columns: 1fr 1fr 1fr; }
.col3 .form-field { border-right: 1px solid var(--borde); }
.col3 .form-field:last-child { border-right: none; }

.value-display { font-size: 14px; font-weight: 600; }
.value-display.blue { color: var(--azul-oscuro); }
.value-display.green { color: var(--verde); }
.value-display.red { color: var(--rojo-fuerte); }
.value-display.amber { color: var(--amber); }

/* ---------- Lista items OT / pagos / movimientos ---------- */
.list-item { padding: 9px 13px; border-bottom: 1px solid var(--borde); display: flex; align-items: center; gap: 8px; }
.list-item:last-child { border-bottom: none; }
.item-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-azul { background: var(--azul-oscuro); }
.dot-verde { background: #639922; }
.dot-rojo { background: #e24b4a; }
.item-text { font-size: 12px; color: var(--negro); flex: 1; }
.item-cost { font-size: 12px; color: var(--gris-claro); font-weight: 500; min-width: 50px; text-align: right; }
.item-tag { font-size: 9px; font-weight: 700; padding: 2px 7px; border-radius: 10px; flex-shrink: 0; }
.tag-azul { background: var(--azul-claro); color: var(--azul-oscuro); }
.tag-verde { background: var(--verde-bg); color: var(--verde); }
.tag-rojo { background: var(--rojo-bg); color: var(--rojo); }
.item-delete { background: none; border: none; color: #c2c2c2; font-size: 16px; cursor: pointer; padding: 4px; flex-shrink: 0; }
.item-delete:active { color: var(--rojo-fuerte); }

.add-row { padding: 10px 13px; display: flex; align-items: center; gap: 7px; color: var(--azul-oscuro); font-size: 12px; font-weight: 700; cursor: pointer; background: none; border: none; width: 100%; text-align: left; }
.add-row.green { color: var(--verde-fuerte); }
.add-row.red { color: var(--rojo-fuerte); }
.add-row.purple { color: var(--morado); }

/* ---------- Tab personal ---------- */
.balance-hero { background: var(--azul-oscuro); border-radius: 14px; padding: 18px; color: white; text-align: center; }
.balance-label { font-size: 11px; opacity: 0.7; letter-spacing: 1.5px; font-weight: 600; text-transform: uppercase; }
.balance-amount { font-size: 32px; font-weight: 800; margin: 4px 0; }
.balance-sub { font-size: 11px; opacity: 0.65; }
.balance-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.balance-col { background: rgba(255,255,255,0.13); border-radius: 10px; padding: 10px; }
.bcol-label { font-size: 10px; opacity: 0.7; font-weight: 500; }
.bcol-val { font-size: 16px; font-weight: 700; margin-top: 2px; }
.bcol-val.income { color: #9fe1cb; }
.bcol-val.expense { color: #f09595; }

.trx-item { padding: 9px 13px; border-bottom: 1px solid var(--borde); display: flex; align-items: center; gap: 10px; }
.trx-item:last-child { border-bottom: none; }
.trx-icon { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 15px; }
.trx-icon.inc { background: var(--verde-bg); color: var(--verde); }
.trx-icon.exp { background: var(--rojo-bg); color: var(--rojo-fuerte); }
.trx-info { flex: 1; min-width: 0; }
.trx-desc { font-size: 13px; font-weight: 500; color: var(--negro); }
.trx-date { font-size: 10px; color: var(--gris-claro); margin-top: 1px; }
.trx-amount { font-size: 13px; font-weight: 700; flex-shrink: 0; }
.trx-amount.inc { color: var(--verde); }
.trx-amount.exp { color: var(--rojo-fuerte); }

/* ---------- Cierre / historial ---------- */
.range-pick { display: flex; gap: 8px; padding: 10px 13px; }
.range-box { flex: 1; }
.range-box label { font-size: 10px; font-weight: 700; color: var(--gris-claro); display: block; margin-bottom: 3px; text-transform: uppercase; }
.range-box input { width: 100%; border: 1px solid var(--borde); border-radius: 8px; padding: 8px; font-size: 13px; font-family: inherit; }

.history-item { padding: 11px 13px; border-bottom: 1px solid var(--borde); display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.history-item:last-child { border-bottom: none; }
.hist-range { font-size: 13px; font-weight: 600; color: var(--negro); }
.hist-meta { font-size: 10px; color: var(--gris-claro); margin-top: 1px; }
.hist-net { font-size: 13px; font-weight: 700; color: var(--verde); }
.hist-net.neg { color: var(--rojo-fuerte); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; background: white; border-top: 1px solid var(--borde);
  display: flex; padding: 10px 0 calc(env(safe-area-inset-bottom, 0px) + 10px); max-width: 560px; margin: 0 auto; z-index: 20;
}
.tab-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; color: #9a9a9a; background: none; border: none; cursor: pointer; }
.tab-item.active { color: var(--azul-oscuro); font-weight: 700; }
.tab-item .icn { font-size: 26px; }

/* ---------- Modal / overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.sheet {
  background: white; width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 16px;
  max-height: 86vh; overflow-y: auto; padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
}
.sheet-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
.sheet-title button { background: none; border: none; font-size: 20px; color: var(--gris-claro); cursor: pointer; }
.sheet .form-field { padding: 10px 0; border-bottom: 1px solid var(--borde); }
.sheet .form-field input, .sheet .form-field select, .sheet .form-field textarea {
  border: 1px solid var(--borde); border-radius: 8px; padding: 9px 11px; margin-top: 2px;
}

.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%); background: var(--negro); color: white;
  padding: 10px 18px; border-radius: 30px; font-size: 13px; z-index: 100; opacity: 0; transition: opacity 0.25s; pointer-events: none;
}
.toast.show { opacity: 1; }

.hidden { display: none !important; }

.install-banner {
  background: var(--morado-bg); color: var(--morado); padding: 10px 13px; border-radius: 12px; font-size: 12px;
  display: flex; align-items: center; gap: 8px; line-height: 1.4;
}
.install-banner i { font-size: 18px; flex-shrink: 0; }
