:root {
  --bg: #0c0c0d;
  --bg-elev: #17171a;
  --bg-elev-2: #1f1f23;
  --border: #2d2d32;
  --gold: #d4a73c;
  --gold-dim: #a9842f;
  --text: #f1f0ec;
  --text-dim: #a3a1a0;
  --red: #c0453f;
  --green: #4caf6e;
  --radius: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Barlow Condensed', 'Oswald', system-ui, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, .brand-ks, .brand-panel, .nav-btn, button {
  font-family: 'Oswald', 'Barlow Condensed', system-ui, sans-serif;
  letter-spacing: 0.02em;
}

h1 { font-size: 1.4rem; margin: 0 0 12px; text-transform: uppercase; color: var(--gold); }
h2 { font-size: 1.1rem; margin: 20px 0 8px; color: var(--gold); text-transform: uppercase; }
h3 { font-size: 1rem; margin: 12px 0 6px; color: var(--text); }
p { color: var(--text-dim); line-height: 1.4; }
a { color: var(--gold); text-decoration: none; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-brand { font-size: 1.25rem; font-weight: 700; }
.brand-ks { color: var(--gold); }
.brand-panel { color: var(--text); margin-left: 4px; font-weight: 400; }

.icon-btn {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--gold);
  border-radius: 50%; width: 38px; height: 38px; font-size: 1.1rem; cursor: pointer;
}

.app {
  padding: 16px 16px calc(96px + var(--safe-bottom));
  max-width: 720px;
  margin: 0 auto;
  min-height: 60vh;
}

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + var(--safe-bottom));
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-dim); font-size: 0.72rem; text-transform: uppercase; padding: 4px 0;
  border-radius: 8px;
}
.nav-item.active { color: var(--gold); }
.nav-icon { font-size: 1.25rem; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card + .card { margin-top: 0; }

.quick-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; text-align: center;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 10px; color: var(--text); text-transform: none;
}
.quick-btn .qb-icon { font-size: 1.6rem; }
.quick-btn .qb-label { font-size: 0.78rem; color: var(--text-dim); text-transform: uppercase; }
.quick-btn .qb-value { font-size: 1.15rem; font-weight: 700; color: var(--gold); }
.quick-btn.primary {
  background: var(--gold); color: #141210; border: none; padding: 22px 10px; margin-bottom: 12px;
}
.quick-btn.primary .qb-icon { font-size: 1.9rem; }
.quick-btn.primary .qb-label { color: #141210; font-size: 1.05rem; font-weight: 700; }
.quick-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 18px; }

.textarea-rapido {
  min-height: 140px; font-size: 1rem;
}
.missing-note { color: var(--gold); font-size: 0.78rem; margin-top: -4px; margin-bottom: 10px; }

.grid-kpi {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: 12px;
}
.kpi .label { color: var(--text-dim); font-size: 0.72rem; text-transform: uppercase; }
.kpi .value { font-size: 1.3rem; font-weight: 600; margin-top: 2px; }
.kpi .value.neg { color: var(--red); }
.kpi .value.pos { color: var(--green); }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--gold); color: #141210; border: none; border-radius: var(--radius);
  padding: 11px 16px; font-size: 0.95rem; font-weight: 600; cursor: pointer;
  text-transform: uppercase;
}
button:disabled { opacity: 0.5; }
.btn-secondary { background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--gold); padding: 8px 10px; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 10px; font-size: 0.8rem; }

input, select, textarea {
  width: 100%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: inherit;
  margin-bottom: 10px;
}
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.checkbox-row input { width: auto; margin: 0; }
.checkbox-row label { margin: 0; text-transform: none; font-size: 0.9rem; }

.list-item {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; margin-bottom: 8px; cursor: pointer;
}
.list-item .folio { color: var(--gold); font-weight: 600; }
.list-item .meta { color: var(--text-dim); font-size: 0.8rem; }
.list-item .amount { text-align: right; font-weight: 600; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 0.68rem;
  text-transform: uppercase; border: 1px solid var(--border); color: var(--text-dim);
}
.badge.gold { background: rgba(212,167,60,0.15); color: var(--gold); border-color: var(--gold-dim); }
.badge.green { background: rgba(76,175,110,0.15); color: var(--green); border-color: var(--green); }
.badge.red { background: rgba(192,69,63,0.15); color: var(--red); border-color: var(--red); }

.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .btn { flex: 0 0 auto; }
.search-input { margin-bottom: 14px; }

.empty-state { text-align: center; padding: 40px 10px; color: var(--text-dim); }

.toast {
  position: fixed; top: calc(12px + var(--safe-top)); left: 50%; transform: translateX(-50%) translateY(-20px);
  background: var(--bg-elev-2); border: 1px solid var(--gold); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 0.9rem; z-index: 100;
  opacity: 0; transition: all 0.25s ease; pointer-events: none; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--red); }

.field-missing {
  border-color: var(--gold) !important;
  box-shadow: 0 0 0 2px rgba(212, 167, 60, 0.35);
  background: rgba(212, 167, 60, 0.08) !important;
}

.item-row {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
  background: var(--bg-elev-2);
}
.item-row .item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.profit-line { font-size: 0.85rem; color: var(--text-dim); margin-top: 4px; }
.profit-line .val { color: var(--green); font-weight: 600; }

.comprobante-box {
  white-space: pre-wrap; background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; font-size: 0.85rem; margin-bottom: 10px;
  font-family: 'Courier New', monospace;
}

.status-timeline { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-logo { font-size: 2rem; margin-bottom: 4px; }
.login-logo .brand-ks { color: var(--gold); }

.lock-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px calc(24px + env(safe-area-inset-right, 0px)) 24px calc(24px + env(safe-area-inset-left, 0px));
}
.lock-overlay.hidden { display: none; }
.lock-card { width: 100%; max-width: 360px; text-align: center; }

/* Candado "a ciegas" aplicado antes de que cargue app.js (ver script inline en
   index.html). Cubre todo con !important porque corre antes que cualquier JS de
   la app pueda decidir nada. */
html.ks-locked-boot #app,
html.ks-locked-boot #bottomNav,
html.ks-locked-boot .topbar {
  display: none !important;
}
html.ks-locked-boot #lockScreen {
  display: flex !important;
}

table.simple-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.simple-table th, table.simple-table td { padding: 6px 4px; border-bottom: 1px solid var(--border); text-align: left; }
table.simple-table th { color: var(--gold); text-transform: uppercase; font-size: 0.7rem; }

.muted { color: var(--text-dim); font-size: 0.85rem; }
.text-right { text-align: right; }
.hidden { display: none !important; }
