/*
 * CIMA · Ventas — Panel de Ventas
 * Archivo: app/style/app.css
 * Estilo CRM profesional. Fondo sólido (blanco en claro, casi-negro en oscuro),
 * automático por prefers-color-scheme. Acento de marca: aguamarina #00afc2.
 */

:root {
  color-scheme: light dark;

  --accent: #00afc2;
  --accent-rgb: 0, 175, 194;
  --accent-ink: #ffffff;
  --navy: #04346c;

  /* ---- Tema claro (por defecto) ---- */
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --surface-hover: #eef1f4;
  --border: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text: #0f172a;
  --text-muted: rgba(15, 23, 42, 0.60);
  --text-faint: rgba(15, 23, 42, 0.40);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 28px rgba(15, 23, 42, 0.06);
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.08);
  --danger-border: rgba(220, 38, 38, 0.24);
  --logo-navy: #04346c;

  --radius: 14px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0d13;
    --surface: #11151d;
    --surface-2: #0d1017;
    --surface-hover: #191f2a;
    --border: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.16);
    --text: #eef3fb;
    --text-muted: rgba(238, 243, 251, 0.62);
    --text-faint: rgba(238, 243, 251, 0.38);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 14px 34px rgba(0, 0, 0, 0.45);
    --danger: #f87171;
    --danger-bg: rgba(248, 113, 113, 0.12);
    --danger-border: rgba(248, 113, 113, 0.30);
    --logo-navy: #eef3fb;
  }
}

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

html, body { height: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

button, input { font-family: inherit; }

/* ───────────────────── Marca: colores del SVG inlineado ───────────────────── */
.cima-c-accent { fill: var(--accent); }
.cima-c-navy { fill: var(--logo-navy); transition: fill 0.15s ease; }

/* ───────────────────── Login ───────────────────── */
.vw-login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.vw-login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 32px 32px;
}

.vw-login-brand {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.vw-login-brand svg {
  width: 168px;
  height: auto;
}

.vw-login-tag {
  text-align: center;
  margin-bottom: 30px;
  font-size: 12.5px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.vw-field {
  margin-bottom: 16px;
}

.vw-field label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.vw-field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14.5px;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.vw-field input::placeholder {
  color: var(--text-faint);
}

.vw-field input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.16);
}

.vw-submit {
  width: 100%;
  margin-top: 8px;
  padding: 12px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.vw-submit:hover { background: #0098a9; }
.vw-submit:active { transform: translateY(1px); }
.vw-submit:disabled { opacity: 0.6; cursor: default; }

.vw-error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  font-size: 13px;
  display: none;
}

.vw-error.is-visible { display: block; }

/* ───────────────────── Shell del panel (sidebar + contenido) ───────────────────── */
.vw-shell {
  min-height: 100vh;
  display: flex;
}

.vw-sidebar {
  width: 240px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.vw-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  border-bottom: 1px solid var(--border);
}

.vw-sidebar-brand svg {
  width: 26px;
  height: auto;
  flex-shrink: 0;
}

.vw-sidebar-brand-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
  line-height: 1.15;
}

.vw-sidebar-brand-text em {
  display: block;
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.vw-sidebar-nav {
  flex: 1;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.vw-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.vw-nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.vw-nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.vw-nav-item.is-active {
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--accent);
}

.vw-nav-item .vw-nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: inherit;
}

.vw-nav-item.is-loading {
  opacity: 0.6;
  pointer-events: none;
}

.vw-nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
}

.vw-sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vw-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vw-logout-btn {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.vw-logout-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

/* ───────────────────── Contenido principal ───────────────────── */
.vw-main {
  flex: 1;
  min-width: 0;
  padding: 32px 36px 48px;
  max-width: 1160px;
}

.vw-header {
  margin-bottom: 26px;
}

.vw-header h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.vw-header p {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 640px;
}

/* KPIs */
.vw-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.vw-kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vw-kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.vw-kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.vw-kpi-icon svg { width: 16px; height: 16px; }

.vw-kpi-soon {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
}

.vw-kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.vw-kpi-label {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Paneles de contenido / tabs */
.vw-tab-panel { display: block; }
.vw-tab-panel[hidden] { display: none; }

.vw-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.vw-panel-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.vw-panel-head h2 {
  font-size: 15px;
  font-weight: 700;
}

.vw-panel-head p {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.vw-panel-body {
  padding: 22px;
}

/* Siguientes pasos (Inicio) */
.vw-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.vw-step {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  background: var(--surface-2);
}

.vw-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(var(--accent-rgb), 0.15);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 700;
  margin-bottom: 10px;
}

.vw-step h3 {
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 4px;
}

.vw-step p {
  font-size: 12.5px;
  color: var(--text-muted);
}

.vw-step-action {
  margin-top: 10px;
  border: none;
  background: none;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.vw-step-action:hover { text-decoration: underline; }

/* Tabla placeholder */
.vw-table-wrap { overflow-x: auto; }

.vw-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.vw-table th {
  text-align: left;
  padding: 10px 22px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.vw-table td {
  padding: 28px 22px;
  color: var(--text-muted);
  text-align: center;
}

/* Estado vacío genérico */
.vw-empty {
  padding: 8px 4px 4px;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* ───────────────────── Formularios (Perfil) ───────────────────── */
.vw-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 2px 20px;
}

.vw-form-submit {
  width: auto;
  margin-top: 8px;
  padding: 10px 22px;
}

@media (max-width: 640px) {
  .vw-form-submit { width: 100%; }
}

/* ───────────────────── Ventana flotante embebida (Demo) ─────────────────────
   Patrón inspirado en el emulador de SIMA (sima/modules/support.js): barra de
   título arrastrable + minimizar/maximizar/cerrar + iframe. */
.vw-float-win {
  position: fixed;
  z-index: 400;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.32), var(--shadow);
  overflow: hidden;
}

.vw-float-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  cursor: move;
  user-select: none;
  flex-shrink: 0;
}

.vw-float-title {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vw-float-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.vw-float-btn {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.12s ease, color 0.12s ease;
}

.vw-float-btn svg { width: 13px; height: 13px; }

.vw-float-btn:hover { background: var(--surface-hover); color: var(--text); }

.vw-float-btn.vw-float-close:hover { background: var(--danger-bg); color: var(--danger); }

.vw-float-body {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--surface-2);
}

.vw-float-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #0b0f13;
}

.vw-float-iframe[hidden] { display: none; }

.vw-float-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.vw-float-loading.is-error { color: var(--danger); }

.vw-float-loading .vw-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: vw-spin 0.8s linear infinite;
}

.vw-float-loading.is-error .vw-spinner { display: none; }

@keyframes vw-spin { to { transform: rotate(360deg); } }

.vw-float-resize {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  z-index: 2;
}

.vw-float-resize::after {
  content: '';
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--border-strong);
  border-bottom: 2px solid var(--border-strong);
  border-radius: 0 0 2px 0;
}

/* Minimizada: colapsa a un chip pequeño anclado abajo a la derecha. */
.vw-float-win.is-minimized {
  width: 240px !important;
  height: auto !important;
  left: auto !important;
  top: auto !important;
  right: 20px;
  bottom: 20px;
  box-shadow: var(--shadow);
}

.vw-float-win.is-minimized .vw-float-body,
.vw-float-win.is-minimized .vw-float-resize { display: none; }

.vw-float-win.is-minimized .vw-float-bar {
  cursor: pointer;
  border-bottom: none;
}

.vw-float-win.is-minimized .vw-float-max { display: none; }

/* Maximizada: ocupa casi toda la ventana del panel. */
.vw-float-win.is-maximized {
  left: 16px !important;
  top: 16px !important;
  width: calc(100vw - 32px) !important;
  height: calc(100vh - 32px) !important;
}

.vw-float-win.is-maximized .vw-float-bar { cursor: default; }

.vw-float-win.is-maximized .vw-float-resize { display: none; }

@media (max-width: 640px) {
  .vw-float-win.is-minimized {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px) !important;
    max-width: 280px;
  }
}

/* ───────────────────── Toast (reemplaza alert/confirm nativos) ───────────────────── */
.vw-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  z-index: 50;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 13.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.vw-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.vw-toast.is-error {
  border-color: var(--danger-border);
  color: var(--danger);
}

/* ───────────────────── Responsive ───────────────────── */
@media (max-width: 860px) {
  .vw-shell { flex-direction: column; }

  .vw-sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  /* Fila 1: marca ... usuario/salir. Fila 2: nav horizontal a todo lo ancho. */
  .vw-sidebar-brand {
    order: 1;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 12px 14px;
  }

  .vw-sidebar-brand-text em { display: none; }

  .vw-sidebar-nav {
    order: 3;
    flex-basis: 100%;
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    padding: 8px 10px;
    gap: 4px;
    border-top: 1px solid var(--border);
  }

  .vw-nav-item { flex-shrink: 0; white-space: nowrap; }
  .vw-nav-item span:not(.vw-nav-badge) { display: inline; }

  .vw-sidebar-footer {
    order: 2;
    flex-direction: row;
    align-items: center;
    border-top: none;
    border-left: 1px solid var(--border);
    margin-left: auto;
    padding: 10px 14px;
  }

  .vw-user-name { max-width: 90px; }

  .vw-main { padding: 24px 18px 40px; }
}

@media (max-width: 640px) {
  .vw-login-card { padding: 32px 22px 26px; }
  .vw-kpi-grid { grid-template-columns: 1fr 1fr; }
  .vw-steps { grid-template-columns: 1fr; }
}

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