/* === LAYOUT — Monitor Ventas Generales === */

/* === HEADER === */
.header {
  position: fixed; top: 0; left: 0; right: 0; height: 56px;
  background: var(--bg-header);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; padding: 0 var(--sp-6);
  z-index: 1000;
  transition: background var(--t-theme);
}

.header-title {
  font-weight: 700; font-size: 15px;
  letter-spacing: -0.02em;
  color: var(--color-text-primary);
}

.header-right {
  margin-left: auto;
  display: flex; align-items: center; gap: var(--sp-3);
}

.header-empresa {
  font-size: 13px; color: var(--color-text-muted); font-weight: 500;
}

.connection-status {
  display: flex; align-items: center; gap: 0.5rem;
  color: var(--color-text-muted); font-size: 13px;
}

.status-indicator {
  width: 8px; height: 8px; border-radius: 50%;
  background-color: #6B7280;
  transition: all var(--t-fast);
}

.status-indicator.connected {
  background-color: var(--color-positive);
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
}

.status-indicator.error {
  background-color: var(--color-negative);
}

.header-actions {
  display: flex; align-items: center; gap: 0.75rem;
}

.header-btn {
  width: 36px; height: 36px; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-secondary);
  transition: all var(--t-fast) var(--ease-out);
}
.header-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text-primary);
}
.header-btn:active { transform: scale(0.92); }
.header-btn svg { width: 18px; height: 18px; }
.header-btn.spin-active svg { animation: spin 0.8s linear infinite; }

.sync-status-indicator {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--text-xs); color: var(--color-text-muted);
  cursor: default; white-space: nowrap;
}
.sync-status-indicator .sync-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}
.sync-dot.ok { background: var(--color-positive); }
.sync-dot.warn { background: var(--color-warm); }
.sync-dot.fail { background: var(--color-negative); }
.sync-dot.none { background: var(--color-text-muted); opacity: 0.4; }

/* === THEME TOGGLE === */
.theme-toggle {
  width: 52px; height: 28px;
  background: var(--toggle-bg);
  border-radius: var(--r-full);
  position: relative; cursor: pointer;
  transition: background var(--t-theme);
  border: 1px solid var(--color-border);
}

.theme-toggle-knob {
  width: 22px; height: 22px;
  background: var(--toggle-knob);
  border-radius: 50%;
  position: absolute; top: 2px; left: 2px;
  transition: transform var(--t-base) var(--ease-spring), background var(--t-theme);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}
.theme-toggle-knob svg { width: 13px; height: 13px; color: var(--toggle-icon); }
[data-theme="dark"] .theme-toggle-knob { transform: translateX(24px); }

/* === SIDEBAR === */
#sidebar {
  position: fixed; top: 56px; left: 0; bottom: 0;
  width: 220px; background: var(--bg-sidebar);
  border-right: 1px solid var(--color-border);
  padding: var(--sp-4) var(--sp-3);
  display: flex; flex-direction: column; gap: var(--sp-1);
  overflow-y: auto; z-index: 900;
  transition: background var(--t-theme), border-color var(--t-theme);
}

.sidebar-nav {
  display: flex; flex-direction: column; gap: 0;
}

.sidebar-label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--color-text-disabled);
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
}

.sidebar-nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  font-size: 13px; font-weight: 500;
  color: var(--color-text-secondary);
  transition: all var(--t-fast) var(--ease-out);
  border-left: 2px solid transparent;
  width: 100%; text-align: left;
  cursor: pointer; user-select: none;
  font-family: var(--font-family);
}
.sidebar-nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.sidebar-nav-item:hover { background: var(--sidebar-hover-bg); color: var(--color-text-primary); }
.sidebar-nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--color-accent);
  border-left-color: var(--sidebar-active-border);
  font-weight: 600;
}

/* === MAIN CONTENT === */
.app-body {
  display: flex;
  min-height: calc(100vh - 56px);
}

main {
  margin-left: 220px; margin-top: 56px;
  padding: var(--sp-8);
  min-height: calc(100vh - 56px);
  transition: margin-left var(--t-slow) var(--ease-out);
  flex: 1;
}

/* === SECTIONS === */
.section-view {
  animation: sectionIn 0.5s var(--ease-out) both;
  width: 100%;
}

@keyframes sectionIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--sp-8);
}

.section-header h2 {
  font-size: 20px; font-weight: 700;
  letter-spacing: -0.02em;
  display: flex; align-items: center; gap: var(--sp-3);
  color: var(--color-text-primary);
}
.section-header h2 i,
.section-header h2 svg {
  width: 22px; height: 22px; color: var(--color-accent);
}

.section-header-actions {
  display: flex; align-items: center; gap: var(--sp-4);
}
.section-filter-input { width: 280px; }

/* === LOGIN SCREEN === */
.db-config-section {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; align-items: center;
  background: var(--login-gradient);
  z-index: 1050;
}

.db-config-card {
  background-color: var(--color-surface);
  padding: 2.5rem;
  border-radius: var(--r-xl);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 550px;
}

.db-config-header {
  text-align: center; margin-bottom: 2rem;
}

.db-config-icon {
  color: var(--color-accent);
  width: 48px; height: 48px; margin-bottom: 1rem;
}

.db-config-header h2 {
  font-size: 1.5rem; font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 0.5rem;
}

.db-config-header p {
  color: var(--color-text-muted); font-size: 1rem;
}

/* === RESPONSIVE === */

/* --- Tablet & small desktop (≤768px) --- */
@media (max-width: 768px) {
  .header { padding: 0 var(--sp-3); gap: var(--sp-2); }

  #sidebar {
    position: fixed; top: 56px; left: 0; right: 0;
    width: 100%; bottom: auto;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    padding: 0 var(--sp-2);
    flex-direction: row;
    overflow-x: auto; overflow-y: visible;
    z-index: 850;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #sidebar::-webkit-scrollbar { display: none; }

  .sidebar-nav { flex-direction: row; gap: 0; }

  .sidebar-nav-item {
    flex-shrink: 0;
    border-left: none;
    border-bottom: 2px solid transparent;
    padding: var(--sp-2) var(--sp-3);
    gap: var(--sp-2);
    font-size: 12px;
    white-space: nowrap;
  }
  .sidebar-nav-item.active {
    border-left: none;
    border-bottom-color: var(--color-accent);
  }

  .sidebar-label { display: none; }

  main {
    margin-left: 0;
    margin-top: 100px;
    padding: var(--sp-4);
  }

  .app-body { flex-direction: column; }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--sp-3);
  }
  .section-header-actions {
    width: 100%;
    flex-wrap: wrap;
  }
  .section-header-actions .input-control {
    width: 100% !important;
    min-width: 0;
  }

  .db-config-card {
    margin: var(--sp-4);
    padding: var(--sp-6);
  }
  .db-config-header h2 { font-size: 1.25rem; }
}

/* --- Phone (≤640px) --- */
@media (max-width: 640px) {
  .header-empresa { display: none; }
  .connection-status span:not(.status-indicator) { display: none; }

  #sidebar {
    padding: 0;
  }

  .sidebar-nav-item span { display: none; }
  .sidebar-nav-item {
    padding: var(--sp-2) var(--sp-3);
    justify-content: center;
  }
  .sidebar-nav-item svg { width: 20px; height: 20px; }

  main {
    margin-top: 90px;
    padding: var(--sp-3);
  }

  .section-header h2 { font-size: 16px; }

  .db-config-section { padding: var(--sp-3); align-items: flex-start; padding-top: 60px; }
  .db-config-card {
    margin: 0;
    padding: var(--sp-5);
    border-radius: var(--r-lg);
  }
}

/* --- Small phone (≤400px) --- */
@media (max-width: 400px) {
  .header { height: 48px; padding: 0 var(--sp-2); }
  .header-title { font-size: 13px; }

  #sidebar { top: 48px; }

  main {
    margin-top: 82px;
    padding: var(--sp-2);
  }

  .header-actions { gap: 0.5rem; }
  .header-btn { width: 32px; height: 32px; }
  .header-btn svg { width: 16px; height: 16px; }
  .month-selector { font-size: 11px; padding: var(--sp-1) var(--sp-2); }

  .theme-toggle { width: 44px; height: 24px; }
  .theme-toggle-knob { width: 18px; height: 18px; }
  .theme-toggle-knob svg { width: 11px; height: 11px; }
  [data-theme="dark"] .theme-toggle-knob { transform: translateX(20px); }
}
