@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Paleta de marca Katherine */
  --bg:        #0B1020;   /* Deep Space */
  --bg-2:      #0e1426;
  --panel:     #131a2e;   /* Graphite/panel */
  --border:    #243049;
  --text:      #F8FAFC;   /* Ghost White */
  --muted:     #94a3b8;
  --accent:    #7C3AED;   /* Neural Purple */
  --accent-2:  #3B82F6;   /* Cyber Blue */
  --grad:      linear-gradient(135deg, #7C3AED 0%, #3B82F6 100%);
  --danger:    #ef4444;
  --ok:        #22c55e;
  --radius:    14px;
  --font:      "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-head: "Space Grotesk", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ☀️ Modo día (claro). Se activa con la clase .light en <html>/<body>. */
html.light, body.light {
  --bg:     #F4F6FB;   /* fondo claro */
  --bg-2:   #E9EDF6;
  --panel:  #FFFFFF;   /* tarjetas */
  --border: #DCE2EE;
  --text:   #0B1020;   /* texto oscuro */
  --muted:  #5A6577;
  /* acentos, gradiente, ok/danger se mantienen */
}
/* Badges adaptados al modo día. */
body.light .badge.pendiente  { background: #fdf3d6; color: #8a6d12; }
body.light .badge.confirmada { background: #d9eef7; color: #176684; }
body.light .badge.realizada  { background: #d9f5e4; color: #15803d; }
body.light .badge.cancelada  { background: #fadcdc; color: #b42318; }
/* Transición suave al cambiar de tema. */
body { transition: background-color .25s ease, color .25s ease; }

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

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

h1, h2, h3, .brand, .page-head h1, .stat-card .val, .login-card .brand {
  font-family: var(--font-head);
}

a { color: var(--accent); text-decoration: none; }

/* ---------- Botones e inputs ---------- */
button, .btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: .15s ease;
}
button:hover, .btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--grad); color: #ffffff; border-color: transparent; }
.btn-primary:hover { filter: brightness(1.08); box-shadow: 0 8px 22px -8px rgba(124,58,237,.6); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 13px; }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field { margin-bottom: 14px; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #23232c 0%, var(--bg) 60%);
}
.login-card {
  width: 360px;
  max-width: 90vw;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 30px;
  text-align: center;
}
.login-card .brand { font-size: 26px; letter-spacing: 2px; font-weight: 700; color: var(--accent); }
.login-card .sub { color: var(--muted); font-size: 13px; margin: 6px 0 26px; letter-spacing: 1px; text-transform: uppercase; }
.login-card .field { text-align: left; }
.error-msg { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 4px; }

/* ---------- Layout admin ---------- */
/* Menú lateral estático: el layout ocupa exactamente la pantalla y solo el
   contenido principal (.main) hace scroll. */
.layout { display: grid; grid-template-columns: 240px 1fr; height: 100vh; overflow: hidden; }
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;   /* por si el menú es más alto que la pantalla */
}
.sidebar .brand { display: flex; align-items: center; gap: 9px; font-size: 20px; font-weight: 700; color: var(--text); letter-spacing: 1px; padding: 0 10px 22px; }
.brand-ic { width: 26px; height: 26px; display: inline-block; vertical-align: middle; }
.mobile-topbar .mt-brand { display: inline-flex; align-items: center; gap: 8px; }
.mobile-topbar .brand-ic { width: 22px; height: 22px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 10px;
  color: var(--muted); font-weight: 600; font-size: 14px;
  cursor: pointer; margin-bottom: 4px;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel); color: var(--accent); }
.nav-item .ico { width: 18px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
  padding: 1px 6px;
  border-radius: 20px;
}
.sidebar .spacer { flex: 1; }
.prospecto-nuevo { font-weight: 700; }
.prospecto-nuevo td:first-child { border-left: 3px solid var(--accent); }
.dot-nuevo { display:inline-block; width:8px; height:8px; border-radius:50%; background:var(--accent); margin-right:6px; }
.user-box { font-size: 13px; color: var(--muted); padding: 12px 10px; border-top: 1px solid var(--border); }
.user-box strong { color: var(--text); display: block; }

.main { padding: 30px 36px; height: 100vh; overflow-y: auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-head h1 { font-size: 24px; font-weight: 700; }

/* ---------- Tarjetas de estadística ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat-card .val { font-size: 30px; font-weight: 700; color: var(--accent); }
.stat-card .lbl { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ---------- Tablas ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 0; overflow: hidden; }
.panel h2 { font-size: 16px; padding: 16px 20px 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 20px; font-size: 14px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-2); }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.pendiente  { background: #3a341f; color: #e0c178; }
.badge.confirmada { background: #1f343a; color: #78c9e0; }
.badge.realizada  { background: #1f3a2a; color: #78e0a4; }
.badge.cancelada  { background: #3a1f1f; color: #e07878; }

.empty { padding: 40px; text-align: center; color: var(--muted); }
.toolbar { display: flex; gap: 12px; margin-bottom: 18px; align-items: center; }
.toolbar input { max-width: 320px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: none; place-items: center; z-index: 50; padding: 20px;
}
.modal-overlay.open { display: grid; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  width: 480px; max-width: 95vw; max-height: 90vh; overflow-y: auto; padding: 26px;
}
.modal h3 { margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 100;
}
#toast.show { opacity: 1; }
#toast.error { border-color: var(--danger); color: #f3a8a2; }

.hidden { display: none !important; }

/* ---------- Calendario (agenda) ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.cal-title { font-family: var(--font-head); font-size: 18px; font-weight: 600; }
.cal-nav { display: flex; gap: 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--muted); padding: 4px 0; text-transform: uppercase; letter-spacing: .5px; }
.cal-cell { min-height: 52px; border: 1px solid var(--border); border-radius: 9px; padding: 5px 4px; cursor: pointer; background: var(--bg-2); transition: border-color .15s; }
.cal-cell:hover { border-color: var(--accent); }
.cal-cell.empty { background: transparent; border: 0; cursor: default; }
.cal-cell.today { border-color: var(--accent-2); }
.cal-cell.sel { outline: 2px solid var(--accent); outline-offset: -1px; }
.cal-daynum { font-size: 12.5px; color: var(--text); text-align: center; }
.cal-dot-row { display: flex; gap: 3px; justify-content: center; margin-top: 5px; flex-wrap: wrap; }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.agenda-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 14px; -webkit-overflow-scrolling: touch; }
.atab { flex: 0 0 auto; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.atab:hover { border-color: var(--accent); color: var(--text); }
.atab.on { background: var(--grad); color: #fff; border-color: transparent; }

/* ---------- Barra superior móvil + menú deslizable ---------- */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

/* ====================================================================
   RESPONSIVE — iPhone / móviles (≤ 820px)
   ==================================================================== */
@media (max-width: 820px) {
  /* Layout en una sola columna */
  .layout { display: block; height: auto; overflow: visible; }

  /* Barra superior fija con botón de menú */
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 40;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
  }
  .menu-toggle {
    font-size: 22px;
    line-height: 1;
    background: transparent;
    border: none;
    color: var(--text);
    padding: 4px 8px;
  }
  .mobile-topbar .mt-brand { font-weight: 700; letter-spacing: 1px; color: var(--accent); }

  /* Sidebar como cajón deslizable */
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100dvh;
    width: 250px;
    max-width: 82vw;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 60;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 50;
  }
  .sidebar-backdrop.show { display: block; }

  /* Toques cómodos */
  .nav-item { padding: 14px 12px; }

  /* Contenido principal: en móvil scroll normal de página (no contenedor fijo) */
  .main { padding: 18px 14px; height: auto; overflow: visible; }
  .page-head { flex-wrap: wrap; gap: 12px; }
  .page-head h1 { font-size: 21px; }

  /* Tarjetas de estadística más compactas */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 15px; }
  .stat-card .val { font-size: 23px; }

  /* Tablas: desplazamiento horizontal con el dedo */
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 520px; }
  th, td { padding: 11px 14px; }

  /* Columnas dobles → una sola */
  .grid-2 { grid-template-columns: 1fr; }
  .dos-col { grid-template-columns: 1fr !important; }

  /* Barras de herramientas y filtros que envuelven */
  .toolbar { flex-wrap: wrap; }
  .toolbar input { max-width: 100%; }

  /* Modales a pantalla casi completa */
  .modal { width: 100%; max-width: 100%; padding: 22px 18px; border-radius: 16px; }
  .modal-overlay { padding: 10px; align-items: flex-start; }
}

/* Sección de dos columnas (contabilidad) — clase para poder apilar en móvil */
.dos-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 24px; }

@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
}
