/* ===== UaiOS components — buttons, inputs, cards, modals, badges, toasts ===== */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  border: 1px solid transparent;
  transition: transform 80ms ease, background 120ms ease, border-color 120ms ease;
  min-height: 40px;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-elev-2);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-icon {
  padding: 8px;
  min-height: 36px;
  min-width: 36px;
  border-radius: 8px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  min-height: 32px;
}

.btn-lg {
  padding: 14px 24px;
  font-size: 16px;
  min-height: 48px;
}

/* ---------- Inputs ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.field .hint {
  font-size: 12px;
  color: var(--text-mute);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
  outline: none;
  min-height: 40px;
  font-family: inherit;
}
.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}
.textarea {
  min-height: 96px;
  resize: vertical;
}

/* Select customizado — mesmo look do input */
.select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
  cursor: pointer;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-mute);
}

/* Toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 12px;
  transition: background 120ms ease;
}
.switch .slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 120ms ease;
}
.switch input:checked + .slider {
  background: var(--primary);
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
}

/* ---------- Datepicker + Timepicker ---------- */
.picker {
  position: relative;
}
.picker .picker-display {
  padding-right: 40px;
  cursor: pointer;
}
.picker .picker-icon {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text-mute);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.picker .picker-icon:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}
.picker .picker-icon svg { width: 16px; height: 16px; }
.picker-popup {
  position: fixed;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  padding: 12px;
  z-index: 5000;
  display: none;
  min-width: 260px;
}
.picker-popup.open { display: block; }

/* Calendario */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.cal-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.cal-nav {
  padding: 6px 8px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text-mute);
  cursor: pointer;
}
.cal-nav:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}
.cal-weekdays,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.cal-weekday {
  padding: 6px 0;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-mute);
}
.cal-cell {
  padding: 8px 0;
  text-align: center;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 100ms;
}
.cal-cell.empty {
  cursor: default;
  visibility: hidden;
}
.cal-cell:hover:not(.empty) {
  background: var(--bg-elev-2);
}
.cal-cell.selected {
  background: var(--primary);
  color: var(--primary-contrast);
  font-weight: 700;
}
.cal-cell.today:not(.selected) {
  border: 1px solid var(--primary);
  color: var(--primary);
}
.cal-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* Timepicker */
.time-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  height: 200px;
}
.time-col {
  overflow-y: auto;
  scrollbar-width: none;
  padding: 0 4px;
}
.time-col::-webkit-scrollbar { display: none; }
.time-cell {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  transition: background 100ms;
}
.time-cell:hover {
  background: var(--bg-elev-2);
}
.time-cell.selected {
  background: var(--primary);
  color: var(--primary-contrast);
  font-weight: 700;
}

/* ---------- Autocomplete ---------- */
.autocomplete {
  position: relative;
}
.autocomplete-input {
  width: 100%;
}
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  max-height: 280px;
  overflow-y: auto;
  scrollbar-width: none;
  z-index: 100;
  display: none;
  padding: 4px;
}
.autocomplete-list::-webkit-scrollbar { display: none; }
.autocomplete-list.open { display: block; }
.autocomplete-option {
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 100ms;
}
.autocomplete-option:hover,
.autocomplete-option.active {
  background: var(--bg-elev-2);
}
.autocomplete-label {
  font-size: 14px;
  color: var(--text);
}
.autocomplete-meta {
  margin-top: 2px;
}
.autocomplete-empty {
  padding: 12px;
  text-align: center;
  color: var(--text-mute);
  font-size: 13px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h2, .card-header h3 { margin: 0; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--bg-elev-2);
  color: var(--text-mute);
}
.badge-primary { background: color-mix(in oklab, var(--primary) 15%, transparent); color: var(--primary); }
.badge-success { background: color-mix(in oklab, var(--success) 15%, transparent); color: var(--success); }
.badge-danger { background: color-mix(in oklab, var(--danger) 15%, transparent); color: var(--danger); }
.badge-info { background: color-mix(in oklab, var(--info) 15%, transparent); color: var(--info); }

/* ---------- Table wrapper: sempre dentro de .card com padding:0 ---------- */
.card:has(> .table),
.card:has(> table.table) {
  overflow: hidden;
}
.table-wrap {
  overflow-x: auto;
  border-radius: inherit;
}

/* ---------- Table ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th,
.table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.table tr:last-child td {
  border-bottom: none;
}
.table th {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--bg-elev-2);
}
.table tbody tr:hover {
  background: var(--bg-elev-2);
}
.table td.actions {
  text-align: right;
  white-space: nowrap;
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-mute);
}
.empty-state h3 { color: var(--text); margin-bottom: 8px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: modalFadeIn 120ms ease;
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modalSlide 160ms ease;
}
.modal-lg { max-width: 900px; }
.modal-sm { max-width: 400px; }

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { margin: 0; }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  flex-shrink: 0;
}

.modal-close {
  background: transparent;
  color: var(--text-mute);
  padding: 4px;
  border-radius: 6px;
}
.modal-close:hover {
  color: var(--text);
  background: var(--bg-elev-2);
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modalSlide {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  min-width: 260px;
  animation: toastSlideIn 200ms ease;
  display: flex;
  align-items: center;
  gap: 12px;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--info); }
@keyframes toastSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 16px;
  color: var(--text-mute);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
  transition: color 120ms, border-color 120ms;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}

/* ---------- Spinner ---------- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Avatar ---------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-contrast);
  font-weight: 600;
  width: 36px;
  height: 36px;
  font-size: 14px;
  flex-shrink: 0;
}
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }
.avatar-lg { width: 48px; height: 48px; font-size: 18px; }
