/* ==========================================================================
   Proyectos Global — Portal de Clientes
   Sistema de diseño alineado con proyectosglobal.cl (Light & Dark Adaptive)
   ========================================================================== */

:root {
  /* Core Brand Tokens (proyectosglobal.cl) */
  --deep: #0B2A45;
  --deep-2: #071C30;
  --blue: #22548A;
  --aqua: #2E7D1A;
  --aqua-hover: #256815;
  --aqua-2: #5DBB3A;
  --heat: #E8833A;
  --alert: #D9482B;
  --live: #3DDC84;

  /* Light Theme (Default) */
  --bg: #F3F6FA;
  --surface: #FFFFFF;
  --surface-2: #E6EDF5;
  --line: #D3DEEA;
  --title: #0B2A45;
  --ink: #0D1E33;
  --ink-2: #4A5D75;
  --accent: #2E7D1A;
  --shadow: 0 12px 32px -14px rgba(11, 42, 69, 0.28);
  --shadow-sm: 0 4px 12px -4px rgba(11, 42, 69, 0.14);

  /* Sidebar Tokens (siempre Navy corporativo) */
  --sidebar-bg: #0B2A45;
  --sidebar-bg-deep: #071C30;
  --sidebar-border: rgba(255, 255, 255, 0.09);
  --sidebar-text: #E6EEF7;
  --sidebar-muted: #93ACC7;
  --sidebar-item-hover: rgba(255, 255, 255, 0.09);
  --sidebar-item-active: #2E7D1A;

  /* Typography */
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  /* Layout */
  --sidebar-width: 272px;
  --header-height: 60px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="dark"] {
  --bg: #06121F;
  --surface: #0C1D31;
  --surface-2: #122A45;
  --line: #1F3A5C;
  --title: #FFFFFF;
  --ink: #E6EEF7;
  --ink-2: #A3B6CC;
  --accent: #5DBB3A;
  --shadow: 0 16px 40px -14px rgba(0, 0, 0, 0.7);
  --shadow-sm: 0 4px 14px -4px rgba(0, 0, 0, 0.5);
}

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

html, body {
  height: 100%;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, a {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

/* Theme Icon Switching */
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* ==========================================================================
   1. Boot Screen
   ========================================================================== */
.boot-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 9999;
}

.boot-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px;
}

.boot-text {
  font-size: 0.92rem;
  color: var(--ink-2);
  font-weight: 500;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

/* ==========================================================================
   2. Login Page (Acceso Interno — Limpio y Centrado)
   ========================================================================== */
.login-page {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: clamp(16px, 3vw, 28px);
  background: var(--bg);
  overflow: hidden;
}

.login-bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.35;
  mask-image: radial-gradient(circle at 50% 40%, #000 10%, transparent 72%);
  pointer-events: none;
}

.login-top-bar {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  justify-content: flex-end;
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  margin: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: clamp(26px, 4vw, 36px);
  box-shadow: var(--shadow);
}

.login-brand-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 24px;
}

.login-logo-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  background: var(--deep);
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 18px;
}

.login-logo-img {
  height: 38px;
  width: auto;
  display: block;
  object-fit: contain;
}

.login-logo-fallback {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 1.15rem;
  color: #FFFFFF;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.login-brand-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--title);
  letter-spacing: -0.015em;
}

/* Alerts */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  margin-bottom: 18px;
  border: 1px solid transparent;
  line-height: 1.45;
}

.alert-error {
  background: rgba(217, 72, 43, 0.1);
  border-color: rgba(217, 72, 43, 0.35);
  color: var(--alert);
}

[data-theme="dark"] .alert-error {
  background: rgba(217, 72, 43, 0.16);
  color: #FF8A70;
}

.alert-warning {
  background: rgba(232, 131, 58, 0.12);
  border-color: rgba(232, 131, 58, 0.4);
  color: #B45309;
}

[data-theme="dark"] .alert-warning {
  background: rgba(232, 131, 58, 0.16);
  color: #FDBA74;
}

/* Form Fields */
.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--title);
  margin-bottom: 6px;
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 13px;
  color: var(--ink-2);
  pointer-events: none;
}

.input-wrap input {
  width: 100%;
  height: 46px;
  padding: 0 42px 0 42px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font-size: 0.96rem;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.input-wrap input::placeholder {
  color: var(--ink-2);
  opacity: 0.7;
}

.input-wrap input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(46, 125, 26, 0.18);
}

[data-theme="dark"] .input-wrap input:focus {
  box-shadow: 0 0 0 3px rgba(93, 187, 58, 0.22);
}

.password-toggle {
  position: absolute;
  right: 8px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--ink-2);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.password-toggle:hover {
  color: var(--title);
  background: var(--surface-2);
}

.btn-primary {
  width: 100%;
  height: 48px;
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--aqua);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}

.btn-primary:hover:not(:disabled) {
  background: var(--aqua-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px -6px rgba(46, 125, 26, 0.55);
}

.btn-primary:disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #FFFFFF;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.login-help {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--ink-2);
  flex-wrap: wrap;
}

.login-help a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.login-help a:hover {
  text-decoration: underline;
}

.login-legal {
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-2);
  padding-top: 16px;
}

/* ==========================================================================
   3. Authenticated Portal Shell
   ========================================================================== */
.portal-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-deep) 100%);
  color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition), transform var(--transition);
  z-index: 40;
  overflow: hidden;
}

.sidebar.collapsed {
  width: 0;
  border-right-width: 0;
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  min-width: 0;
}

.sidebar-logo-img {
  height: 36px;
  max-width: 185px;
  object-fit: contain;
  display: block;
}

.sidebar-logo-fallback {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 1.1rem;
  color: #FFFFFF;
}

.sidebar-close-btn {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.sidebar-section-label {
  padding: 18px 18px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--sidebar-muted);
  white-space: nowrap;
}

.menu-nav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.menu-nav::-webkit-scrollbar {
  width: 6px;
}

.menu-nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}

.menu-item-btn {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: 0.92rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform 0.12s ease;
  white-space: nowrap;
  overflow: hidden;
}

.menu-item-btn .menu-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

.menu-item-btn .menu-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-item-btn:hover {
  background: var(--sidebar-item-hover);
}

.menu-item-btn.selected {
  background: var(--sidebar-item-active);
  color: #FFFFFF;
  font-weight: 600;
  box-shadow: 0 6px 14px -6px rgba(0, 0, 0, 0.45);
}

.menu-item-btn.selected .menu-dot {
  background: #FFFFFF;
  transform: scale(1.15);
}

.menu-item-btn:active {
  transform: scale(0.985);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 14px 14px 16px;
  border-top: 1px solid var(--sidebar-border);
  background: rgba(0, 0, 0, 0.16);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--blue);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.user-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: #FFFFFF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  color: var(--sidebar-muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--live);
}

.logout-btn {
  width: 100%;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: #E6EEF7;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.logout-btn:hover {
  background: rgba(217, 72, 43, 0.22);
  border-color: rgba(217, 72, 43, 0.55);
  color: #FFFFFF;
}

/* Content Area */
.content-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
}

.content-header {
  height: var(--header-height);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  z-index: 20;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.active-context {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.active-module-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--title);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.active-view-badge {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

/* Header Buttons */
.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--title);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Views Dropdown */
.views-dropdown-wrap {
  position: relative;
}

.views-trigger {
  height: 38px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--deep);
  color: #FFFFFF;
  border: 1px solid var(--deep);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

[data-theme="dark"] .views-trigger {
  background: var(--blue);
  border-color: #2E69A8;
}

.views-trigger:hover {
  background: var(--blue);
  border-color: var(--accent);
}

.views-count {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.views-trigger[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.views-trigger .chevron {
  transition: transform var(--transition);
}

.views-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 240px;
  max-width: min(340px, 85vw);
  max-height: 65vh;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  z-index: 60;
}

.views-menu-item {
  width: 100%;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: transparent;
  color: var(--ink);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.views-menu-item:hover {
  background: var(--surface-2);
  color: var(--title);
}

.views-menu-item.active {
  background: rgba(46, 125, 26, 0.12);
  color: var(--accent);
  font-weight: 600;
}

[data-theme="dark"] .views-menu-item.active {
  background: rgba(93, 187, 58, 0.16);
}

.views-menu-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Frame Stage */
.frame-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--bg);
}

.content-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: var(--surface);
}

.frame-loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg);
  color: var(--ink-2);
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 10;
}

.frame-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  z-index: 12;
}

.empty-card {
  max-width: 380px;
  text-align: center;
  padding: 32px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  color: var(--ink-2);
}

.empty-card svg {
  color: var(--accent);
  margin-bottom: 12px;
}

.empty-card h3 {
  font-size: 1.1rem;
  color: var(--title);
  margin-bottom: 6px;
}

.empty-card p {
  font-size: 0.9rem;
}

/* Backdrop for mobile drawer */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 18, 31, 0.6);
  backdrop-filter: blur(2px);
  z-index: 35;
}

/* ==========================================================================
   4. Responsive Breakpoints
   ========================================================================== */
@media (max-width: 1023px) {
  /* Sidebar becomes off-canvas drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(290px, 84vw);
    transform: translateX(-100%);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
  }

  .sidebar.collapsed {
    width: min(290px, 84vw);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-close-btn {
    display: inline-flex;
  }
}

@media (max-width: 640px) {
  .content-header {
    padding: 0 12px;
    gap: 8px;
  }

  .active-view-badge {
    display: none;
  }

  .views-trigger span:not(.views-count) {
    display: none;
  }

  .views-trigger {
    padding: 0 10px;
  }

  .login-card {
    padding: 24px 20px;
  }
}
