/* =========================================================
   PharmaRoute · Plataforma (SPA layout)
   Reuses the same tokens as chat.css (--brand, --bg, --shadow-*, etc.)
   ========================================================= */

body.app-body {
  background: var(--bg);
  padding-bottom: calc(60px + env(safe-area-inset-bottom, 0));
  min-height: 100vh;
}
@media (min-width: 900px) {
  body.app-body {
    padding-bottom: 0;
    padding-left: 240px;
  }
}

/* ---------- Sidebar (desktop only) ---------- */
.app-sidebar {
  display: none;
  position: fixed;
  inset: 0 auto 0 0;
  width: 240px;
  padding: 20px 16px;
  background: white;
  border-right: 1px solid var(--border);
  flex-direction: column;
  z-index: 5;
}
@media (min-width: 900px) {
  .app-sidebar { display: flex; }
}
.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
}
.app-brand-mark {
  width: 38px; height: 38px; border-radius: 9px;
  background: var(--brand); color: white;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; letter-spacing: 0.02em;
}
.app-brand-name { font-weight: 700; font-size: 15px; color: var(--text-primary); }
.app-brand-sub  { font-size: 11.5px; color: var(--text-tertiary); margin-top: 1px; }

.app-nav {
  display: flex; flex-direction: column; gap: 2px;
  margin-top: 8px;
}
.app-nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--r-3);
  font-size: 14px; font-weight: 500;
  transition: background var(--dur-1) var(--ease-std), color var(--dur-1) var(--ease-std);
}
.app-nav-item:hover { background: var(--brand-xsoft); color: var(--brand-dark); }
.app-nav-item.active {
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 600;
}
.app-nav-icon { width: 20px; height: 20px; flex-shrink: 0; }

.app-footer-link { margin-top: auto; padding: 12px 8px; }
.app-footer-link a {
  color: var(--text-tertiary);
  font-size: 12.5px;
  text-decoration: none;
}
.app-footer-link a:hover { color: var(--brand); }

/* ---------- Main view ---------- */
.app-main { min-height: 100vh; }
.app-view {
  max-width: 960px;
  margin: 0 auto;
  /* Bottom padding clears the fixed tab bar + safe-area + a bit for the FAB. */
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom, 0));
  animation: viewIn var(--dur-2) var(--ease-out);
}
@media (min-width: 720px) {
  .app-view { padding: 28px 32px calc(96px + env(safe-area-inset-bottom, 0)); }
}
@media (min-width: 900px) {
  /* Desktop: no tab bar — collapse bottom padding. */
  .app-view { padding-bottom: 40px; }
}
@keyframes viewIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Bottom tab bar (mobile only) ---------- */
.app-tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(255,255,255,0.96);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(env(safe-area-inset-bottom, 0) + 6px);
  z-index: 10;
}
@media (min-width: 900px) { .app-tabbar { display: none; } }
.app-tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px;
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  border-radius: var(--r-3);
  transition: color var(--dur-1) var(--ease-std);
}
.app-tab svg { width: 22px; height: 22px; }
.app-tab.active { color: var(--brand); }

/* ---------- FAB ---------- */
.app-fab {
  position: fixed;
  right: 16px; bottom: calc(72px + env(safe-area-inset-bottom, 0));
  width: 56px; height: 56px;
  border: none; border-radius: 50%;
  background: linear-gradient(160deg, var(--brand), var(--brand-dark));
  color: white;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  text-decoration: none;
  font-weight: 600; font-size: 14px;
  box-shadow: 0 8px 24px rgba(15,122,77,0.35);
  cursor: pointer;
  z-index: 20;
  transition: transform var(--dur-1) var(--ease-std), box-shadow var(--dur-1) var(--ease-std);
}
.app-fab-label { display: none; }
.app-fab:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(15,122,77,0.4); }
.app-fab:active { transform: scale(0.97); }
@media (min-width: 900px) {
  .app-fab {
    bottom: 28px; right: 28px;
    width: auto; height: auto;
    padding: 12px 18px 12px 14px;
    border-radius: 999px;
  }
  .app-fab-label { display: inline; }
}

/* ---------- Common view elements ---------- */
.view-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 18px;
  gap: 12px; flex-wrap: wrap;
}
.view-title { font-size: 22px; font-weight: 700; color: var(--text-primary); margin: 0; }
.view-sub { color: var(--text-tertiary); font-size: 13px; margin-top: 2px; }

.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 14px; }
.card-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 12px;
}
.card-title {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-tertiary);
}

/* KPI + small stats */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kpi-cell {
  background: var(--bg);
  border-radius: var(--r-2);
  padding: 12px 14px;
}
.kpi-val { font-size: 22px; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.kpi-label { font-size: 11px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 4px; }
.kpi-delta { font-size: 13px; font-weight: 600; }
.kpi-delta.up   { color: var(--brand); }
.kpi-delta.down { color: var(--danger); }

/* Alerts */
.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert {
  display: grid;
  grid-template-columns: 8px 1fr auto;
  gap: 12px;
  padding: 12px 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  transition: background var(--dur-1), transform var(--dur-1), box-shadow var(--dur-1);
  cursor: pointer;
  text-decoration: none; color: inherit;
}
.alert:hover { background: var(--bg); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.alert-pip { width: 6px; border-radius: 4px; align-self: stretch; }
.alert.sev-danger .alert-pip { background: var(--danger); }
.alert.sev-warn   .alert-pip { background: #f7b500; }
.alert.sev-info   .alert-pip { background: var(--brand); }
.alert-body { min-width: 0; }
.alert-title {
  font-weight: 600; font-size: 14px; color: var(--text-primary);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.alert-title .alert-sub { font-weight: 500; color: var(--text-secondary); font-size: 13px; }
.alert-msg { font-size: 12.5px; color: var(--text-tertiary); margin-top: 3px; }
.alert-cta {
  align-self: center;
  color: var(--brand); font-size: 12.5px; font-weight: 500;
  white-space: nowrap;
}

/* Pharmacy list (cartera) */
.cartera-filters {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px;
}
.cartera-filters input[type=search] {
  flex: 1 1 200px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font: inherit; font-size: 14px;
  background: white;
  box-shadow: var(--shadow-sm);
}
.cartera-filters input[type=search]:focus { outline: none; border-color: var(--brand); box-shadow: var(--shadow-ring); }
.filter-chip {
  padding: 8px 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  color: var(--text-secondary);
  font-size: 12px; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--dur-1) var(--ease-std);
}
.filter-chip:hover { border-color: var(--brand); color: var(--brand-dark); }
.filter-chip.active { background: var(--brand); color: white; border-color: var(--brand); }

.pharm-list { display: flex; flex-direction: column; gap: 8px; }
.pharm-card {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 12px;
  padding: 12px 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  text-decoration: none; color: inherit;
  transition: all var(--dur-1) var(--ease-std);
}
.pharm-card:hover { border-color: rgba(15,122,77,0.3); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.pharm-avatar {
  width: 36px; height: 36px; border-radius: 9px;
  background: var(--brand-soft); color: var(--brand-dark);
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
}
.pharm-body { min-width: 0; }
.pharm-name { font-weight: 600; font-size: 14.5px; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pharm-city { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }
.pharm-stats { display: flex; gap: 10px; margin-top: 5px; font-size: 12px; color: var(--text-secondary); flex-wrap: wrap; }
.pharm-stats .up   { color: var(--brand); font-weight: 600; }
.pharm-stats .down { color: var(--danger); font-weight: 600; }
.pharm-tags { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 4px; }
.pharm-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.pharm-tag.danger { background: #ffe9e9; color: #b53030; border-color: #f3c9c9; }
.pharm-tag.warn { background: #fff7e1; color: #92721a; border-color: #f2d98b; }
.pharm-tag.info { background: var(--brand-soft); color: var(--brand-dark); border-color: rgba(15,122,77,0.2); }

.pharm-arrow { color: var(--text-tertiary); align-self: center; font-size: 18px; line-height: 1; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-tertiary); font-size: 14px; }
.loading { padding: 40px 0; text-align: center; color: var(--text-tertiary); font-size: 13px; }

/* Pharmacy detail page */
.detail-head {
  display: flex; align-items: flex-start; gap: 12px;
  margin-bottom: 16px;
}
.detail-back {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--brand); text-decoration: none;
  font-size: 13px; font-weight: 500;
  margin-bottom: 8px;
}
.detail-back:hover { color: var(--brand-dark); }
.detail-name {
  font-size: 22px; font-weight: 700; line-height: 1.2;
  color: var(--text-primary);
}
.detail-addr { color: var(--text-secondary); font-size: 14px; margin-top: 3px; }
.detail-tabs {
  display: flex; gap: 4px; margin-top: 14px; margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.detail-tab {
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font: inherit; font-size: 13.5px; font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--dur-1), border-color var(--dur-1);
  white-space: nowrap;
}
.detail-tab:hover { color: var(--brand); }
.detail-tab.active { color: var(--brand-dark); border-bottom-color: var(--brand); font-weight: 600; }

.detail-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 10px; margin-bottom: 4px;
}
.detail-actions button, .detail-actions a {
  padding: 10px 16px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: white;
  color: var(--text-primary);
  font: inherit; font-size: 13.5px; font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all var(--dur-1) var(--ease-std);
}
.detail-actions button.primary, .detail-actions a.primary {
  background: linear-gradient(160deg, var(--brand), var(--brand-dark));
  border-color: var(--brand);
  color: white;
  box-shadow: var(--shadow-md);
}
.detail-actions button:hover, .detail-actions a:hover { transform: translateY(-1px); }

/* Data grid inside detail */
.data-row { display: grid; grid-template-columns: 120px 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.data-row:first-child { border-top: none; }
.data-key { color: var(--text-tertiary); font-size: 13px; }
.data-val { color: var(--text-primary); font-size: 13.5px; }

/* Chart container */
.chart-wrap { position: relative; height: 280px; margin-top: 8px; }

/* Visit feed */
.visit-feed { display: flex; flex-direction: column; gap: 10px; }
.visit-card {
  background: white; border: 1px solid var(--border); border-radius: var(--r-3);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.visit-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px; margin-bottom: 6px;
}
.visit-who { font-weight: 600; font-size: 14.5px; color: var(--text-primary); }
.visit-when { font-size: 12px; color: var(--text-tertiary); }
.visit-sub { color: var(--text-secondary); font-size: 12.5px; margin-bottom: 8px; }
.visit-notes { font-size: 13.5px; color: var(--text-primary); line-height: 1.5; }
.visit-followup { margin-top: 6px; font-size: 12.5px; color: var(--brand-dark); }
.visit-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.visit-chip { font-size: 11px; padding: 2px 8px; border-radius: var(--r-pill); background: var(--brand-xsoft); color: var(--brand-dark); border: 1px solid rgba(15,122,77,0.15); }
.visit-chip.sent-positive { background: var(--brand-soft); color: var(--brand-dark); border-color: rgba(15,122,77,0.2); }
.visit-chip.sent-neutral  { background: var(--bg); color: var(--text-secondary); }
.visit-chip.sent-negative { background: #fff2f2; color: var(--danger); border-color: #f3c9c9; }

/* Assistant embed */
.assistant-embed {
  width: 100%;
  height: calc(100vh - 120px);
  min-height: 500px;
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  overflow: hidden;
}
@media (min-width: 900px) {
  .assistant-embed { height: calc(100vh - 60px); }
}
