/* ==============================================================================
   KS STOCK — DESIGN SYSTEM & ESTILOS PRINCIPAIS (PREMIUM SAAS)
   ============================================================================== */

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

:root {
  /* Cores Principais */
  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-primary-light: #eef2ff;
  --color-primary-glow: rgba(79, 70, 229, 0.15);

  --color-bg-body: #f8fafc;
  --color-bg-surface: #ffffff;
  --color-bg-sidebar: #0f172a;
  --color-bg-sidebar-hover: #1e293b;
  --color-bg-sidebar-active: #334155;

  /* Texto */
  --color-text-main: #0f172a;
  --color-text-muted: #64748b;
  --color-text-subtle: #94a3b8;
  --color-text-inverted: #f8fafc;

  /* Status e Alertas */
  --color-success: #10b981;
  --color-success-bg: #ecfdf5;
  --color-success-border: #a7f3d0;

  --color-warning: #f59e0b;
  --color-warning-bg: #fffbeb;
  --color-warning-border: #fde68a;

  --color-danger: #ef4444;
  --color-danger-bg: #fef2f2;
  --color-danger-border: #fecaca;

  --color-info: #0ea5e9;
  --color-info-bg: #f0f9ff;
  --color-info-border: #bae6fd;

  /* Bordas e Sombras */
  --border-color: #e2e8f0;
  --border-color-light: #f1f5f9;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

  /* Dimensões do Layout */
  --sidebar-width: 260px;
  --header-height: 70px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

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

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--color-bg-body);
  color: var(--color-text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ==============================================================================
   LAYOUT GERAL (APP SHELL)
   ============================================================================== */

.app-container {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* SIDEBAR */

.sidebar {
  width: var(--sidebar-width);
  background-color: var(--color-bg-sidebar);
  color: var(--color-text-inverted);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: transform var(--transition-normal);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}

.brand-badge {
  background: linear-gradient(135deg, var(--color-primary), #6366f1);
  color: white;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.35);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  color: white;
  font-size: 1.15rem;
  line-height: 1.2;
}

.brand-tagline {
  font-size: 0.7rem;
  color: var(--color-text-subtle);
  font-weight: 400;
}

.sidebar-company-card {
  margin: 1rem 1.25rem 0.5rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.company-avatar {
  width: 32px;
  height: 32px;
  background: rgba(79, 70, 229, 0.2);
  border: 1px solid rgba(79, 70, 229, 0.4);
  color: #a5b4fc;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.company-info {
  flex: 1;
  min-width: 0;
}

.company-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.company-plan {
  font-size: 0.7rem;
  color: #38bdf8;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-section-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  font-weight: 600;
  padding: 0.75rem 0.75rem 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-md);
  color: #94a3b8;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.nav-item:hover {
  background-color: var(--color-bg-sidebar-hover);
  color: #f8fafc;
}

.nav-item.active {
  background-color: var(--color-primary);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.nav-item svg {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.user-profile-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: #334155;
  color: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8rem;
}

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

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

.user-role {
  font-size: 0.7rem;
  color: var(--color-text-subtle);
}

.btn-logout {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-logout:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* MAIN CONTENT WRAPPER */

.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

/* TOP HEADER */

.top-header {
  height: var(--header-height);
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.btn-menu-toggle {
  display: none;
  background: transparent;
  border: none;
  padding: 0.5rem;
  color: var(--color-text-main);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.page-title-wrap {
  display: flex;
  flex-direction: column;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text-main);
}

.page-subtitle {
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

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

/* CONTENT CONTAINER */

.content-body {
  padding: 2rem;
  flex: 1;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* ==============================================================================
   COMPONENTES: BOTÕES
   ============================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  font-weight: 600;
  font-size: 0.88rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--color-primary);
  color: white;
  box-shadow: 0 2px 4px rgba(79, 70, 229, 0.2);
}

.btn-primary:hover {
  background-color: var(--color-primary-hover);
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
  background-color: white;
  color: var(--color-text-main);
  border-color: var(--border-color);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
  background-color: var(--color-bg-body);
  border-color: #cbd5e1;
}

.btn-success {
  background-color: var(--color-success);
  color: white;
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.2);
}

.btn-success:hover {
  background-color: #059669;
}

.btn-danger {
  background-color: var(--color-danger);
  color: white;
}

.btn-danger:hover {
  background-color: #dc2626;
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-icon-only {
  padding: 0.55rem;
  border-radius: var(--radius-md);
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* ==============================================================================
   COMPONENTES: CARDS E MÉTRICAS (KPIS)
   ============================================================================== */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.card {
  background: var(--color-bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.kpi-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.kpi-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-icon-wrap {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-primary {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.icon-success {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.icon-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.icon-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--color-text-main);
  line-height: 1.2;
}

.kpi-subtext {
  font-size: 0.75rem;
  color: var(--color-text-subtle);
  margin-top: 0.4rem;
}

/* ==============================================================================
   COMPONENTES: TABELAS E LISTAS
   ============================================================================== */

.table-card {
  background: var(--color-bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

.table-search-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--color-bg-body);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.85rem;
  width: 320px;
  max-width: 100%;
}

.table-search-box input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 0.88rem;
  width: 100%;
}

.table-filters {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.data-table th {
  background-color: #f8fafc;
  padding: 0.85rem 1.25rem;
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color-light);
  color: var(--color-text-main);
  vertical-align: middle;
}

.data-table tr:hover td {
  background-color: #fafbfc;
}

.data-table tr:last-child td {
  border-bottom: none;
}

/* BADGES */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-success {
  background-color: var(--color-success-bg);
  color: #065f46;
  border: 1px solid var(--color-success-border);
}

.badge-success .badge-dot {
  background-color: var(--color-success);
}

.badge-warning {
  background-color: var(--color-warning-bg);
  color: #92400e;
  border: 1px solid var(--color-warning-border);
}

.badge-warning .badge-dot {
  background-color: var(--color-warning);
}

.badge-danger {
  background-color: var(--color-danger-bg);
  color: #991b1b;
  border: 1px solid var(--color-danger-border);
}

.badge-danger .badge-dot {
  background-color: var(--color-danger);
}

.badge-neutral {
  background-color: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.badge-neutral .badge-dot {
  background-color: #94a3b8;
}

/* ==============================================================================
   COMPONENTES: FORMULÁRIOS
   ============================================================================== */

.form-group {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.form-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #334155;
}

.form-label span.req {
  color: var(--color-danger);
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.9rem;
  font-size: 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: #ffffff;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.form-control::placeholder {
  color: var(--color-text-subtle);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

/* CARD INFORMATIVO DE MARGEM DE LUCRO */

.margin-calc-box {
  background: #f8fafc;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.25rem;
}

.margin-calc-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.margin-calc-value {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--color-success);
}

/* ==============================================================================
   COMPONENTES: MODAIS
   ============================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: var(--color-bg-surface);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow-xl);
  transform: scale(0.96) translateY(10px);
  transition: transform var(--transition-normal);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-backdrop.active .modal-dialog {
  transform: scale(1) translateY(0);
}

.modal-dialog-lg {
  max-width: 780px;
}

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

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text-main);
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

.btn-close-modal:hover {
  background: #f1f5f9;
  color: var(--color-text-main);
}

.modal-body {
  padding: 1.75rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1.25rem 1.75rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  background: #fafbfc;
}

/* ==============================================================================
   COMPONENTES: TOAST NOTIFICATIONS
   ============================================================================== */

#toast-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 300px;
  max-width: 420px;
  background: white;
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

@keyframes toastSlideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  margin-top: 2px;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-text-main);
  line-height: 1.3;
}

.toast-message {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 0.2rem;
}

.toast.success .toast-icon {
  color: var(--color-success);
}

.toast.error .toast-icon {
  color: var(--color-danger);
}

.toast.warning .toast-icon {
  color: var(--color-warning);
}

.toast.info .toast-icon {
  color: var(--color-info);
}

/* ==============================================================================
   COMPONENTES: ESTADOS VAZIOS (EMPTY STATES) E SKELETON
   ============================================================================== */

.empty-state {
  padding: 3.5rem 2rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 460px;
  margin: 0 auto;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-full);
  background: #f1f5f9;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.empty-state-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text-main);
  margin-bottom: 0.5rem;
}

.empty-state-desc {
  font-size: 0.88rem;
  color: var(--color-text-muted);
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

/* SKELETON LOADERS */

.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: 12px;
}

.skeleton-card {
  height: 110px;
  border-radius: var(--radius-lg);
}

/* ==============================================================================
   TELAS PÚBLICAS DE AUTENTICAÇÃO (LOGIN / CADASTRO)
   ============================================================================== */

.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  position: relative;
  overflow: hidden;
}

.auth-wrapper::before {
  content: '';
  position: absolute;
  top: -20%;
  left: -10%;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(79, 70, 229, 0.25) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.auth-box {
  width: 100%;
  max-width: 440px;
  background: #ffffff;
  border-radius: var(--radius-xl);
  padding: 2.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  position: relative;
  z-index: 1;
}

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

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.auth-brand-logo {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--color-primary), #6366f1);
  border-radius: var(--radius-md);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 800;
  box-shadow: 0 8px 16px rgba(79, 70, 229, 0.35);
}

.auth-brand-name {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--color-text-main);
}

.auth-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text-main);
}

.auth-subtitle {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 0.3rem;
}

.auth-footer-links {
  text-align: center;
  margin-top: 1.75rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.auth-footer-links a {
  color: var(--color-primary);
  font-weight: 600;
}

.auth-footer-links a:hover {
  text-decoration: underline;
}

/* CONFIGURAÇÃO SUPABASE PENDENTE AVISO */

.config-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
}

/* ==============================================================================
   TELA: RELATÓRIOS E GRÁFICOS
   ============================================================================== */

.chart-container {
  position: relative;
  height: 320px;
  width: 100%;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.filter-pills {
  display: inline-flex;
  background: var(--color-bg-body);
  border: 1px solid var(--border-color);
  padding: 3px;
  border-radius: var(--radius-md);
}

.filter-pill {
  padding: 0.3rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  transition: all var(--transition-fast);
}

.filter-pill.active {
  background: white;
  color: var(--color-text-main);
  box-shadow: var(--shadow-xs);
}

/* ==============================================================================
   RESPONSIVIDADE (MOBILE, TABLET, DESKTOP)
   ============================================================================== */

@media (max-width: 992px) {

  .sidebar {
    transform: translateX(-100%);
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.3);
  }

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

  .main-wrapper {
    margin-left: 0;
  }

  .btn-menu-toggle {
    display: flex;
  }

  .top-header {
    padding: 0 1.25rem;
  }

  .content-body {
    padding: 1.25rem;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 90;
    display: none;
  }

  .sidebar-backdrop.active {
    display: block;
  }
}

@media (max-width: 640px) {

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .table-header-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .table-search-box {
    width: 100%;
  }

  .auth-box {
    padding: 1.75rem 1.25rem;
  }

  .modal-dialog {
    max-height: 95vh;
  }
}

/* ===============================================================================
   KS STOCK — OTIMIZAÇÃO GLOBAL DE RESPONSIVIDADE E SCROLL
   =============================================================================== */

html {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
  min-width: 0;
}

img,
svg,
video,
canvas {
  max-width: 100%;
}

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  touch-action: manipulation;
}

/* ============================================================================ 
   APP / CONTEÚDO
   ============================================================================ */

.app-container,
.main-wrapper,
.content-body {
  min-width: 0;
}

.content-body {
  overflow-x: hidden;
}

/* ============================================================================ 
   HEADER
   ============================================================================ */

.top-header {
  min-width: 0;
}

.header-left,
.header-actions,
.page-title-wrap {
  min-width: 0;
}

.page-title,
.page-subtitle {
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-title {
  white-space: nowrap;
}

.page-subtitle {
  white-space: nowrap;
}

/* ============================================================================ 
   TABELAS — desktop + celular
   ============================================================================ */

.table-responsive {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.data-table {
  min-width: 760px;
}

.table-card {
  min-width: 0;
  max-width: 100%;
}

/* ============================================================================ 
   FILTROS / BUSCA
   ============================================================================ */

.table-header-bar,
.table-filters,
.table-search-box {
  min-width: 0;
}

.table-search-box {
  max-width: 100%;
}

.table-search-box input {
  min-width: 0;
}

.form-control {
  min-width: 0;
  max-width: 100%;
}

select.form-control {
  text-overflow: ellipsis;
}

/* ============================================================================ 
   FORMULÁRIOS
   ============================================================================ */

.form-row {
  min-width: 0;
}

.form-group {
  min-width: 0;
}

.form-group > * {
  max-width: 100%;
}

textarea.form-control {
  max-width: 100%;
}

/* ============================================================================ 
   MODAIS — SCROLL CORRETO PARA TODOS OS MODAIS
   ============================================================================ */

.modal-backdrop {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.modal-dialog {
  width: min(100%, 780px);
  max-height: min(90vh, 900px);
  height: auto;
  min-height: 0;
  overflow: hidden;
  flex: 0 1 auto;
}

.modal-dialog > form,
.modal-dialog > .modal-form,
.modal-dialog > .form-modal {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.modal-dialog > .modal-content {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

.modal-dialog > .modal-content > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.modal-footer {
  flex: 0 0 auto;
  flex-shrink: 0;
  min-height: 68px;
  position: relative;
  z-index: 5;
}

.modal-header {
  flex: 0 0 auto;
  min-height: 64px;
}

.modal-scroll,
.modal-content-scroll {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ============================================================================ 
   MODAL DE PRODUTOS — ajuste específico
   ============================================================================ */

#form-product {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

#form-product .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* ============================================================================ 
   BOTÕES — área de toque confortável
   ============================================================================ */

.btn {
  min-height: 38px;
  touch-action: manipulation;
}

.btn-sm {
  min-height: 34px;
}

.btn-icon-only {
  min-width: 38px;
  min-height: 38px;
}

.btn-close-modal {
  min-width: 38px;
  min-height: 38px;
}

/* ============================================================================ 
   MOBILE — ATÉ 992PX
   ============================================================================ */

@media (max-width: 992px) {

  .top-header {
    height: auto;
    min-height: var(--header-height);
    padding: 0 1.25rem;
    gap: 0.75rem;
  }

  .content-body {
    padding: 1.25rem;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-header-bar {
    align-items: stretch;
  }

  .table-search-box {
    width: 100%;
  }

  .table-filters {
    width: 100%;
  }

  .table-filters .form-control {
    flex: 1 1 180px;
  }

  .modal-backdrop {
    padding: 1rem;
  }

  .modal-dialog {
    max-height: 92vh;
  }
}

/* ============================================================================ 
   MOBILE — ATÉ 640PX
   ============================================================================ */

@media (max-width: 640px) {

  :root {
    --header-height: 62px;
  }

  body {
    font-size: 14px;
  }

  .main-wrapper {
    width: 100%;
    min-width: 0;
  }

  .top-header {
    width: 100%;
    min-height: var(--header-height);
    padding: 0.65rem 0.9rem;
    gap: 0.6rem;
  }

  .header-left {
    flex: 1 1 auto;
    min-width: 0;
    gap: 0.6rem;
  }

  .header-actions {
    flex: 0 0 auto;
  }

  .btn-menu-toggle {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    padding: 0.45rem;
  }

  .page-title {
    font-size: 1.05rem;
    line-height: 1.25;
  }

  .page-subtitle {
    display: none;
  }

  .header-actions .btn {
    min-height: 40px;
    padding: 0.5rem 0.7rem;
  }

  .header-actions .btn svg {
    flex-shrink: 0;
  }

  .content-body {
    width: 100%;
    padding: 0.85rem;
  }

  /* KPI */

  .kpi-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
  }

  .card {
    padding: 1rem;
    border-radius: var(--radius-lg);
  }

  .kpi-value {
    font-size: 1.45rem;
  }

  /* Tabelas */

  .table-card {
    border-radius: var(--radius-lg);
  }

  .table-header-bar {
    padding: 0.9rem;
    gap: 0.75rem;
  }

  .table-search-box {
    width: 100%;
    min-height: 42px;
    padding: 0.55rem 0.75rem;
  }

  .table-filters {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    gap: 0.6rem;
  }

  .table-filters .form-control,
  .table-filters select.form-control {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100%;
  }

  .table-responsive {
    border-top: 0;
  }

  .data-table {
    min-width: 720px;
  }

  .data-table th,
  .data-table td {
    padding: 0.75rem 0.85rem;
  }

  /* Formulários */

  .form-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .form-row > [style*="grid-column"] {
    grid-column: 1 / -1 !important;
  }

  .form-group {
    margin-bottom: 1rem;
  }

  .form-control {
    min-height: 42px;
    padding: 0.65rem 0.8rem;
  }

  textarea.form-control {
    min-height: 100px;
  }

  .margin-calc-box {
    gap: 0.75rem;
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .margin-calc-value {
    margin-left: auto;
    text-align: right;
  }

  /* Modais */

  .modal-backdrop {
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
  }

  .modal-dialog,
  .modal-dialog-lg {
    width: 100%;
    max-width: 100%;
    height: 94vh;
    max-height: 94vh;
    border-radius: 14px;
  }

  .modal-header {
    min-height: 58px;
    padding: 0.85rem 1rem;
  }

  .modal-title {
    font-size: 1rem;
    line-height: 1.3;
    padding-right: 0.5rem;
  }

  .modal-body {
    padding: 1rem;
  }

  .modal-footer {
    min-height: 64px;
    padding: 0.75rem 1rem;
    gap: 0.6rem;
  }

  .modal-footer .btn {
    flex: 1 1 0;
    min-height: 44px;
    padding: 0.65rem 0.75rem;
  }

  /* Toast */

  #toast-container {
    top: 0.75rem;
    right: 0.75rem;
    left: 0.75rem;
  }

  .toast {
    min-width: 0;
    width: 100%;
    max-width: none;
  }
}

/* ============================================================================ 
   CELULARES MUITO PEQUENOS — ATÉ 380PX
   ============================================================================ */

@media (max-width: 380px) {

  .content-body {
    padding: 0.65rem;
  }

  .top-header {
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }

  .page-title {
    font-size: 0.98rem;
  }

  .header-actions .btn {
    padding: 0.5rem 0.6rem;
    font-size: 0.75rem;
  }

  .modal-backdrop {
    padding: 0.25rem;
  }

  .modal-dialog,
  .modal-dialog-lg {
    height: 96vh;
    max-height: 96vh;
    border-radius: 12px;
  }

  .modal-body {
    padding: 0.85rem;
  }

  .modal-footer {
    padding: 0.65rem 0.75rem;
  }

  .modal-footer .btn {
    font-size: 0.78rem;
  }
}

/* ============================================================================ 
   CELULARES COM POUCA ALTURA
   ============================================================================ */

@media (max-width: 640px) and (max-height: 700px) {

  .modal-dialog,
  .modal-dialog-lg {
    height: 97vh;
    max-height: 97vh;
  }

  .modal-header {
    min-height: 52px;
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
  }

  .modal-body {
    padding-top: 0.85rem;
    padding-bottom: 0.85rem;
  }

  .modal-footer {
    min-height: 58px;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
  }
}

/* ============================================================================ 
   TOUCH / ACESSIBILIDADE
   ============================================================================ */

@media (hover: none) and (pointer: coarse) {

  .btn,
  .nav-item,
  .btn-close-modal,
  .btn-logout {
    -webkit-user-select: none;
    user-select: none;
  }

  .btn {
    min-height: 42px;
  }

  .btn-sm {
    min-height: 38px;
  }

  .btn-icon-only,
  .btn-close-modal {
    min-width: 42px;
    min-height: 42px;
  }
}

/* ============================================================================ 
   SAFE AREA — iPhone com notch / Dynamic Island / barra inferior
   ============================================================================ */

@supports (padding: env(safe-area-inset-bottom)) {

  .modal-footer {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }

  .sidebar-footer {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* ============================================================================ 
   REDUÇÃO DE MOVIMENTO
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* ==============================================================================
   KS STOCK — INTRO DO SISTEMA
   SOMENTE NA ENTRADA DO SISTEMA
   ============================================================================== */

.ks-system-entry .app-container::before {
  content: "KS STOCK\A Controle Inteligente";

  white-space: pre;

  position: fixed;
  inset: 0;

  z-index: 99999;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 2rem;

  background: var(--color-bg-sidebar);

  color: var(--color-text-inverted);

  text-align: center;

  font-size: clamp(3rem, 8vw, 7rem);
  font-weight: 800;
  letter-spacing: -0.07em;
  line-height: 0.95;

  pointer-events: none;

  animation:
    ksSystemIntro
    1.55s
    cubic-bezier(0.22, 1, 0.36, 1)
    forwards;
}

.ks-system-entry .app-container::after {
  content: "";

  position: fixed;
  inset: 0;

  z-index: 99998;

  pointer-events: none;

  background:
    radial-gradient(
      circle at center,
      var(--color-primary-glow),
      transparent 42%
    );

  opacity: 0;

  animation:
    ksSystemIntroGlow
    1.55s
    ease-out
    forwards;
}

/* ==============================================================================
   ANIMAÇÃO DA INTRO
   ============================================================================== */

@keyframes ksSystemIntro {

  0% {
    opacity: 1;
    transform: scale(1.045);
    filter: blur(7px);
  }

  20% {
    opacity: 1;
    transform: scale(1.015);
    filter: blur(0);
  }

  60% {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }

  100% {
    opacity: 0;
    visibility: hidden;
    transform: scale(1.01);
    filter: blur(1px);
  }

}

@keyframes ksSystemIntroGlow {

  0% {
    opacity: 0;
    transform: scale(0.75);
  }

  25% {
    opacity: 0.4;
    transform: scale(1);
  }

  60% {
    opacity: 0.12;
    transform: scale(1.04);
  }

  100% {
    opacity: 0;
    visibility: hidden;
    transform: scale(1.1);
  }

}

/* ==============================================================================
   INTRO — CELULAR
   ============================================================================== */

@media (max-width: 640px) {

  .ks-system-entry .app-container::before {
    font-size: clamp(2rem, 11vw, 3.8rem);
    letter-spacing: -0.055em;
    line-height: 1;
    padding: 1.25rem;
  }

  .ks-system-entry .app-container::after {
    background:
      radial-gradient(
        circle at center,
        var(--color-primary-glow),
        transparent 55%
      );
  }

}

/* ==============================================================================
   INTRO — CELULARES PEQUENOS
   ============================================================================== */

@media (max-width: 380px) {

  .ks-system-entry .app-container::before {
    font-size: clamp(1.75rem, 11vw, 3rem);
    letter-spacing: -0.045em;
    padding: 1rem;
  }

}

/* ==============================================================================
   INTRO — TELAS BAIXAS
   ============================================================================== */

@media (max-width: 640px) and (max-height: 700px) {

  .ks-system-entry .app-container::before {
    font-size: 2.2rem;
    line-height: 1.05;
  }

}

/* ==============================================================================
   GARANTIA — SEM INTRO FORA DA ENTRADA
   ============================================================================== */

body:not(.ks-system-entry) .app-container::before,
body:not(.ks-system-entry) .app-container::after {
  display: none !important;
}

/* ==============================================================================
   REDUÇÃO DE MOVIMENTO — INTRO
   ============================================================================== */

@media (prefers-reduced-motion: reduce) {

  .ks-system-entry .app-container::before,
  .ks-system-entry .app-container::after {
    animation: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
  }

}
