/* Estilos da Farmácia por cima do CSS base do kit (css/style.css, que fica
   igual ao do pwa-kit para receber correções sem conflito). */
:root {
  --bg: #f1f5f4;
  --border: #d7e2df;
  --primary: #0f766e;
  --primary-contrast: #ffffff;
  --accent: #0d9488;
  --warn: #a16207;
  --warn-bg: #fef3c7;
  --shadow: 0 8px 24px rgba(15, 45, 42, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1716;
    --surface: #152321;
    --border: #28403c;
    --text-muted: #9bb3ae;
    --primary: #5eead4;
    --primary-contrast: #042f2e;
    --accent: #2dd4bf;
    --warn: #fcd34d;
    --warn-bg: #3a2e0a;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

main#app {
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

/* ---------- cabeçalho ---------- */

#btn-sync {
  position: relative;
}

.pending-count {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--pending);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.menu-item-danger {
  color: var(--danger);
}

/* ---------- aviso de configuração ---------- */

.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.notice .btn {
  flex-shrink: 0;
}

/* ---------- filtros e busca ---------- */

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}

.chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.chip-count {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 12px;
  text-align: center;
}

.chip[aria-selected="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-contrast);
}

.chip[aria-selected="true"] .chip-count {
  background: rgba(255, 255, 255, 0.22);
}

.chip-danger:not([aria-selected="true"]) .chip-count:not(:empty) {
  color: var(--danger);
}

.chip-warn:not([aria-selected="true"]) .chip-count:not(:empty) {
  color: var(--warn);
}

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search,
.sort select,
.field textarea {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.search {
  flex: 1;
  min-width: 0;
}

.sort select {
  height: 100%;
  padding-right: 8px;
}

.search:focus,
.sort select:focus,
.field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- lista ---------- */

.remedio-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.remedio {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 10px 4px 4px;
}

.remedio.val-vencido { border-left-color: var(--danger); }
.remedio.val-vencendo { border-left-color: var(--warn); }
.remedio.val-ok { border-left-color: var(--success); }

.remedio-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-align: left;
  padding: 8px 8px;
  cursor: pointer;
}

.remedio-nome {
  font-weight: 600;
  font-size: 15px;
}

.remedio-apres {
  font-weight: 400;
  color: var(--text-muted);
}

.remedio-meta {
  font-size: 13px;
  color: var(--text-muted);
}

.val-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-top: 2px;
}

.val-badge.val-vencido { background: var(--danger-bg); color: var(--danger); }
.val-badge.val-vencendo { background: var(--warn-bg); color: var(--warn); }
.val-badge.val-ok { background: var(--success-bg); color: var(--success); }
.val-badge.val-none { background: var(--bg); color: var(--text-muted); }

.btn-usei {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 36px;
  justify-content: center;
  font-size: 14px;
}

/* ---------- botão flutuante ---------- */

.fab {
  position: fixed;
  right: max(16px, calc((100vw - 640px) / 2 + 16px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 15;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-contrast);
  font-size: 15px;
  font-weight: 700;
  padding: 14px 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- folha (dialog) ---------- */

.sheet {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  padding: 18px 16px;
  box-shadow: var(--shadow);
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.sheet h2 {
  font-size: 17px;
  margin: 0 0 14px;
}

.sheet-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field textarea {
  resize: vertical;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-row .field input {
  width: 100%;
  min-width: 0;
}

@media (max-width: 380px) {
  .field-row { grid-template-columns: 1fr; }
}

.stepper {
  display: flex;
  gap: 6px;
}

.stepper input {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.stepper-btn {
  justify-content: center;
  min-width: 40px;
  font-size: 18px;
  padding: 6px 10px;
}

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.sheet-actions .spacer {
  flex: 1;
}

/* ---------- aviso com desfazer ---------- */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 30;
  width: max-content;
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: center;
  gap: 14px;
  background: #1f2a28;
  color: #fff;
  border-radius: 12px;
  padding: 10px 12px 10px 16px;
  font-size: 14px;
  box-shadow: var(--shadow);
}

.toast-undo {
  background: none;
  border: none;
  color: #5eead4;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 4px;
}

/* ---------- sugestões (Anvisa) ---------- */

.suggest-field {
  position: relative;
}

.suggest-field label {
  color: var(--text-muted);
}

.suggest {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 5;
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.suggest-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.suggest-item:hover,
.suggest-item:focus-visible {
  background: var(--bg);
}

.suggest-label {
  font-size: 14px;
  font-weight: 600;
}

.suggest-detail {
  font-size: 12px;
  color: var(--text-muted);
}

.equivalentes {
  margin: 2px 0 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 13px;
  line-height: 1.4;
}

.fonte-anvisa {
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
}

.fonte-anvisa a {
  color: inherit;
}

/* ---------- configurações: endereços do servidor (recolhidos) ---------- */

.advanced {
  font-size: 13px;
  color: var(--text-muted);
}

.advanced summary {
  cursor: pointer;
  padding: 4px 0;
}

.advanced[open] {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-hint {
  min-height: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.field-hint.val-vencido { color: var(--danger); }
.field-hint.val-vencendo { color: var(--warn); }
.field-hint.val-ok { color: var(--success); }

.field-row .field label,
.field > label {
  color: var(--text-muted);
}
