/**
 * GNZDEV Design System - Estilo Apple Human Interface (Inspirado en GPW)
 * Sin dependencias externas ni Bootstrap. 100% CSS nativo.
 */

:root,
[data-theme="dark"] {
  --font-apple: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Plus Jakarta Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* Colores del Sistema Apple */
  --apple-blue: #007AFF;
  --apple-blue-hover: #0062cc;
  --apple-indigo: #5856D6;
  --apple-purple: #AF52DE;
  --apple-pink: #FF2D55;
  --apple-red: #FF3B30;
  --apple-orange: #FF9500;
  --apple-yellow: #FFCC00;
  --apple-green: #34C759;
  --apple-teal: #30B0C7;
  --apple-mint: #00C7BE;
  --apple-cyan: #32ADE6;

  /* Superficies y Sombras Dark Mode HIG */
  --bg-dark: #000000;
  --bg-canvas: #09090b;
  --bg-sidebar: #121214;
  --bg-card: #1c1c1e;
  --bg-card-hover: #242426;
  --bg-surface: #2c2c2e;
  --bg-input: #232326;
  --bg-popover: rgba(20, 20, 24, 0.96);
  --bg-topbar-glass: rgba(18, 18, 20, 0.85);
  --bg-sidebar-glass: rgba(18, 18, 20, 0.85);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.14);
  --border-active: rgba(0, 122, 255, 0.5);

  /* Texto */
  --text-primary: #FFFFFF;
  --text-secondary: #AEAEB2;
  --text-muted: #8E8E93;
  --text-tertiary: #636366;

  /* Botones secundarios e interactivos */
  --btn-secondary-bg: rgba(255, 255, 255, 0.08);
  --btn-secondary-hover: rgba(255, 255, 255, 0.14);

  /* Radios de borde Apple */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-pill: 9999px;

  /* Sombras */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.45);
  --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 20px rgba(0, 122, 255, 0.35);
}

[data-theme="light"] {
  --font-apple: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Plus Jakarta Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* Colores del Sistema Apple para modo claro */
  --apple-blue: #007AFF;
  --apple-blue-hover: #0062cc;
  --apple-indigo: #5856D6;
  --apple-purple: #AF52DE;
  --apple-pink: #FF2D55;
  --apple-red: #D70015;
  --apple-orange: #C93400;
  --apple-yellow: #B25000;
  --apple-green: #248A3D;
  --apple-teal: #008299;
  --apple-mint: #00827D;
  --apple-cyan: #0071A4;

  /* Superficies y Sombras Light Mode Apple HIG */
  --bg-dark: #e5e5ea;
  --bg-canvas: #f2f2f7;
  --bg-sidebar: #fbfbfd;
  --bg-card: #ffffff;
  --bg-card-hover: #f2f2f7;
  --bg-surface: #e5e5ea;
  --bg-input: #ffffff;
  --bg-popover: rgba(255, 255, 255, 0.98);
  --bg-topbar-glass: rgba(255, 255, 255, 0.88);
  --bg-sidebar-glass: rgba(251, 251, 253, 0.88);
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-medium: rgba(0, 0, 0, 0.14);
  --border-active: rgba(0, 122, 255, 0.6);

  /* Texto Light Mode */
  --text-primary: #1c1c1e;
  --text-secondary: #48484a;
  --text-muted: #8e8e93;
  --text-tertiary: #aeaeb2;

  /* Botones secundarios */
  --btn-secondary-bg: rgba(0, 0, 0, 0.06);
  --btn-secondary-hover: rgba(0, 0, 0, 0.10);

  /* Sombras */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.1);
  --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.08);
  --shadow-glow: 0 0 20px rgba(0, 122, 255, 0.2);
}

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

body {
  font-family: var(--font-apple);
  background-color: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

input, textarea, [contenteditable="true"], .selectable, pre, code {
  user-select: text !important;
  -webkit-user-select: text !important;
}

/* Scrollbar Minimalista Apple (de GPW) */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Contenedor Principal Split-View macOS (3 Columnas / 2 Columnas) */
.apple-app-layout {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  max-width: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
}

/* Sidebar estilo macOS */
.apple-sidebar {
  width: 290px;
  min-width: 290px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  z-index: 40;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.apple-sidebar-header {
  padding: 1.25rem 1.25rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-sidebar-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-primary);
}

.brand-logo-img {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  object-fit: cover;
}

.brand-text h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.brand-text p {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: -0.01em;
}

.sidebar-section {
  padding: 1rem 0.85rem 0.5rem;
}

.sidebar-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 0.5rem 0.5rem;
}

.sidebar-nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-nav-item:hover {
  background-color: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.sidebar-nav-item.active {
  background-color: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  font-weight: 600;
}

.nav-item-left {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.squircle-icon {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  flex-shrink: 0;
}

.badge-counter {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.09);
  color: var(--text-secondary);
  font-weight: 600;
}

/* Área de contenido central */
.apple-content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-canvas);
}

/* Barra superior estilo macOS / iOS */
.apple-topbar {
  height: 60px;
  min-height: 60px;
  padding: 0 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-topbar-glass);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 200;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.mobile-menu-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
}

.search-spotlight {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.85rem;
  width: 320px;
  transition: all 0.2s ease;
}

.search-spotlight:focus-within {
  border-color: var(--apple-blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

.search-spotlight input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.88rem;
  width: 100%;
  font-family: inherit;
}

.search-spotlight input::placeholder {
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: nowrap;
  white-space: nowrap;
}

#userPillContainer,
.user-pill-container {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
  white-space: nowrap;
}

/* Botones Apple */
.btn-apple {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  text-decoration: none;
  font-family: inherit;
}

.btn-apple:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--apple-blue);
  color: #FFFFFF;
}

.btn-primary:hover {
  background: var(--apple-blue-hover);
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.35);
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--btn-secondary-hover);
}

.btn-danger {
  background: rgba(255, 59, 48, 0.15);
  color: var(--apple-red);
  border-color: rgba(255, 59, 48, 0.3);
}

.btn-danger:hover {
  background: var(--apple-red);
  color: #FFFFFF;
}

/* Perfil de Usuario en Barra */
.user-pill {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 4px 10px 4px 4px;
  background: var(--btn-secondary-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.15s ease;
}

.user-pill:hover {
  background: var(--btn-secondary-hover);
}

.user-avatar-tiny {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: #2c2c2e;
}

.user-pill-info {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.user-pill-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.user-pill-code {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  color: var(--apple-blue);
  font-weight: 600;
}

/* Dynamic Island Toast Notifications (de GPW) */
.toast-container {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}

.apple-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(28, 28, 30, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-glass);
  font-size: 0.88rem;
  color: #FFFFFF;
  animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Modales Estilo Apple */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 1rem;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-glass);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.modal-overlay.open .modal-dialog {
  transform: scale(1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal-close-btn {
  background: var(--btn-secondary-bg);
  border: none;
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.modal-close-btn:hover {
  background: var(--btn-secondary-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Formularios Apple */
.form-group {
  margin-bottom: 1.1rem;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.85rem;
  font-size: 0.9rem;
  color: var(--text-primary);
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--apple-blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.25);
}

.form-help {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

/* Telón de fondo móvil del Sidebar */
.apple-mobile-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.apple-mobile-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* Media queries para mobile y tablet */
@media (max-width: 900px) {
  .apple-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    box-shadow: 12px 0 35px rgba(0, 0, 0, 0.7);
  }
  .apple-sidebar.mobile-open {
    transform: translateX(0);
  }
  .mobile-menu-btn {
    display: block;
  }
  .apple-topbar {
    padding: 0 1.25rem;
  }
  .search-spotlight {
    width: 220px;
  }
}

@media (max-width: 640px) {
  .apple-topbar {
    padding: 0 0.65rem;
    height: 54px;
    min-height: 54px;
  }
  .topbar-left {
    gap: 0.5rem;
  }
  .search-spotlight {
    width: 140px;
    padding: 0.35rem 0.55rem;
  }
  .search-spotlight input {
    font-size: 0.8rem;
  }
  .topbar-right {
    gap: 0.35rem;
  }
  .topbar-right .btn-apple {
    padding: 0.4rem 0.6rem;
    font-size: 0.82rem;
  }
  .topbar-right .btn-apple span {
    display: none;
  }
  .user-pill {
    padding: 3px 6px;
    gap: 6px;
  }
  .user-pill-code {
    display: none;
  }
  .user-pill-name {
    max-width: 75px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.82rem;
  }
  .modal-dialog {
    width: 95vw !important;
    max-width: 95vw !important;
    margin: 12px auto;
  }
}

@media (max-width: 480px) {
  .search-spotlight {
    width: 105px;
  }
  .search-spotlight input::placeholder {
    font-size: 0.75rem;
  }
}
