/* Dental Track — tema bordô (#3D010B) */
:root {
  --brand-900: #3d010b;
  --brand-700: #6b1426;
  --brand-600: #8c2a3e;
  --bg: #f8f4f4;
  --card-bg: #ffffff;
  --text: #2a1a1d;
  --text-muted: #6b5b5e;
  --border: #e8dfe0;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --yellow: #a16207;
  --yellow-bg: #fef9c3;
  --green: #15803d;
  --green-bg: #dcfce7;
  --violet: #6d28d9;
  --violet-bg: #ede9fe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(61, 1, 11, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 2rem;
}

[hidden] { display: none !important; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--brand-900);
  color: white;
  padding: 0.9rem 1rem;
  padding-top: max(0.9rem, env(safe-area-inset-top));
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand img { width: 30px; height: 30px; display: block; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-topbar-secondary {
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: white;
  text-decoration: none;
  white-space: nowrap;
  background: none;
  cursor: pointer;
}

.btn-topbar-secondary:disabled { opacity: 0.6; }

@media (max-width: 480px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .topbar-actions { width: 100%; }

  .topbar-actions > a,
  .topbar-actions > button {
    flex: 1;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    font-size: 0.78rem;
    text-align: center;
  }
}

/* ---------- Botões ---------- */
.btn-primary, .btn-secondary {
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: #ffffff;
  color: var(--brand-900);
}

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.6; cursor: default; }

/* ---------- Barra do usuário / clínica ---------- */
.userbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.35rem 0.75rem;
  padding: 0.5rem 1rem 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.userbar-left, .userbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.75rem;
  min-width: 0;
}

.clinic-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
  border: 1px solid var(--brand-600);
  background: #fff;
  color: var(--brand-900);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.clinic-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-button {
  border: none;
  background: none;
  color: var(--brand-700);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* ---------- Alerta de vencimentos ---------- */
.alert-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  margin: 0.75rem 1rem 0;
  padding: 0.6rem 0.8rem;
  background: #fff;
  border: 1px solid var(--brand-600);
  border-left-width: 5px;
  border-radius: var(--radius);
  font-size: 0.82rem;
  box-shadow: var(--shadow);
}

.alert-banner strong { color: var(--brand-900); }

.alert-pill {
  border: none;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.alert-pill.vencido { background: var(--red-bg); color: var(--red); }
.alert-pill.d7 { background: var(--amber-bg); color: var(--amber); }
.alert-pill.d15 { background: var(--yellow-bg); color: var(--yellow); }
.alert-pill.baixo { background: var(--violet-bg); color: var(--violet); }

.notify-button {
  margin-left: auto;
  border: 1px solid var(--brand-600);
  background: #fff;
  color: var(--brand-900);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.notify-button.on { background: var(--brand-900); color: #fff; }

/* ---------- Resumo ---------- */
.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  padding: 1rem;
}

.summary-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 0.7rem 0.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.summary-card .num { font-size: 1.4rem; font-weight: 700; display: block; }
.summary-card .label { font-size: 0.68rem; color: var(--text-muted); }

.summary-card.vencido .num { color: var(--red); }
.summary-card.critico .num { color: var(--amber); }
.summary-card.atencao .num { color: var(--yellow); }
.summary-card.ok .num { color: var(--green); }

/* ---------- Filtros ---------- */
.filters {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0 1rem 0.5rem;
}

.filters-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.filters input, .filters select {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  background: white;
  color: var(--text);
  font-family: inherit;
}

.filters-more {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
}

.filters-more summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--brand-700);
}

.filters-more-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.filters-more-body label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.filters-more-body .span-2 { grid-column: 1 / -1; }

.filters-hint { font-size: 0.74rem; color: var(--text-muted); margin: 0; }

.result-count { padding: 0 1rem; font-size: 0.78rem; color: var(--text-muted); }

/* ---------- Lista e cartões ---------- */
.list {
  padding: 0.25rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.card.vencido { border-left-color: var(--red); }
.card.critico { border-left-color: var(--amber); }
.card.atencao { border-left-color: var(--yellow); }
.card.ok { border-left-color: var(--green); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.card-header-main {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.card-title { font-weight: 600; font-size: 0.98rem; overflow-wrap: anywhere; }
.card-category { font-size: 0.78rem; color: var(--text-muted); }

.card-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.card-badges {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}

.badge.vencido { background: var(--red-bg); color: var(--red); }
.badge.critico { background: var(--amber-bg); color: var(--amber); }
.badge.atencao { background: var(--yellow-bg); color: var(--yellow); }
.badge.ok { background: var(--green-bg); color: var(--green); }
.badge.baixo { background: var(--violet-bg); color: var(--violet); }

.card-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.3rem;
}

.card-actions button {
  flex: 1;
  padding: 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  font-size: 0.82rem;
  cursor: pointer;
}

.card-actions button.useBtn { color: var(--brand-700); border-color: var(--brand-600); }
.card-actions button.danger { color: var(--red); border-color: var(--red-bg); }

@media (min-width: 640px) {
  .list { display: grid; grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 960px) {
  .list { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Diálogos ---------- */
dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(92vw, 420px);
  color: var(--text);
}

dialog::backdrop { background: rgba(61, 1, 11, 0.45); }

.dialog-form {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.dialog-form h2 { margin: 0 0 0.3rem; font-size: 1.1rem; color: var(--brand-900); }

.dialog-form label {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.dialog-form input,
.dialog-form select,
.dialog-form textarea {
  font-size: 0.95rem;
  padding: 0.55rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  background: #fff;
}

.dialog-form .btn-primary { background: var(--brand-900); color: #fff; }

.dialog-actions { display: flex; gap: 0.6rem; margin-top: 0.4rem; }
.dialog-actions button { flex: 1; }

.row { display: flex; gap: 0.6rem; }
.row label { flex: 1; min-width: 0; }

.field-label { font-size: 0.82rem; color: var(--text-muted); }
.field-hint { font-size: 0.72rem; color: var(--text-muted); font-weight: 400; }

#integrationDialog { width: min(92vw, 480px); }
#integrationForm { max-height: 85vh; overflow-y: auto; }
#integrationForm input, #integrationForm select { font-size: 0.9rem; padding: 0.5rem 0.6rem; }
#useForm input { font-size: 1.1rem; }

.integration-help { font-size: 0.8rem; color: var(--text-muted); margin: 0; line-height: 1.4; }

.mapping-fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.mapping-fieldset legend { font-size: 0.78rem; color: var(--text-muted); padding: 0 0.3rem; }

.integration-result {
  background: var(--bg);
  border-radius: 8px;
  padding: 0.7rem;
  font-size: 0.72rem;
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.use-product-name { margin: 0; font-weight: 600; font-size: 1rem; }
.use-current-qty { margin: 0; font-size: 0.82rem; color: var(--text-muted); }

.photo-capture { display: flex; flex-direction: column; gap: 0.4rem; }

.photo-preview {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.photo-buttons { display: flex; gap: 0.5rem; }
.photo-buttons button { flex: 1; }

.ocr-status { margin: 0; font-size: 0.78rem; color: var(--text-muted); }
.ocr-status.ocr-success { color: var(--green); }
.ocr-status.ocr-fail { color: var(--amber); }

/* Lista de clínicas (trocar de clínica) */
.clinic-list { display: flex; flex-direction: column; gap: 0.4rem; }

.clinic-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.clinic-option:hover { border-color: var(--brand-600); }
.clinic-option.current { border-color: var(--brand-900); background: #fbf3f4; }
.clinic-option small { font-weight: 600; color: var(--brand-700); }

.clinic-section { border-top: 1px solid var(--border); padding-top: 0.7rem; display: flex; flex-direction: column; gap: 0.5rem; }
.clinic-section h3 { margin: 0; font-size: 0.85rem; color: var(--text); }
.inline-form { display: flex; gap: 0.5rem; }
.inline-form input { flex: 1; min-width: 0; }
.inline-form button { flex: 0 0 auto; }

.member-list { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.6rem; }
.member-row { display: flex; align-items: center; justify-content: space-between; padding: 0.4rem 0.6rem; background: var(--bg); border-radius: 6px; font-size: 0.9rem; }
.member-email { color: var(--text); }
.member-role { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 12px; }
.member-role.owner { background: #fdf5f6; color: var(--brand-900); }
.member-role.colaborador { background: #e8f0fe; color: #1a4a8a; }

/* ---------- Login / cadastro ---------- */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(61, 1, 11, 0.14);
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 380px;
}

.auth-logo { display: block; width: 64px; height: 64px; margin: 0 auto 0.4rem; }

.auth-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
  text-align: center;
  color: var(--brand-900);
}

.auth-subtitle {
  margin: 0 0 1.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}

.auth-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
  background: var(--bg);
  border-radius: 999px;
  padding: 0.25rem;
}

.auth-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.5rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.auth-tab.active { background: var(--brand-900); color: white; }

.auth-form, .clinic-step { display: flex; flex-direction: column; gap: 0.8rem; }

.auth-form label {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.auth-form input, .clinic-step input {
  font-size: 0.95rem;
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
}

.auth-form .btn-primary, .clinic-step .btn-primary {
  background: var(--brand-900);
  color: white;
  padding: 0.7rem;
  margin-top: 0.3rem;
}

.clinic-step h2 { margin: 0; font-size: 1.05rem; color: var(--brand-900); text-align: center; }
.clinic-step p { margin: 0; font-size: 0.82rem; color: var(--text-muted); text-align: center; }

.auth-error {
  margin: 1rem 0 0;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  background: var(--red-bg);
  color: var(--red);
  font-size: 0.82rem;
  text-align: center;
}
