*, *::before, *::after {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

h1, h2, h3, .font-display {
  font-family: "Poppins", "Inter", sans-serif;
}

/* Cards */
.peso-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  transition: box-shadow 0.2s;
}

.peso-card:hover {
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

/* Buttons */
.peso-btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #fff;
  background: #10b981;
  cursor: pointer;
  transition: background 0.15s;
}

.peso-btn-primary:hover {
  background: #059669;
}

.peso-btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #334155;
  background: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.peso-btn-outline:hover {
  background: #f8fafc;
}

/* Form */
.peso-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #334155;
}

.peso-input {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: #0f172a;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.peso-input:focus {
  outline: none;
  border-color: #10b981;
  box-shadow: 0 0 0 2px rgb(16 185 129 / 0.2);
}

.peso-textarea {
  resize: vertical;
  min-height: 4rem;
}

#settings-form input[type="date"],
#settings-form input[type="number"],
#add-weight-form input[type="date"],
#add-weight-form input[type="number"] {
  width: 100%;
  max-width: 100%;
  display: block;
}

@media (max-width: 899px) {
  #settings-form .space-y-2,
  #add-weight-form .space-y-2 {
    width: 100%;
  }

  #settings-form input[type="date"],
  #settings-form input[type="number"],
  #add-weight-form input[type="date"],
  #add-weight-form input[type="number"] {
    min-height: 48px;
  }

  #settings-form input[type="date"],
  #add-weight-form input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
  }
}

/* Table */
.peso-table tbody tr:last-child {
  border-bottom: none;
}

/* Histórico — cartões no telemóvel */
@media (max-width: 899px) {
  #history-table-card .history-table-scroll {
    overflow-x: visible;
  }

  #history-table-card .history-card-header {
    padding: 1rem 1rem 0.75rem;
  }

  #history-table-card .peso-history-table,
  #history-table-card .peso-history-table tbody {
    display: block;
  }

  #history-table-card .peso-history-table thead {
    display: none;
  }

  #history-table-card .peso-history-table tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "date actions"
      "weight delta"
      "note note";
    gap: 0.25rem 0.75rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid #f1f5f9;
  }

  #history-table-card .peso-history-table tbody tr:last-child {
    border-bottom: none;
  }

  #history-table-card .peso-history-table tbody tr:hover {
    background: #f8fafc;
  }

  #history-table-card .peso-history-table td {
    display: block;
    padding: 0;
    max-width: none;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }

  #history-table-card .peso-history-table td:nth-child(1) {
    grid-area: date;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #64748b;
    align-self: center;
    line-height: 1.3;
  }

  #history-table-card .peso-history-table td:nth-child(2) {
    grid-area: weight;
    font-size: 1.125rem;
    font-weight: 600;
    color: #0f172a;
    align-self: end;
  }

  #history-table-card .peso-history-table td:nth-child(3) {
    grid-area: delta;
    justify-self: end;
    align-self: end;
  }

  #history-table-card .peso-history-table td.history-note {
    grid-area: note;
    font-size: 0.8125rem;
    color: #64748b;
    line-height: 1.4;
    padding-top: 0.125rem;
  }

  #history-table-card .peso-history-table td.history-note.is-empty {
    display: none;
  }

  #history-table-card .peso-history-table td:nth-child(5) {
    grid-area: actions;
    text-align: right;
    align-self: start;
  }

  #history-table-card .peso-history-table .history-actions .btn-edit-entry,
  #history-table-card .peso-history-table .history-actions .btn-delete-entry {
    margin: -0.25rem -0.25rem 0 0;
    min-width: 2.75rem;
    min-height: 2.75rem;
  }
}

/* Dialog */
.peso-dialog {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.peso-dialog.hidden {
  display: none;
}

.peso-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(15 23 42 / 0.5);
}

.peso-dialog-panel {
  position: relative;
  width: 100%;
  max-width: 28rem;
  background: #fff;
  border-radius: 0.5rem;
  border: 1px solid #e2e8f0;
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
  padding: 1.5rem;
  animation: dialog-in 0.15s ease-out;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Toast */
.peso-toast {
  min-width: 240px;
  max-width: 360px;
  padding: 0.875rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  animation: toast-in 0.2s ease-out;
}

.peso-toast.destructive {
  border-color: #fecaca;
  background: #fef2f2;
}

.peso-toast-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #0f172a;
}

.peso-toast-desc {
  font-size: 0.8125rem;
  color: #64748b;
  margin-top: 0.125rem;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Nav active states (JS toggles classes) */
.nav-btn.is-active {
  background: #ecfdf5;
  color: #047857;
}

.mobile-nav-btn.is-active {
  color: #059669;
}

.chart-range-btn.is-active {
  background: #fff;
  color: #1e293b;
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

.chart-range-btn:not(.is-active) {
  color: #64748b;
}

/* Layout principal — largura equilibrada */
.peso-page {
  width: 100%;
  max-width: none;
}

.peso-page .view-section {
  width: 100%;
}

#view-settings .peso-settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  width: 100%;
  align-items: stretch;
}

#view-settings .peso-settings-card {
  height: 100%;
  display: flex;
  flex-direction: column;
}

#view-settings .peso-settings-card form {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

#view-settings .peso-settings-submit {
  margin-top: auto;
  align-self: flex-start;
}

@media (min-width: 1024px) {
  #view-settings .peso-settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #view-settings .peso-settings-card-wide {
    grid-column: 1 / -1;
  }
}

#notifications-form input[type="time"] {
  width: 100%;
  max-width: 100%;
  display: block;
}

@media (max-width: 899px) {
  #notifications-form input[type="time"] {
    min-height: 48px;
    -webkit-appearance: none;
    appearance: none;
  }
}

/* FAB mobile — registar peso */
.peso-fab {
  position: fixed;
  right: 1.25rem;
  bottom: 5.5rem;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 3.5rem;
  border: none;
  border-radius: 9999px;
  color: #fff;
  background: #10b981;
  box-shadow: 0 10px 25px -5px rgb(16 185 129 / 0.45), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.peso-fab:hover {
  background: #059669;
  transform: scale(1.04);
}

.peso-fab:active {
  transform: scale(0.98);
}
