:root {
  --bg: #06080c;
  --panel: #0d1118;
  --panel-2: #141a24;
  --border: rgba(255,255,255,0.08);
  --text: #f3f4f6;
  --muted: #9ca3af;
  --dim: #6b7280;
  --emerald: #10b981;
  --blue: #3b82f6;
  --amber: #f59e0b;
  --rose: #f43f5e;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--rose); font-size: 13px; min-height: 18px; margin-top: 6px; }

/* ---------- Login ---------- */
.login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% -10%, rgba(59,130,246,0.12), transparent 50%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 24px;
  text-align: center;
}
.brand { margin-bottom: 22px; }
.brand img { display: block; margin: 0 auto 10px; }
.brand h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.brand p { font-size: 13px; margin-top: 2px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
#pin {
  text-align: center; font-size: 22px; letter-spacing: 6px;
  font-family: var(--mono);
  padding: 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
}
#pin:focus { outline: none; border-color: var(--blue); }

/* ---------- App shell ---------- */
.app { max-width: 720px; margin: 0 auto; padding-bottom: 96px; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px calc(12px + env(safe-area-inset-top, 0));
  padding-top: max(16px, env(safe-area-inset-top, 0));
  background: rgba(6,8,12,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 800; font-size: 18px; letter-spacing: -0.3px; display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--emerald); box-shadow: 0 0 10px var(--emerald); }
.view { padding: 18px; }

/* ---------- Buttons ---------- */
button { font-family: inherit; cursor: pointer; }
.icon-btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 12px; font-size: 13px; font-weight: 600;
}
.icon-btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--emerald); color: #04130d; border: none;
  border-radius: 11px; padding: 13px 18px; font-weight: 700; font-size: 15px;
}
.btn-danger {
  background: transparent; color: var(--rose);
  border: 1px solid rgba(244,63,94,0.4); border-radius: 11px;
  padding: 13px 18px; font-weight: 700; font-size: 15px;
}
#login-btn {
  background: var(--emerald); color: #04130d; border: none;
  border-radius: 12px; padding: 14px; font-weight: 700; font-size: 16px;
}

/* FAB */
.fab {
  position: fixed; right: 20px; bottom: 84px; z-index: 20;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--emerald); color: #04130d; border: none;
  font-size: 30px; line-height: 1; font-weight: 600;
  box-shadow: 0 8px 24px rgba(16,185,129,0.35);
}
.fab:active { transform: scale(0.94); }

/* Tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; max-width: 720px; margin: 0 auto;
  background: rgba(13,17,24,0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 14px 0; font-size: 13px; font-weight: 600;
}
.tab.active { color: var(--emerald); }

/* ---------- Cards / lists ---------- */
.summary { display: flex; gap: 10px; margin-bottom: 18px; }
.chip {
  flex: 1; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; text-align: center;
}
.chip .n { font-size: 22px; font-weight: 800; font-family: var(--mono); }
.chip .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-top: 2px; }
.chip.vencido .n { color: var(--rose); }
.chip.proximo .n { color: var(--amber); }

.section-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 22px 4px 10px; font-weight: 700; }

.card {
  display: flex; align-items: stretch; gap: 12px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
  position: relative; overflow: hidden;
}
.card:active { background: var(--panel-2); }
.card .stripe { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.card .body { flex: 1; min-width: 0; padding-left: 4px; }
.card .titulo { font-weight: 600; font-size: 15px; }
.card .meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.card .when { font-weight: 600; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.monto { font-family: var(--mono); color: var(--text); }

.u-vencido { color: var(--rose); }
.u-hoy, .u-pronto { color: var(--amber); }
.u-proxima { color: var(--blue); }
.u-futuro, .u-sin_fecha { color: var(--dim); }
.s-vencido { background: var(--rose); }
.s-hoy, .s-pronto { background: var(--amber); }
.s-proxima { background: var(--blue); }
.s-futuro, .s-sin_fecha { background: var(--dim); }

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

/* areas */
.area-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.area-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.area-card:active { background: var(--panel-2); }
.area-card .nombre { font-weight: 700; font-size: 15px; }
.area-card .count { font-size: 12px; color: var(--muted); margin-top: 4px; }
.area-card .desc { font-size: 11.5px; color: var(--dim); margin-top: 6px; line-height: 1.35; }

.back-btn { background: none; border: none; color: var(--blue); font-size: 14px; font-weight: 600; padding: 0 0 12px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,0.6);
}
.modal-card {
  width: 100%; max-width: 720px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 20px 20px 0 0; padding: 20px;
  max-height: 92vh; overflow-y: auto;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
}
@media (min-width: 560px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 20px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h2 { font-size: 18px; font-weight: 700; }
#modal-close { font-size: 22px; line-height: 1; padding: 4px 10px; }
#item-form { display: flex; flex-direction: column; gap: 14px; }
#item-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
#item-form .row { display: flex; gap: 12px; }
#item-form .row label { flex: 1; }
#item-form input, #item-form select, #item-form textarea {
  font-family: inherit; font-size: 15px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px;
  text-transform: none; font-weight: 400; letter-spacing: 0;
}
#item-form input:focus, #item-form select:focus, #item-form textarea:focus { outline: none; border-color: var(--blue); }
#item-form textarea { resize: vertical; }
.modal-actions { display: flex; gap: 12px; margin-top: 6px; }
.modal-actions button { flex: 1; }
