/* =====================================================================
   Componentes base
   ===================================================================== */

/* ---------- Button ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--h-control);
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font: 600 14px/1 var(--font);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { border-color: var(--accent); box-shadow: var(--focus-ring); }

.btn--primary { background: var(--primary); color: var(--on-primary); }
.btn--primary:hover { background: var(--primary-hover); }

.btn--secondary { background: var(--surface-subtle); color: var(--text); border-color: var(--border); }
.btn--secondary:hover { background: var(--track); }

.btn--ghost { background: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--surface-subtle); color: var(--text); }

.btn--danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(248, 113, 113, 0.28); }
.btn--danger:hover { border-color: var(--danger); }

.btn:disabled,
.btn[aria-disabled='true'] {
  background: var(--track);
  color: var(--placeholder);
  border-color: transparent;
  cursor: not-allowed;
}

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

.btn--sm { height: var(--h-sm); padding: 0 12px; border-radius: var(--r-sm); font-size: 13px; gap: 6px; }
.btn--lg { height: var(--h-action); padding: 0 22px; font-size: 15px; }
.btn--xl { height: var(--h-action-lg); padding: 0 24px; font-size: 15px; }
.btn--icon { width: var(--h-control); padding: 0; }
.btn--sm.btn--icon { width: var(--h-sm); }
.btn--full { width: 100%; }

.btn__badge {
  display: inline-flex; align-items: center;
  height: 22px; padding: 0 8px;
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, 0.18);
  color: var(--on-primary);
  font-size: 12px; font-weight: 700;
}
.btn--secondary .btn__badge, .btn--ghost .btn__badge { background: var(--accent-soft); color: var(--accent); }

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  padding: 22px;
  min-width: 0;
}
.card--flush { padding: 0; overflow: hidden; }
.card__header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.card__title { font-size: var(--fs-card-title); font-weight: 700; letter-spacing: -0.01em; }
.card__subtitle { font-size: var(--fs-small); color: var(--text-muted); margin-top: 2px; }
.card__footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--divider);
}

.block {
  background: var(--surface-subtle);
  border-radius: var(--r-lg);
  padding: 14px 16px;
}

/* ---------- KPI ---------- */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 18px 20px;
  min-width: 0;
}
.kpi__label {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--fs-small); font-weight: 600; color: var(--text-muted);
}
.kpi__value {
  margin-top: 8px;
  font-size: var(--fs-kpi); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi__hint { margin-top: 6px; font-size: var(--fs-xs); color: var(--text-muted); }
.kpi--accent .kpi__value { color: var(--accent); }
.kpi--warning .kpi__value { color: var(--warning); }
.kpi--success .kpi__value { color: var(--success); }
.kpi--danger .kpi__value { color: var(--danger); }

/* ---------- ProgressBar ---------- */
.progress { display: flex; flex-direction: column; gap: 8px; }
.progress__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.progress__label { font-weight: 600; }
.progress__value { font-size: var(--fs-small); color: var(--text-2); font-variant-numeric: tabular-nums; }
.progress__value strong { color: var(--text); font-weight: 700; }
.progress__track { height: 8px; border-radius: var(--r-full); background: var(--track); overflow: hidden; }
.progress__bar {
  height: 100%; border-radius: inherit; background: var(--primary);
  transition: width 400ms var(--ease);
}
.progress--done .progress__bar { background: var(--success); }
.progress--done .progress__value strong { color: var(--success); }
.progress__note { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------- Pill / Badge ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px;
  border-radius: var(--r-full);
  background: var(--track); color: var(--text-2);
  font: 600 12px/1 var(--font);
  white-space: nowrap;
  max-width: 100%;
}
.pill > span { overflow: hidden; text-overflow: ellipsis; }
.pill--sm { height: 20px; padding: 0 8px; font-size: 11px; }
.pill--accent  { background: var(--accent-soft); color: var(--accent); }
.pill--success { background: var(--success-bg); color: var(--success); }
.pill--warning { background: var(--warning-bg); color: var(--warning); }
.pill--danger  { background: var(--danger-bg); color: var(--danger); }
.pill--primary { background: var(--primary); color: var(--on-primary); }
.pill__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex: none; }

.count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 20px; padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
}

/* ---------- Avatar ---------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 13px; letter-spacing: 0.02em;
  user-select: none;
}
.avatar--xs { width: 24px; height: 24px; font-size: 10px; }
.avatar--sm { width: 28px; height: 28px; font-size: 11px; }
.avatar--lg { width: 44px; height: 44px; font-size: 15px; }

/* ---------- SegmentedTabs ---------- */
.tabs {
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--track); border-radius: var(--r-md);
  max-width: 100%; overflow-x: auto;
}
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text-2);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tab:hover { color: var(--text); }
.tab[aria-selected='true'] { background: var(--primary); color: var(--on-primary); }
.tab[aria-selected='true'] .count { background: rgba(255, 255, 255, 0.2); color: var(--on-primary); }
.tabs--full { display: flex; }
.tabs--full .tab { flex: 1 1 0; justify-content: center; }

/* ---------- Switch ---------- */
.switch {
  position: relative; flex: none;
  width: 44px; height: 26px; padding: 0;
  border: 1px solid var(--border); border-radius: var(--r-full);
  background: var(--track);
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--text-2);
  transition: transform var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.switch[aria-checked='true'] { background: var(--primary); border-color: var(--primary); }
.switch[aria-checked='true']::after { transform: translateX(18px); background: var(--on-primary); }
.switch:disabled { opacity: 0.5; cursor: not-allowed; }
.switch-field { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.switch-field__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.switch-field__label { font-weight: 600; cursor: pointer; }
.switch-field__hint { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------- Field / Input / Select / Textarea ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field__label { font-size: var(--fs-small); font-weight: 600; color: var(--text-2); }
.field__label .req { color: var(--accent); margin-left: 2px; }
.field__hint { font-size: var(--fs-xs); color: var(--text-muted); }
.field__error { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--danger); }

.input, .select, .textarea {
  width: 100%;
  height: var(--h-control);
  padding: 0 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--placeholder); }
.input:hover, .select:hover, .textarea:hover { border-color: #3A3A40; }
.input:focus, .select:focus, .textarea:focus,
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: var(--focus-ring);
}
.input:disabled, .select:disabled, .textarea:disabled { color: var(--placeholder); background: var(--surface-subtle); cursor: not-allowed; }
.input[aria-invalid='true'], .select[aria-invalid='true'], .textarea[aria-invalid='true'] { border-color: var(--danger); }

.select {
  appearance: none; -webkit-appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239A9AA2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
}
.select option { background: var(--surface); color: var(--text); }

.textarea { height: auto; min-height: 96px; padding: 12px 14px; line-height: 1.5; resize: vertical; }

.input-group { position: relative; }
.input-group > .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.input-group > .input { padding-left: 42px; }

/* Checkbox e radio */
.checkbox, .radio {
  appearance: none; -webkit-appearance: none;
  flex: none; width: 18px; height: 18px; margin: 0;
  border: 1.5px solid #4A4A52; background: var(--bg);
  display: inline-grid; place-content: center;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.checkbox { border-radius: 5px; }
.radio { border-radius: 50%; }
.checkbox:checked {
  background-color: var(--primary); border-color: var(--primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: center;
}
.checkbox:indeterminate {
  background-color: var(--primary); border-color: var(--primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: center;
}
.radio:checked { border-color: var(--primary); }
.radio:checked::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.checkbox:disabled, .radio:disabled { opacity: 0.4; cursor: not-allowed; }
.checkbox:focus-visible, .radio:focus-visible { box-shadow: var(--focus-ring); border-color: var(--accent); }
.check-row { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.check-row .checkbox, .check-row .radio { margin-top: 1px; }

/* ---------- EmptyState / ErrorState ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 10px; padding: 48px 24px;
}
.empty__icon {
  display: grid; place-items: center;
  width: 52px; height: 52px; margin-bottom: 6px;
  border-radius: var(--r-lg);
  background: var(--accent-soft); color: var(--accent);
}
.empty--error .empty__icon { background: var(--danger-bg); color: var(--danger); }
.empty__title { font-size: 16px; font-weight: 700; }
.empty__text { max-width: 420px; color: var(--text-muted); }
.empty__actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }

/* ---------- Skeleton (pulso, sem gradiente) ---------- */
.skeleton {
  display: block;
  height: 14px;
  border-radius: 8px;
  background: var(--surface-subtle);
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}
.skeleton--title { height: 30px; width: 280px; max-width: 70%; border-radius: 10px; }
.skeleton--block { height: 96px; border-radius: var(--r-xl); }
@keyframes skeleton-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ---------- Toast ---------- */
.toast-region {
  position: fixed; right: 24px; bottom: 24px; z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  min-width: 280px; max-width: min(440px, calc(100vw - 32px));
  padding: 12px 12px 12px 16px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  opacity: 0; transform: translateY(8px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.toast.is-visible { opacity: 1; transform: none; }
.toast__icon { color: var(--accent); }
.toast--success .toast__icon { color: var(--success); }
.toast--warning .toast__icon { color: var(--warning); }
.toast--danger .toast__icon { color: var(--danger); }
.toast__msg { flex: 1; min-width: 0; font-weight: 500; }
.toast__action {
  border: 0; background: none; padding: 6px 8px; border-radius: var(--r-xs);
  color: var(--accent); font-weight: 700; white-space: nowrap;
}
.toast__action:hover { background: var(--track); text-decoration: none; }
.toast__close {
  display: grid; place-items: center; flex: none;
  width: 30px; height: 30px; border: 0; border-radius: var(--r-xs);
  background: none; color: var(--text-muted);
}
.toast__close:hover { background: var(--track); color: var(--text); }
@media (max-width: 560px) {
  .toast-region { left: 16px; right: 16px; bottom: 16px; align-items: stretch; }
  .toast { min-width: 0; max-width: none; }
}

/* ---------- Modal e Drawer ---------- */
.layer { position: fixed; inset: 0; z-index: var(--z-layer); }
.layer__backdrop {
  position: absolute; inset: 0;
  background: rgba(5, 5, 7, 0.68);
  opacity: 0; transition: opacity var(--dur) var(--ease);
}
.layer.is-open .layer__backdrop { opacity: 1; }

.modal {
  position: absolute; left: 50%; top: 50%;
  display: flex; flex-direction: column;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow-overlay);
  opacity: 0; transform: translate(-50%, calc(-50% + 12px));
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.layer.is-open .modal { opacity: 1; transform: translate(-50%, -50%); }
.modal--sm { width: min(420px, calc(100vw - 32px)); }
.modal--lg { width: min(760px, calc(100vw - 32px)); }

.drawer {
  position: absolute; top: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column;
  width: min(520px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-overlay);
  transform: translateX(100%);
  transition: transform 220ms var(--ease);
}
.layer.is-open .drawer { transform: none; }
.drawer--lg { width: min(760px, 100vw); }
.drawer--xl { width: min(960px, 100vw); }

.layer__header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 20px 14px 22px;
}
.layer__title { font-size: var(--fs-card-title); font-weight: 700; letter-spacing: -0.01em; }
.layer__body { flex: 1 1 auto; overflow-y: auto; padding: 4px 22px 22px; }
.layer__footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
  padding: 16px 22px; border-top: 1px solid var(--divider);
}
.drawer .layer__header { border-bottom: 1px solid var(--divider); padding-bottom: 18px; }
.drawer .layer__body { padding-top: 20px; }

/* ---------- Menu (popover) ---------- */
.menu-anchor { position: relative; }
.menu {
  position: absolute; z-index: 60;
  min-width: 200px; padding: 6px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-pop);
}
.menu__item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; height: 40px; padding: 0 12px;
  border: 0; border-radius: var(--r-xs);
  background: none; color: var(--text-2); text-align: left;
  font-size: 14px; font-weight: 500;
}
.menu__item:hover, .menu__item:focus-visible { background: var(--track); color: var(--text); box-shadow: none; }
.menu__item--danger { color: var(--danger); }
.menu__sep { height: 1px; margin: 6px 4px; background: var(--divider); }

/* ---------- Tabela ---------- */
.table-wrap { overflow-x: auto; }
.table th {
  height: 40px; padding: 0 14px;
  text-align: left; white-space: nowrap;
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--divider);
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--divider); vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-subtle); }
.table tbody tr:last-child td { border-bottom: 0; }

/* ---------- Lista simples ---------- */
.list-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px;
  border-radius: var(--r-lg);
  background: var(--surface-subtle);
}

/* ---------- Ícone em quadrado (próximas ações, etc.) ---------- */
.icon-box {
  display: grid; place-items: center; flex: none;
  width: 38px; height: 38px; border-radius: var(--r-sm);
  background: var(--track); color: var(--text-2);
}
.icon-box--accent  { background: var(--accent-soft); color: var(--accent); }
.icon-box--success { background: var(--success-bg); color: var(--success); }
.icon-box--warning { background: var(--warning-bg); color: var(--warning); }
.icon-box--danger  { background: var(--danger-bg); color: var(--danger); }

/* ---------- Atalho de teclado ---------- */
.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 5px;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px;
  background: var(--surface-subtle); color: var(--text-2);
  font: 600 11px/1 var(--font);
}

.divider { height: 1px; background: var(--divider); border: 0; margin: 0; }
