/* ==========================================================================
   BOTÕES
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-min);
  padding: 0 var(--space-6);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.12s ease, background-color 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  user-select: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.btn-op {
  min-height: var(--touch-op);
  padding: 0 var(--space-6);
  font-size: var(--text-md);
}

.btn-sm {
  min-height: var(--touch-min);
  padding: 0 var(--space-4);
  font-size: var(--text-xs);
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background-color: var(--wine-700);
  color: var(--cream-50);
  box-shadow: var(--shadow-warm);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--wine-900);
}

.btn-secondary {
  background-color: var(--surface);
  color: var(--wine-700);
  border-color: var(--wine-700);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--cream-100);
}

.btn-cta {
  background-color: var(--yellow-500);
  color: var(--wine-900);
  font-family: var(--font-display);
  font-weight: 700;
  box-shadow: var(--shadow-warm);
}

.btn-cta:hover:not(:disabled) {
  background-color: var(--yellow-300);
}

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

.btn-danger:hover:not(:disabled) {
  background-color: #8F1D17;
}

.btn-ghost {
  background-color: transparent;
  color: var(--wine-700);
}

.btn-ghost:hover:not(:disabled) {
  background-color: var(--cream-100);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

/* ==========================================================================
   CAMPOS DE FORMULÁRIO
   ========================================================================== */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.field-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--wine-900);
}

.input,
.select {
  width: 100%;
  min-height: var(--touch-min);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-input);
  border: 1.5px solid var(--border);
  background-color: var(--surface);
  color: var(--ink);
  font-size: var(--text-md);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--wine-700);
  box-shadow: var(--focus-ring);
}

.input-group {
  display: flex;
  align-items: stretch;
  border-radius: var(--radius-input);
  border: 1.5px solid var(--border);
  background-color: var(--surface);
  overflow: hidden;
}

.input-group:focus-within {
  border-color: var(--wine-700);
  box-shadow: var(--focus-ring);
}

.input-group .input {
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.input-suffix {
  display: inline-flex;
  align-items: center;
  padding: 0 var(--space-3);
  background-color: var(--cream-100);
  color: var(--wine-900);
  font-size: var(--text-sm);
  font-weight: 600;
  border-left: 1px solid var(--border);
}

.field-hint {
  font-size: var(--text-xs);
  color: var(--muted);
}

.field-error {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--danger);
}

/* Controle segmentado */
.segmented {
  display: inline-flex;
  padding: var(--space-1);
  border-radius: 22px;
  background-color: var(--cream-100);
  border: 1px solid var(--border);
  gap: var(--space-1);
  flex-wrap: wrap;
  max-width: 100%;
}

.segmented-btn {
  min-height: var(--touch-min);
  padding: 0 var(--space-4);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--wine-900);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.segmented-btn.is-active {
  background-color: var(--wine-700);
  color: var(--cream-50);
  box-shadow: var(--shadow-warm);
}

/* Chips */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-min);
  padding: 0 var(--space-4);
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background-color: var(--surface);
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 600;
}

.chip.is-active {
  background-color: var(--yellow-300);
  border-color: var(--wine-700);
  color: var(--wine-900);
}

/* Switch */
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-min);
  cursor: pointer;
}

.switch-track {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: var(--radius-pill);
  background-color: var(--border);
  transition: background-color 0.15s ease;
  flex-shrink: 0;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background-color: var(--surface);
  box-shadow: 0 2px 6px rgba(63, 13, 32, 0.22);
  transition: transform 0.15s ease;
}

.switch input:checked + .switch-track {
  background-color: var(--wine-700);
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(20px);
}

.switch input:focus-visible + .switch-track {
  box-shadow: var(--focus-ring);
}

/* ==========================================================================
   CARDS & KPI
   ========================================================================== */
.card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-6);
  box-shadow: var(--shadow-warm);
}

.card-warm {
  background-color: var(--cream-100);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--space-4);
}

.kpi-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-4) var(--space-6);
  box-shadow: var(--shadow-warm);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

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

.kpi-value {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--wine-900);
}

.kpi-meta {
  font-size: var(--text-xs);
  color: var(--muted);
}

/* ==========================================================================
   TABELAS RESPONSIVAS (viram cards no mobile)
   ========================================================================== */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  background-color: var(--surface);
  box-shadow: var(--shadow-warm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.data-table thead th {
  background-color: var(--cream-100);
  color: var(--wine-900);
  font-weight: 700;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1.5px solid var(--border);
}

.data-table thead th.is-num,
.data-table tbody td.is-num {
  text-align: right;
}

.data-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

.data-table tbody tr:hover {
  background-color: var(--cream-50);
}

@media (max-width: 767px) {
  .table-wrap {
    border: none;
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }

  .data-table,
  .data-table thead,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }

  .data-table tbody tr {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-3) var(--space-4);
    box-shadow: var(--shadow-warm);
  }

  .data-table tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px dashed var(--border);
    text-align: right;
  }

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

  .data-table tbody td::before {
    content: attr(data-label);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--muted);
    text-align: left;
    flex-shrink: 0;
  }
}

/* ==========================================================================
   BADGES SEMÂNTICOS (sempre ícone + texto)
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.badge-saudavel,
.badge-status-ativo {
  background-color: var(--success-bg);
  color: var(--success-ink);
}

.badge-atencao {
  background-color: var(--warning-bg);
  color: var(--warning-ink);
}

.badge-critico,
.badge-mov-perda {
  background-color: var(--danger-bg);
  color: var(--danger);
}

.badge-abc-a {
  background-color: var(--wine-700);
  color: var(--cream-50);
}

.badge-abc-b {
  background-color: #FCE8DA;
  color: #A6470B;
}

.badge-abc-c,
.badge-mov-neutro,
.badge-status-inativo {
  background-color: var(--cream-100);
  color: var(--muted);
  border: 1px solid var(--border);
}

.badge-canal-balcao {
  background-color: var(--cream-100);
  color: var(--wine-900);
  border: 1px solid var(--border);
}

.badge-canal-ifood {
  background-color: #FDEAE8;
  color: #9E1F18;
}

.badge-canal-99food {
  background-color: var(--yellow-300);
  color: var(--wine-900);
}

.badge-canal-whatsapp {
  background-color: var(--success-bg);
  color: var(--success-ink);
}

.badge-mov-compra {
  background-color: var(--success-bg);
  color: var(--success-ink);
}

.badge-mov-ajuste {
  background-color: var(--warning-bg);
  color: var(--warning-ink);
}

.badge-mov-venda {
  background-color: var(--info-bg);
  color: var(--info);
}

/* ==========================================================================
   BARRA DE PROGRESSO
   ========================================================================== */
.progress {
  width: 100%;
  height: 10px;
  border-radius: var(--radius-pill);
  background-color: var(--cream-100);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background-color: var(--wine-700);
  transition: width 0.25s ease;
}

.progress-fill.is-success { background-color: var(--success); }
.progress-fill.is-warning { background-color: var(--orange-500); }
.progress-fill.is-danger { background-color: var(--danger); }

/* ==========================================================================
   TOASTS
   ========================================================================== */
.toast-stack {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: min(380px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-card);
  background-color: var(--surface);
  border: 1.5px solid var(--border);
  border-left-width: 6px;
  box-shadow: var(--shadow-warm-lg);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
}

.toast-success { border-left-color: var(--success); }
.toast-warning { border-left-color: var(--warning); }
.toast-danger { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--info); }

.toast-heart {
  color: var(--heart-500);
  display: inline-flex;
  flex-shrink: 0;
}

/* ==========================================================================
   SKELETON & EMPTY STATE
   ========================================================================== */
.skeleton {
  background: linear-gradient(90deg, var(--cream-100) 25%, #FFFDF8 50%, var(--cream-100) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-input);
  animation: shimmer 1.4s infinite linear;
}

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

.empty-state {
  background-color: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-8) var(--space-6);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.empty-sun-wrap {
  position: relative;
  width: 148px;
  height: 96px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  margin-bottom: var(--space-2);
}

.empty-sun-arch {
  position: absolute;
  bottom: 0;
  width: 140px;
  height: 70px;
  border-radius: 140px 140px 0 0;
  background-color: var(--yellow-300);
}

.empty-mascot {
  position: relative;
  z-index: 1;
  width: 112px;
  height: auto;
  border-radius: 12px;
  mix-blend-mode: multiply;
}

/* ==========================================================================
   MODAL & DRAWER
   ========================================================================== */
.modal-backdrop,
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(43, 21, 32, 0.52);
  display: flex;
  z-index: 1000;
}

.modal-backdrop {
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  background-color: var(--surface);
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-warm-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-lg {
  max-width: 720px;
}

.modal-header,
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border);
  background-color: var(--cream-50);
}

.modal-body,
.drawer-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}

.modal-footer,
.drawer-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background-color: var(--cream-50);
}

.drawer-backdrop {
  justify-content: flex-end;
}

.drawer {
  width: min(460px, 100vw);
  height: 100dvh;
  background-color: var(--surface);
  box-shadow: var(--shadow-warm-lg);
  display: flex;
  flex-direction: column;
}

@media (max-width: 767px) {
  .drawer-backdrop {
    align-items: flex-end;
    justify-content: center;
  }

  .drawer {
    width: 100%;
    height: auto;
    max-height: 88dvh;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ==========================================================================
   NAVEGAÇÃO DO SHELL (Sidebar Clara >=1024px / Bottom Nav <1024px)
   ========================================================================== */
.sidebar {
  display: none;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 900;
  background-color: var(--surface);
  border-top: 1.5px solid var(--border);
  box-shadow: 0 -4px 16px rgba(86, 20, 40, 0.08);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  padding: var(--space-1) var(--space-2) calc(var(--space-1) + env(safe-area-inset-bottom));
  min-height: var(--bottom-nav-height);
}

.bottom-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: var(--touch-min);
  padding: 4px 2px;
  border-radius: var(--radius-input);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.bottom-nav-btn span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-nav-btn.is-active {
  color: var(--wine-700);
}

.bottom-nav-btn.is-center {
  background-color: var(--yellow-500);
  color: var(--wine-900);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 700;
  min-height: 48px;
  margin: 0 4px;
  box-shadow: var(--shadow-warm);
}

.bottom-nav-btn.is-center.is-active {
  box-shadow: 0 0 0 2px var(--wine-700), var(--shadow-warm);
}

@media (min-width: 1024px) {
  .bottom-nav {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background-color: var(--surface);
    border-right: 1.5px solid var(--border);
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: var(--space-3);
    overflow-y: auto;
    z-index: 800;
  }

  .sidebar-top {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
  }

  .sidebar-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    background-color: var(--cream-50);
    border-radius: var(--radius-card);
    border: 1px solid var(--border);
    margin-bottom: var(--space-4);
    flex-shrink: 0;
  }

  .sidebar-logo {
    width: 140px;
    height: auto;
    mix-blend-mode: multiply;
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 2px;
  }

  .nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 40px;
    padding: 0 var(--space-4);
    border-radius: var(--radius-pill);
    color: var(--ink);
    font-size: var(--text-sm);
    font-weight: 600;
    text-align: left;
    flex-shrink: 0;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .nav-item:hover {
    background-color: var(--cream-100);
    color: var(--wine-900);
  }

  .nav-item.is-active {
    background-color: var(--wine-700);
    color: var(--cream-50);
    box-shadow: var(--shadow-warm);
  }

  .nav-item.is-active::after {
    content: "";
    position: absolute;
    right: 14px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--yellow-500);
  }

  .sidebar-footer {
    border-top: 1px solid var(--border);
    padding-top: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }

  .user-pill {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    background-color: var(--cream-50);
    border-radius: var(--radius-input);
    border: 1px solid var(--border);
  }

  .user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background-color: var(--yellow-300);
    color: var(--wine-900);
    font-family: var(--font-display);
    font-weight: 700;
    display: grid;
    place-items: center;
    flex-shrink: 0;
  }
}

@media (max-width: 420px) {
  .card {
    padding: var(--space-4);
  }

  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
  }

  .modal-header,
  .modal-body,
  .modal-footer,
  .drawer-header,
  .drawer-body,
  .drawer-footer {
    padding: var(--space-4);
  }
}
