/* ============================================================
   theme.css — Sistema de Ventas Funeraria Jardín
   ============================================================ */

/* ─── Variables ─────────────────────────────────────────────── */
:root {
  --bg:      #0f1117;
  --bg2:     #181c24;
  --bg3:     #222736;
  --bg4:     #2a3045;
  --border:  #2e3450;
  --accent:  #6366f1;
  --accent2: #a5b4fc;
  --accent-soft: rgba(99,102,241,.15);
  --text:    #e8eaf0;
  --text2:   #8b91a8;
  --text3:   #4a5068;
  --danger:  #e05c5c;
  --danger-soft: rgba(224,92,92,.15);
  --success: #4caf7d;
  --success-soft: rgba(76,175,125,.15);
  --warning: #e8a93e;
  --warning-soft: rgba(232,169,62,.15);
  --info:    #5b9cf6;
  --info-soft: rgba(91,156,246,.15);
  --gold:    #d4a847;
  --gold-soft: rgba(212,168,71,.15);
  --radius:  12px;
  --radius-sm: 8px;
  --shadow:  0 4px 24px rgba(0,0,0,.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.25);
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --gap: 16px;
}

/* ─── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--accent2); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  background: var(--bg3);
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  outline: none;
  transition: border .15s, box-shadow .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select option { background: var(--bg3); }
textarea { resize: vertical; min-height: 72px; }

/* ─── Layout ─────────────────────────────────────────────────── */
#app { display: flex; min-height: 100vh; }

/* Sidebar */
#sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s;
}
.sidebar-logo {
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .logo-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .3px;
  line-height: 1.3;
}
.sidebar-logo .logo-sub {
  font-size: 11px;
  color: var(--text3);
  margin-top: 2px;
}
.nav-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text3);
  padding: 14px 18px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 0;
  color: var(--text2);
  font-size: 13.5px;
  cursor: pointer;
  transition: background .12s, color .12s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent2); }
.nav-item .badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 20px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}
.sidebar-footer {
  margin-top: auto;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-footer .user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: var(--accent2);
  flex-shrink: 0;
}
.sidebar-footer .user-info { flex: 1; overflow: hidden; }
.sidebar-footer .user-name {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-footer .user-role { font-size: 11px; color: var(--text3); }
#btn-logout {
  background: none; border: none; color: var(--text3);
  padding: 4px; border-radius: 6px; display: flex;
  transition: color .12s;
}
#btn-logout:hover { color: var(--danger); }
#btn-logout svg { width: 16px; height: 16px; }

/* Topbar */
#topbar {
  position: fixed;
  top: 0; left: var(--sidebar-w); right: 0;
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 90;
  gap: 12px;
}
#btn-menu-mobile {
  display: none;
  background: none; border: none; color: var(--text2); padding: 6px;
  border-radius: 8px; cursor: pointer;
}
#btn-menu-mobile svg { width: 22px; height: 22px; }
#topbar-title {
  font-size: 16px; font-weight: 600; flex: 1;
}
#topbar-actions { display: flex; gap: 8px; }

/* Main content */
#main {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  padding: 24px;
  flex: 1;
  min-width: 0;
}

/* Pages */
.page { display: none; }
.page.active { display: block; }

/* ─── Login ──────────────────────────────────────────────────── */
#page-login {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 60% 40%, rgba(99,102,241,.12) 0%, transparent 70%),
              var(--bg);
  padding: 20px;
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo .login-icon {
  width: 64px; height: 64px;
  border-radius: 16px;
  background: var(--accent-soft);
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.login-logo .login-icon svg { width: 32px; height: 32px; color: var(--accent2); }
.login-logo h1 { font-size: 20px; font-weight: 700; }
.login-logo p { font-size: 13px; color: var(--text3); margin-top: 4px; }

/* ─── Cards y contenedores ───────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-hdr {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px;
  flex-wrap: wrap;
}
.card-title {
  font-size: 15px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.card-title svg { width: 18px; height: 18px; color: var(--accent2); }

/* Grid de KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--gap);
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi-card .kpi-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
}
.kpi-card .kpi-icon svg { width: 22px; height: 22px; }
.kpi-card .kpi-val {
  font-size: 24px; font-weight: 700; line-height: 1;
  margin-bottom: 4px;
}
.kpi-card .kpi-lbl {
  font-size: 12px; color: var(--text2);
}
.kpi-card.accent .kpi-icon { background: var(--accent-soft); color: var(--accent2); }
.kpi-card.success .kpi-icon { background: var(--success-soft); color: var(--success); }
.kpi-card.warning .kpi-icon { background: var(--warning-soft); color: var(--warning); }
.kpi-card.info .kpi-icon { background: var(--info-soft); color: var(--info); }
.kpi-card.accent .kpi-val { color: var(--accent2); }
.kpi-card.success .kpi-val { color: var(--success); }
.kpi-card.warning .kpi-val { color: var(--warning); }
.kpi-card.info .kpi-val { color: var(--info); }

/* ─── Botones ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600;
  border: none; cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-a { background: var(--accent); color: #fff; }
.btn-a:hover { background: #5254cc; }
.btn-g { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-g:hover { background: var(--bg4); }
.btn-s { background: var(--success); color: #fff; }
.btn-s:hover { filter: brightness(1.1); }
.btn-d { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(224,92,92,.3); }
.btn-d:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); background: var(--bg3); border: 1px solid var(--border); color: var(--text2); }
.btn-icon:hover { color: var(--text); background: var(--bg4); }
.btn-icon svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ─── Formularios ────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label {
  font-size: 12.5px; font-weight: 600; color: var(--text2);
  display: flex; align-items: center; gap: 5px;
}
.form-group label svg { width: 13px; height: 13px; }
.form-group.full { grid-column: 1 / -1; }
.form-sep {
  grid-column: 1 / -1;
  border: none; border-top: 1px solid var(--border);
  margin: 4px 0;
}
.form-section-title {
  grid-column: 1 / -1;
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text3);
  padding-top: 4px;
  display: flex; align-items: center; gap: 8px;
}
.form-section-title::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.input-prefix {
  position: relative;
}
.input-prefix span {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text3); font-size: 13px; pointer-events: none;
}
.input-prefix input { padding-left: 24px; }

/* ─── Tablas ─────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; }
.tbl {
  width: 100%; border-collapse: collapse;
  font-size: 13.5px;
}
.tbl th {
  text-align: left; padding: 10px 14px;
  font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl td {
  padding: 11px 14px;
  border-bottom: 1px solid rgba(46,52,80,.5);
  vertical-align: middle;
}
.tbl tr:hover td { background: rgba(255,255,255,.02); }
.tbl tr:last-child td { border-bottom: none; }

/* ─── Modales ────────────────────────────────────────────────── */
.modal-bg {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  z-index: 200; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%; max-height: calc(100vh - 40px);
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { transform: scale(.96) translateY(10px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.modal-hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg2); z-index: 1;
}
.modal-hdr .modal-title {
  font-size: 15px; font-weight: 700;
  display: flex; align-items: center; gap: 9px;
}
.modal-hdr .modal-title svg { width: 20px; height: 20px; color: var(--accent2); }
.modal-body { padding: 22px; }
.modal-footer {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
  flex-wrap: wrap;
  position: sticky; bottom: 0; background: var(--bg2); z-index: 1;
}
.icon-btn {
  background: none; border: none; color: var(--text2);
  display: flex; padding: 5px; border-radius: 8px;
  transition: color .12s, background .12s;
}
.icon-btn:hover { color: var(--text); background: var(--bg3); }
.icon-btn svg { width: 18px; height: 18px; }

/* ─── Pills y badges ─────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill-activo    { background: var(--info-soft);    color: var(--info); }
.pill-completado{ background: var(--success-soft); color: var(--success); }
.pill-cancelado { background: var(--danger-soft);  color: var(--danger); }
.pill-funerario   { background: rgba(99,102,241,.15); color: #a5b4fc; }
.pill-parcela     { background: var(--gold-soft); color: var(--gold); }
.pill-cremacion   { background: rgba(224,92,92,.12); color: #f08080; }
.pill-prenecesidad{ background: var(--success-soft); color: var(--success); }
.pill-otro        { background: var(--bg3); color: var(--text2); }

/* ─── Toast ──────────────────────────────────────────────────── */
#toast-wrap {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-size: 13.5px; color: var(--text);
  max-width: 340px;
  animation: toastIn .25s ease;
  pointer-events: auto;
}
.toast-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast-item.error { border-color: var(--danger); }
.toast-item.error svg { color: var(--danger); }
.toast-item.success { border-color: var(--success); }
.toast-item.success svg { color: var(--success); }
.toast-item.warn { border-color: var(--warning); }
.toast-item.warn svg { color: var(--warning); }
@keyframes toastIn {
  from { transform: translateX(30px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ─── Loading spinner ────────────────────────────────────────── */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-state {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; padding: 48px; color: var(--text3); font-size: 13px;
}

/* ─── Empty state ────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding: 52px 20px; text-align: center;
  color: var(--text3);
}
.empty-state svg { width: 48px; height: 48px; opacity: .4; }
.empty-state p { font-size: 14px; }

/* ─── Divider con texto ──────────────────────────────────────── */
.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--text3); font-size: 12px; margin: 8px 0;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ─── Autocomplete dropdown ──────────────────────────────────── */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  z-index: 50; max-height: 200px; overflow-y: auto;
  display: none;
}
.autocomplete-list.open { display: block; }
.autocomplete-item {
  padding: 9px 12px; cursor: pointer; font-size: 13.5px;
  transition: background .1s;
  border-bottom: 1px solid rgba(46,52,80,.5);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--bg4); }
.autocomplete-item .ac-sub { font-size: 11.5px; color: var(--text3); }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  #sidebar {
    transform: translateX(-240px);
    width: 240px;
  }
  #sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,.5); }
  #topbar { left: 0; }
  #main { margin-left: 0; padding: 16px; }
  #btn-menu-mobile { display: flex; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .modal-bg { padding: 12px; align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; }
}
@media (max-width: 400px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .btn { padding: 8px 12px; font-size: 13px; }
}
