:root {
  --bg: #F7F4EE;
  --surface: #FFFFFF;
  --ink: #1E2A28;
  --ink-muted: #667A74;
  --line: #E3DECE;
  --teal: #1F5A52;
  --teal-dark: #123430;
  --clay: #BE5A26;
  --clay-bg: #F7E5D7;
  --green: #3E7A4F;
  --green-bg: #E6F1E7;
  --sidebar-ink: #F4F1E7;
  --sidebar-ink-muted: #93A9A3;
  --sidebar-hover: rgba(244, 241, 231, 0.06);
  --sidebar-active: rgba(244, 241, 231, 0.09);
  --radius: 8px;
  --radius-sm: 6px;
  --shadow-brand: 0 20px 50px -24px rgba(18, 52, 48, 0.35);
  --font-display: "Space Grotesk", "Segoe UI", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--ink-muted); font-weight: 500; font-family: var(--font-body); }

p { margin: 0 0 8px; color: var(--ink-muted); }

button {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  cursor: pointer;
  background: var(--teal);
  color: white;
  transition: background-color 0.15s ease;
}
button:hover { background: var(--teal-dark); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}
button.secondary {
  background: transparent;
  color: var(--teal);
  border: 1px solid var(--line);
  font-weight: 500;
}
button.secondary:hover { background: var(--surface); border-color: var(--teal); }
button.danger { background: var(--clay); }
button.danger:hover { background: #9E4B1E; }

input, select, textarea {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}

/* ---------- App shell ---------- */

#app { display: none; min-height: 100vh; }
#app.visible { display: flex; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--teal-dark);
  padding: 22px 0;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 20px 18px;
  border-bottom: 1px solid rgba(244, 241, 231, 0.1);
  margin-bottom: 14px;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--clay);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong {
  display: block;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--sidebar-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text span { font-size: 12px; color: var(--sidebar-ink-muted); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 20px;
  margin: 1px 0;
  color: var(--sidebar-ink-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
  cursor: pointer;
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-ink); }
.nav-item.active {
  color: var(--sidebar-ink);
  border-left-color: var(--clay);
  background: var(--sidebar-active);
  font-weight: 600;
}
.nav-item .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--clay); margin-left: auto;
}

.nav-item .icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nav-item .icon svg { width: 19px; height: 19px; display: block; }

.sidebar .logout {
  margin-top: auto;
  padding: 12px 20px 4px;
  font-size: 13px;
  color: var(--sidebar-ink-muted);
  cursor: pointer;
}
.sidebar .logout:hover { color: var(--sidebar-ink); }

.main {
  flex: 1;
  padding: 32px 36px 90px;
  max-width: 980px;
}

.section { display: none; }
.section.active {
  display: block;
  animation: section-fade-in 0.18s ease;
}
@keyframes section-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Buscador (estilo lista de chats de WhatsApp) ---------- */

.search-input {
  margin: 4px 0 14px;
  border-radius: 999px;
  background: var(--surface);
  padding: 10px 16px;
}
.search-input::placeholder { color: var(--ink-muted); }

/* ---------- Botón flotante (FAB), solo en celular ---------- */

.fab {
  display: none;
  position: fixed;
  right: 20px;
  bottom: 78px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--clay);
  color: white;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 28px -8px rgba(190, 90, 38, 0.55);
  z-index: 15;
  padding: 0;
}
.fab:hover { background: #9E4B1E; }
.fab svg { width: 24px; height: 24px; }

@media (min-width: 721px) {
  .fab { display: none !important; }
}

/* ---------- Cards / rows ---------- */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 18px 0 32px;
}
.summary-cell {
  background: var(--surface);
  padding: 18px 18px 16px;
}
.summary-cell .value {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.summary-cell .label { font-size: 13px; color: var(--ink-muted); margin-top: 3px; }

.alert-group { margin-bottom: 26px; }
.alert-group h3 { margin-bottom: 9px; }

.list {
  border-top: 1px solid var(--line);
}
.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}
.list-row .main-text { font-weight: 500; }
.list-row .sub-text { font-size: 13px; color: var(--ink-muted); margin-top: 1px; }
.list-row .amount { font-variant-numeric: tabular-nums; font-weight: 600; }

.list-row-tappable {
  cursor: pointer;
  margin: 0 -4px;
  padding-left: 4px;
  padding-right: 4px;
  border-radius: var(--radius-sm);
}
.list-row-tappable:hover, .list-row-tappable:active { background: var(--bg); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.badge.alert { background: var(--clay-bg); color: var(--clay); }
.badge.ok { background: var(--green-bg); color: var(--green); }
.badge.neutral { background: var(--bg); color: var(--ink-muted); }

/* ---------- Selector de período (Análisis → Ver reporte) ---------- */
.period-selector { display: flex; gap: 8px; margin: 4px 0 20px; flex-wrap: wrap; }
.period-btn {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-muted);
  font-weight: 500;
  font-size: 13px;
}
.period-btn:hover { background: var(--bg); }
.period-btn.active { background: var(--teal); color: var(--sidebar-ink); border-color: var(--teal); }

.bar-compare-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.bar-compare-label { width: 84px; font-size: 13px; color: var(--ink-muted); flex-shrink: 0; }
.bar-compare-track { flex: 1; background: var(--bg); border-radius: 6px; height: 22px; position: relative; overflow: hidden; min-width: 40px; }
.bar-compare-fill { height: 100%; border-radius: 6px; }
.bar-compare-fill.current { background: var(--teal); }
.bar-compare-fill.previous { background: var(--line); }
.bar-compare-value { width: 108px; text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; font-weight: 600; flex-shrink: 0; }
.bar-compare-legend { display: flex; gap: 18px; font-size: 12px; color: var(--ink-muted); margin: -4px 0 16px; }
.bar-compare-legend span { display: inline-flex; align-items: center; gap: 6px; }
.bar-compare-legend .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.bar-compare-legend .dot.current { background: var(--teal); }
.bar-compare-legend .dot.previous { background: var(--line); }

.form-row { margin-bottom: 13px; }
.form-row label { display: block; font-size: 13px; color: var(--ink-muted); margin-bottom: 5px; }
.form-actions { display: flex; gap: 8px; margin-top: 18px; }

.empty-state, .state-message {
  padding: 26px 0;
  color: var(--ink-muted);
  font-size: 14px;
}
.state-message.is-error { color: var(--clay); }

.error-text { color: var(--clay); font-size: 13px; margin-top: 6px; }

/* ---------- Login ---------- */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.login-box {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-brand);
  padding: 36px 32px;
  width: 100%;
  max-width: 350px;
}
.login-box h1 { margin-bottom: 5px; }
.login-box p { margin-bottom: 22px; }

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

#modal-box {
  border-radius: 14px;
  box-shadow: var(--shadow-brand);
}

/* ---------- Mobile: bottom nav instead of sidebar ---------- */

.bottom-nav { display: none; }

@media (max-width: 720px) {
  .sidebar { display: none; }
  .main { padding: 22px 18px 92px; max-width: none; }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--line);
    justify-content: space-around;
    padding: 7px 0;
    z-index: 10;
  }
  .bottom-nav .nav-item {
    flex-direction: column;
    gap: 3px;
    padding: 6px 8px;
    margin: 0;
    border-left: none;
    font-size: 11px;
    font-weight: 500;
    color: var(--ink-muted);
    text-align: center;
  }
  .bottom-nav .nav-item:hover { background: none; color: var(--ink-muted); }
  .bottom-nav .nav-item.active {
    border-left: none;
    background: none;
    color: var(--teal);
  }
  .bottom-nav .nav-item .icon svg { width: 21px; height: 21px; }
  .new-item-btn { display: none; }
}

/* ---------- Aviso de carga / error (siempre visible, nunca falla en silencio) ---------- */

#global-status {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 30;
  background: var(--teal-dark);
  color: var(--sidebar-ink);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  padding: 8px 12px;
}
#global-status.is-error { background: var(--clay); color: white; }

/* ---------- Menú "Más" (celular) ---------- */

.more-menu { display: flex; flex-direction: column; gap: 2px; }
.more-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 4px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.more-menu-item:last-child { border-bottom: none; }
.more-menu-item:hover { background: var(--bg); }
.more-menu-item .icon { color: var(--teal); flex-shrink: 0; }
.more-menu-item .icon svg { width: 20px; height: 20px; }
