/* ═══════════════════════════════════════════════════════════════════
   APEX v2 — Components (Dark)
   Botões, cards, chips, modals, inputs — tudo com linhas definidas.
═══════════════════════════════════════════════════════════════════ */

/* ── BOTÕES ──────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
  letter-spacing: -0.005em;
  white-space: nowrap;
  min-height: 40px;
}

.btn-primary,
.btn-green {
  background: var(--green);
  color: #042018;
  font-weight: 600;
  border-color: var(--green);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled),
.btn-green:hover:not(:disabled) {
  background: var(--green-deep);
  border-color: var(--green-deep);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.btn-primary:active:not(:disabled),
.btn-green:active:not(:disabled) {
  transform: translateY(0);
}

.btn-outline {
  background: var(--bg-2);
  color: var(--text);
  border-color: var(--line-3);
}
.btn-outline:hover:not(:disabled) {
  background: var(--bg-3);
  border-color: var(--line-4);
}

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

.btn-danger {
  background: var(--crit-tint);
  color: var(--crit);
  border-color: rgba(224, 56, 48, 0.3);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(224, 56, 48, 0.22);
  border-color: var(--crit);
}

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

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

.btn-full {
  width: 100%;
  white-space: normal; /* override nowrap: texto pode partir linha em ecrãs estreitos */
}

.btn-arrow::after {
  content: '→';
  font-size: 14px;
  transition: transform var(--duration-fast) var(--ease);
  display: inline-block;
}
.btn-arrow:hover::after {
  transform: translateX(3px);
}

/* ── CARDS ──────────────────────────────────────── */

.card {
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--duration) var(--ease),
              background var(--duration) var(--ease);
}

.card-elevated {
  background: var(--bg-2);
  border-color: var(--line-3);
  box-shadow: var(--shadow-md);
}

.card-muted {
  background: var(--bg-1);
  border-color: var(--line);
}

.card-inline {
  padding: var(--sp-4);
  border-radius: var(--radius);
}

.card-interactive {
  cursor: pointer;
}
.card-interactive:hover {
  background: var(--bg-2);
  border-color: var(--line-3);
}

/* ── CHIPS (sempre com fundo sólido, nunca flutuantes) ── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
  user-select: none;
  min-height: 34px;
}

.chip:hover:not(.chip-selected):not(:disabled) {
  border-color: var(--line-4);
  background: var(--bg-3);
}

.chip-selected {
  background: var(--green-tint);
  color: var(--green);
  border-color: var(--green);
  font-weight: 600;
}

.chip-sm {
  padding: 5px 10px;
  font-size: 11.5px;
  min-height: 26px;
}

/* ── INPUTS / FIELDS ──────────────────────────────── */

.field {
  display: block;
  width: 100%;
  padding: 11px 14px;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  transition: border-color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease),
              box-shadow var(--duration-fast) var(--ease);
  min-height: 44px;
}

.field:hover {
  border-color: var(--line-3);
}

.field:focus {
  outline: none;
  border-color: var(--green);
  background: var(--bg-3);
  box-shadow: 0 0 0 3px var(--green-tint);
}

.field::placeholder {
  color: var(--text-3);
}

.field-error {
  border-color: var(--crit);
  background: var(--crit-tint);
}

.field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--text-2);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.field-help {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 6px;
  line-height: 1.5;
}

.field-error-msg {
  font-size: 12.5px;
  color: var(--crit);
  margin-top: 6px;
  font-weight: 500;
}

/* Wrapper com unidade (kg, cm) */
.field-wrap {
  position: relative;
}
.field-wrap .field { padding-right: 48px; }
.field-wrap .field-unit {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  pointer-events: none;
  letter-spacing: 0.04em;
  font-weight: 500;
}

/* Textarea */
textarea.field {
  min-height: 80px;
  resize: vertical;
  line-height: 1.5;
}

/* Checkbox custom */
.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  transition: all var(--duration-fast) var(--ease);
}
.checkbox:hover {
  border-color: var(--line-3);
  background: var(--bg-3);
}
.checkbox input[type="checkbox"] {
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--bg-3);
  border: 1.5px solid var(--line-4);
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 1px;
  position: relative;
  transition: all var(--duration-fast) var(--ease);
}
.checkbox input[type="checkbox"]:checked {
  background: var(--green);
  border-color: var(--green);
}
.checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #042018;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.checkbox-content {
  flex: 1;
  min-width: 0;
}
.checkbox-title {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 2px;
}
.checkbox-sub {
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.4;
}

/* ── OPTION CARDS (onboarding) ──────────────────── */

.opt-card {
  position: relative;
  width: 100%;
  text-align: left;
  padding: 18px 20px;
  background: var(--bg-2);
  border: 1px solid var(--line-3);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
  font-family: inherit;
  color: var(--text);
}
.opt-card:hover {
  border-color: var(--line-4);
  background: var(--bg-3);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.opt-card:active {
  transform: translateY(0);
}
.opt-card[data-selected="true"] {
  background: var(--green-tint);
  border-color: var(--green);
  box-shadow: var(--shadow-green);
}
.opt-card .opt-num {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 0.12em;
  margin-bottom: 8px;
  text-transform: uppercase;
}
.opt-card .opt-title {
  font-family: var(--font-serif);
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--text);
  line-height: 1.25;
  margin-bottom: 4px;
}
.opt-card[data-selected="true"] .opt-title {
  color: var(--green);
}
.opt-card .opt-sub {
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.5;
}
.opt-card .opt-check {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--line-4);
  background: var(--bg-3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-fast) var(--ease);
  flex-shrink: 0;
}
.opt-card[data-selected="true"] .opt-check {
  border-color: var(--green);
  background: var(--green);
}
.opt-card[data-selected="true"] .opt-check::after {
  content: '';
  width: 5px;
  height: 9px;
  border: solid #042018;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  margin-top: -2px;
}

/* ── PICKER BUTTON (check-in scales) ──────────────── */

.picker-btn {
  padding: 16px 8px;
  background: var(--bg-2);
  border: 1px solid var(--line-3);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  transition: all var(--duration-fast) var(--ease);
  min-height: 64px;
}
.picker-btn:hover:not([data-selected="true"]) {
  background: var(--bg-3);
  border-color: var(--line-4);
  transform: translateY(-1px);
}
.picker-btn[data-selected="true"] {
  background: var(--green-tint);
  border-color: var(--green);
  color: var(--green);
  box-shadow: var(--shadow-green);
}
.picker-btn .picker-label {
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.2;
}
.picker-btn .picker-sub {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-3);
  margin-top: 4px;
  letter-spacing: 0.04em;
}
.picker-btn[data-selected="true"] .picker-sub {
  color: var(--green-deep);
}

/* ── MODAL / OVERLAY ────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration) var(--ease);
}
.overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-1);
  border: 1px solid var(--line-3);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--sp-6);
  transform: translateY(12px);
  transition: transform var(--duration) var(--ease-out);
}
.overlay.open .modal { transform: translateY(0); }

.modal-header { margin-bottom: var(--sp-5); }
.modal-title {
  font-family: var(--font-serif);
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 6px;
}
.modal-sub {
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.55;
}
.modal-body { margin-bottom: var(--sp-5); }
.modal-actions {
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
}

/* ── TOAST ───────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: calc(var(--sp-8) + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line-3);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration) var(--ease),
              transform var(--duration) var(--ease);
  max-width: calc(100vw - 48px);
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.toast-error {
  background: var(--crit-tint);
  border-color: var(--crit);
  color: #FDD;
}
.toast.toast-info {
  background: var(--info-tint);
  border-color: var(--info);
  color: #DFF;
}

/* ── BADGE ───────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  color: var(--text-2);
  border: 1px solid var(--line-2);
}
.badge-green { background: var(--green-tint); color: var(--green); border-color: var(--green); }
.badge-warn  { background: var(--warn-tint);  color: var(--warn);  border-color: var(--warn); }
.badge-crit  { background: var(--crit-tint);  color: var(--crit);  border-color: var(--crit); }
.badge-info  { background: var(--info-tint);  color: var(--info);  border-color: var(--info); }

/* ── DIVIDERS ─────────────────────────────────────── */

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

.divider-text {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: var(--sp-5) 0;
}
.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* ── LOADING ─────────────────────────────────────── */

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line-3);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
  vertical-align: middle;
}

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

.skeleton {
  background: linear-gradient(90deg, var(--bg-1) 25%, var(--bg-2) 50%, var(--bg-1) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

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

/* ── TABS (para ecrã Plano e Saúde) ───────────────── */

.tabs {
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
}
.tab {
  flex: 1;
  padding: 9px 14px;
  background: transparent;
  border: none;
  color: var(--text-2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--duration-fast) var(--ease);
  text-align: center;
}
.tab:hover:not([aria-selected="true"]) {
  color: var(--text);
  background: var(--bg-3);
}
.tab[aria-selected="true"] {
  background: var(--bg-4);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

/* ── LIST ROW (linhas clicáveis em cards) ──────── */

.list-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: 14px 18px;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  transition: background var(--duration-fast) var(--ease);
}
.list-row:hover {
  background: var(--bg-2);
}
.list-row:not(:last-child) {
  border-bottom: 1px solid var(--line);
}
.list-row-title {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 3px;
}
.list-row-sub {
  font-size: 12px;
  color: var(--text-3);
}
.list-row-chevron {
  color: var(--text-3);
  flex-shrink: 0;
}

/* ── Aparelho mobile: touch targets maiores ───── */

@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .chip { min-height: 38px; }
  .picker-btn { min-height: 68px; }
}
