/* =========================================================================
   DrugReminder — visual refit (healthcare moderno, responsivo, dark mode)
   Mantém todos os seletores consumidos por app.js e login.js.
   ========================================================================= */

:root {
  color-scheme: light;

  /* Paleta light (healthcare / clean) */
  --bg: #f6f8fb;
  --bg-elev: #ffffff;
  --bg-subtle: #eef2f7;
  --bg-hover: #f1f5f9;
  --panel: #ffffff;
  --panel-muted: #f8fafc;

  --ink: #0f172a;
  --ink-soft: #1e293b;
  --muted: #64748b;
  --muted-strong: #475569;
  --line: #e5e9f0;
  --line-strong: #d8dee9;

  --primary: #0f766e;        /* teal 700 */
  --primary-strong: #115e59; /* teal 800 */
  --primary-soft: #ccfbf1;   /* teal 100 */
  --primary-ink: #ffffff;

  --accent: #2563eb;         /* blue 600 */
  --accent-soft: #dbeafe;

  --warn: #b45309;           /* amber 700 */
  --warn-soft: #fef3c7;

  --danger: #b91c1c;         /* red 700 */
  --danger-soft: #fee2e2;

  --success: #166534;        /* green 800 */
  --success-soft: #dcfce7;

  --ring: 0 0 0 3px rgba(15, 118, 110, 0.18);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06), 0 2px 6px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, 0.15);

  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 22px;

  --sidebar-w: 264px;
  --topbar-h: 64px;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0b1220;
  --bg-elev: #111a2c;
  --bg-subtle: #0f1828;
  --bg-hover: #17223a;
  --panel: #111a2c;
  --panel-muted: #0f1828;

  --ink: #e7ecf3;
  --ink-soft: #c9d3e2;
  --muted: #8696ad;
  --muted-strong: #a4b1c6;
  --line: #1f2c45;
  --line-strong: #2a3a5a;

  --primary: #2dd4bf;        /* teal 400 */
  --primary-strong: #5eead4;
  --primary-soft: rgba(45, 212, 191, 0.18);
  --primary-ink: #06221f;

  --accent: #60a5fa;
  --accent-soft: rgba(96, 165, 250, 0.18);

  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.18);

  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.18);

  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.18);

  --ring: 0 0 0 3px rgba(45, 212, 191, 0.28);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.55);
}

/* Quando o sistema está em dark e o usuário não escolheu tema manualmente */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    color-scheme: dark;

    --bg: #0b1220;
    --bg-elev: #111a2c;
    --bg-subtle: #0f1828;
    --bg-hover: #17223a;
    --panel: #111a2c;
    --panel-muted: #0f1828;

    --ink: #e7ecf3;
    --ink-soft: #c9d3e2;
    --muted: #8696ad;
    --muted-strong: #a4b1c6;
    --line: #1f2c45;
    --line-strong: #2a3a5a;

    --primary: #2dd4bf;
    --primary-strong: #5eead4;
    --primary-soft: rgba(45, 212, 191, 0.18);
    --primary-ink: #06221f;

    --accent: #60a5fa;
    --accent-soft: rgba(96, 165, 250, 0.18);

    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, 0.18);

    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.18);

    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, 0.18);

    --ring: 0 0 0 3px rgba(45, 212, 191, 0.28);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: "Inter", "Nunito Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Camada ambiente é agora decorativa e muito discreta */
.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(1200px 600px at -10% -10%, var(--primary-soft), transparent 60%),
    radial-gradient(800px 500px at 110% -20%, var(--accent-soft), transparent 60%);
  opacity: 0.5;
}

h1, h2, h3, h4 {
  font-family: "Inter", "Fraunces", system-ui, sans-serif;
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.01em;
}

h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.125rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }

p { margin: 0; }

button, input, textarea, select { font: inherit; color: inherit; }

/* =============================
   Layout principal: sidebar + shell
   ============================= */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  padding: 20px 16px;
  border-right: 1px solid var(--line);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  gap: 20px;
  z-index: 40;
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 6px;
}

.brand strong {
  display: block;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.brand small {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--primary-ink);
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-sm);
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-item {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: left;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  transition: background 140ms ease, color 140ms ease;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--ink);
}

.nav-item.active {
  color: var(--primary-ink);
  background: var(--primary);
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .nav-item.active {
  color: var(--primary-ink);
}

.app-shell {
  margin-left: var(--sidebar-w);
  padding: 20px 28px 60px;
  position: relative;
  z-index: 1;
}

/* =============================
   Topbar
   ============================= */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
  min-height: var(--topbar-h);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-left > div { min-width: 0; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.7rem;
  font-weight: 700;
}

.user-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  background: var(--panel);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Ícone de menu (hambúrguer) — só visível no mobile */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.icon-btn:hover { background: var(--bg-hover); border-color: var(--line-strong); }

.icon-btn svg { width: 20px; height: 20px; }

.menu-toggle { display: none; }

/* Overlay para quando o drawer está aberto no mobile */
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

/* =============================
   Seções / painéis
   ============================= */

.section { display: none; }
.section.active { display: block; }

.panel,
.metric-card,
.login-card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

.panel {
  padding: 20px;
  margin-bottom: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.panel-head h2 { line-height: 1.25; }

.panel-head p {
  margin: 4px 0 0;
  font-size: 0.88rem;
}

/* =============================
   Cards do dashboard
   ============================= */

.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric-card {
  padding: 18px;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.metric-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.metric-card span.muted {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.metric-card strong {
  display: block;
  font-size: 2rem;
  line-height: 1.1;
  margin-top: 6px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

/* =============================
   Filtros do dashboard
   ============================= */

.dashboard-filter-panel {
  display: grid;
  grid-template-columns: minmax(220px, 360px) 1fr;
  gap: 12px;
  align-items: start;
  margin-bottom: 16px;
}

.dashboard-filter { max-width: 460px; }

.dashboard-status-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px;
  background: var(--panel-muted);
}

.dashboard-status-filter legend {
  padding: 0 6px;
  color: var(--muted-strong);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.dashboard-status-filter label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}

.dashboard-status-filter input { width: auto; }

/* =============================
   Formulários / inputs
   ============================= */

label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--muted-strong);
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--ink);
  background: var(--bg-elev);
  outline: none;
  font-weight: 500;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

input::placeholder, textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}

input:hover, textarea:hover, select:hover { border-color: var(--line-strong); }

input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

textarea { resize: vertical; }

input[type="checkbox"], input[type="radio"] {
  width: auto;
  accent-color: var(--primary);
}

input[type="file"] {
  padding: 8px;
  background: var(--panel-muted);
  cursor: pointer;
}

.search {
  padding-left: 14px;
  background: var(--bg-elev);
}

/* =============================
   Botões
   ============================= */

.btn {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  color: var(--ink);
  background: var(--bg-elev);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease, box-shadow 120ms ease;
  white-space: nowrap;
}

.btn:hover { background: var(--bg-hover); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }

.btn.primary {
  color: var(--primary-ink);
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.btn.primary:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

[data-theme="dark"] .btn.primary {
  color: var(--primary-ink);
}

.btn.danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: transparent;
}

.btn.danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn.ghost {
  margin-top: auto;
  background: transparent;
  border-color: var(--line);
  color: var(--muted-strong);
}

.btn.ghost:hover {
  background: var(--bg-hover);
  color: var(--ink);
}

.form-title-row .btn.ghost { margin-top: 0; }

.btn.compact {
  padding: 6px 10px;
  font-size: 0.82rem;
  border-radius: var(--radius-xs);
}

/* =============================
   Form geral
   ============================= */

.form-stack {
  display: grid;
  gap: 14px;
}

.agenda-form {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.agenda-form h2 { grid-column: 1 / -1; }

.form-title-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compact-row { align-items: flex-start; }
.compact-row h3 { margin: 0; }
.compact-row p { margin: 4px 0 0; font-size: 0.85rem; }

.hint { color: var(--muted); font-size: 0.78rem; font-weight: 500; }

.muted { color: var(--muted); font-weight: 500; }

/* Toolbars no topo de cada seção */
.agenda-toolbar,
.medication-toolbar,
.patient-toolbar,
.notification-toolbar {
  align-items: flex-start;
}

.agenda-filter,
.medication-filter {
  max-width: 460px;
  margin-bottom: 14px;
}

/* =============================
   Data grids (pacientes / medicamentos / notificações)
   ============================= */

.patients-grid,
.medications-grid,
.notification-types-list {
  margin-top: 12px;
  overflow-x: auto;
}

.data-grid {
  min-width: 760px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--panel);
}

.patient-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(160px, 1fr) minmax(180px, 1fr) minmax(180px, 1fr) minmax(120px, 0.7fr) minmax(180px, auto);
}

.medication-grid {
  display: grid;
  grid-template-columns: 90px minmax(180px, 1.1fr) minmax(170px, 1fr) minmax(260px, 1.6fr) minmax(180px, auto);
}

.notification-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(140px, 0.7fr) minmax(320px, 2fr) minmax(100px, 0.5fr) minmax(180px, auto);
}

.notification-device-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.1fr) minmax(180px, 1fr) minmax(120px, 0.7fr) minmax(140px, 0.8fr) minmax(140px, 0.8fr) minmax(160px, auto);
}

.data-grid-head,
.data-grid-cell {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}

.data-grid-head {
  color: var(--muted-strong);
  background: var(--panel-muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.data-grid-cell { background: var(--panel); }

.webhook-cell {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.patient-grid .data-grid-cell:nth-last-child(-n + 6),
.medication-grid .data-grid-cell:nth-last-child(-n + 5),
.notification-grid .data-grid-cell:nth-last-child(-n + 5),
.notification-device-grid .data-grid-cell:nth-last-child(-n + 6) {
  border-bottom: 0;
}

.strong-cell { font-weight: 700; color: var(--ink); }

.actions-head, .row-actions { justify-content: flex-end; }

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* =============================
   Agenda cards
   ============================= */

.agenda-list {
  display: grid;
  gap: 10px;
}

.agenda-card {
  display: grid;
  grid-template-columns: minmax(160px, 1.1fr) minmax(150px, 1fr) minmax(100px, 0.7fr) minmax(220px, 1.6fr) minmax(120px, 0.7fr) minmax(150px, 1fr) auto auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  background: var(--panel);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.agenda-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}

.agenda-card strong { display: block; color: var(--ink); font-weight: 700; }

.field-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 3px;
}

/* =============================
   Toggle switch
   ============================= */

.switch-control {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.82rem;
  white-space: nowrap;
  color: var(--muted-strong);
  position: relative;
}

.switch-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background 160ms ease;
  flex: none;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.18);
  transition: transform 160ms ease;
}

.switch-control input:checked + .switch-track {
  background: var(--primary);
}

.switch-control input:checked + .switch-track::after {
  transform: translateX(18px);
}

/* =============================
   Painéis auxiliares (form panels)
   ============================= */

.patient-form-panel,
.medication-form-panel,
.agenda-form-panel,
.agenda-renew-panel {
  margin-top: 14px;
}

.device-assignment-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(140px, 0.55fr);
  gap: 12px;
  align-items: end;
}

.patient-identity-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1.2fr) minmax(220px, 0.85fr);
  gap: 12px;
  align-items: start;
}

.patient-tag-preview {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-muted);
  min-height: 60px;
  display: flex;
  align-items: center;
}

.patient-tag-preview-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35), 0 6px 14px rgba(0, 0, 0, 0.06);
}

.patient-row-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.patient-color-chip {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.patient-tag-color-sage { background: #edf5ef; color: #2e6f4e; }
.patient-tag-color-sky { background: #e9f3fb; color: #2f6787; }
.patient-tag-color-peach { background: #fdf0e7; color: #a25d3f; }
.patient-tag-color-lavender { background: #f2ecfb; color: #6d56a6; }
.patient-tag-color-rose { background: #fbecef; color: #a14b62; }
.patient-tag-color-sand { background: #f5efe4; color: #8a6a3d; }
.patient-tag-color-mint { background: #e8f7f1; color: #29745f; }
.patient-tag-color-slate { background: #edf1f4; color: #506271; }

.toggle-field {
  display: grid;
  gap: 8px;
  font-weight: 600;
  color: var(--muted-strong);
}

.toggle-field input {
  width: 20px;
  height: 20px;
}

/* =============================
   Notification chain editor
   ============================= */

.notification-chain-editor {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-muted);
}

.notification-steps { display: grid; gap: 8px; }

.notification-step-row {
  display: grid;
  grid-template-columns: 44px minmax(120px, 0.8fr) minmax(150px, 1fr) minmax(150px, 1fr) minmax(120px, 0.7fr) auto auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.step-order {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-xs);
  color: var(--primary-ink);
  background: var(--primary);
  font-weight: 800;
  font-size: 0.88rem;
}

.step-move-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* =============================
   Modal (notificações)
   ============================= */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(6px);
}

.notification-modal {
  width: min(100%, 760px);
  max-height: min(90vh, 860px);
  overflow: auto;
  box-shadow: var(--shadow-lg);
}

/* =============================
   JSON editor
   ============================= */

.edit-json-textarea {
  min-height: 280px;
  font-family: "JetBrains Mono", "Noto Sans Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

.json-fallback-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #0f172a;
  overflow: hidden;
}

.json-fallback-highlight {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 12px 14px;
  font-family: "JetBrains Mono", "Noto Sans Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #d8dee9;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow: hidden;
  pointer-events: none;
}

textarea.json-fallback-input {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  margin: 0;
  min-height: 280px;
  background: transparent;
  color: transparent;
  caret-color: #f8f8f2;
  font-family: "JetBrains Mono", "Noto Sans Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  resize: vertical;
  box-sizing: border-box;
}

textarea.json-fallback-input:focus { box-shadow: none; }

textarea.json-fallback-input::selection {
  background: rgba(96, 165, 250, 0.28);
}

.json-token.json-key { color: #79b8ff; }
.json-token.json-string { color: #9ecbff; }
.json-token.json-number { color: #f6a875; }
.json-token.json-boolean { color: #ffab70; }
.json-token.json-null { color: #c9d1d9; }

body.sali-admin-theme .json-fallback-wrap {
  background: #0f172a;
  border-color: #203244;
}

body.sali-admin-theme .json-fallback-highlight {
  color: #d8dee9;
}

body.sali-admin-theme textarea.json-fallback-input,
body.sali-admin-theme textarea.json-fallback-input:hover,
body.sali-admin-theme textarea.json-fallback-input:focus {
  background: transparent;
  color: transparent;
  caret-color: #f8f8f2;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

/* =============================
   Test notification box
   ============================= */

.test-notification-box {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-muted);
}

.test-notification-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
}

.notification-logs-summary {
  margin: 10px 0 14px;
}

.notification-logs-list {
  margin-top: 12px;
  overflow-x: auto;
}

.notification-log-grid {
  display: grid;
  grid-template-columns:
    minmax(140px, 0.9fr)
    minmax(170px, 1fr)
    minmax(180px, 1fr)
    minmax(120px, 0.8fr)
    minmax(180px, 1fr)
    minmax(140px, 0.9fr)
    minmax(220px, 1.2fr);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.status-sent {
  background: var(--success-soft);
  color: var(--success);
}

.status-pending {
  background: #fff7ea;
  color: #9a6b2b;
}

.status-info {
  background: #edf4f8;
  color: #4a697d;
}

.status-failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.log-error-text {
  color: var(--danger);
  font-size: 0.88rem;
  line-height: 1.45;
}

.notification-log-grid .data-grid-cell:nth-last-child(-n + 7) {
  border-bottom: 0;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* =============================
   Lista de lembretes
   ============================= */

.list { display: grid; gap: 10px; }

.list-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  background: var(--panel);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.list-item:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}

.list-item strong {
  display: block;
  color: var(--ink);
  font-weight: 700;
  margin-bottom: 2px;
}

.list-item .muted { font-size: 0.85rem; }

.late-reminder {
  border-color: var(--danger);
  background: var(--danger-soft);
  box-shadow: 0 0 0 1px var(--danger) inset;
}

[data-theme="dark"] .late-reminder {
  box-shadow: none;
}

.taken-reminder {
  opacity: 0.7;
  border-color: var(--line);
  background: var(--panel-muted);
}

.taken-reminder strong,
.taken-reminder p,
.taken-reminder .muted {
  color: var(--muted);
}

.late-alert {
  display: inline-flex;
  width: fit-content;
  margin-top: 6px;
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  font-size: 0.78rem;
  font-weight: 700;
}

[data-theme="dark"] .late-alert {
  border-color: transparent;
}

/* =============================
   Imagem do medicamento
   ============================= */

.medication-thumb,
.image-preview {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-muted);
  object-fit: cover;
}

.medication-thumb { width: 76px; height: 76px; }

.medication-thumb.small {
  width: 54px;
  height: 54px;
  border-radius: var(--radius-xs);
}

.medication-thumb.placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  text-transform: uppercase;
}

.image-preview {
  width: 100%;
  max-width: 220px;
  height: 150px;
}

/* =============================
   Toast / erro
   ============================= */

.toast, .error {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
  font-weight: 600;
  font-size: 0.88rem;
}

[data-theme="dark"] .toast,
[data-theme="dark"] .error {
  border-color: transparent;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  box-shadow: var(--shadow-lg);
  z-index: 80;
  max-width: min(420px, calc(100vw - 32px));
}

.token-result {
  margin-bottom: 14px;
}

.token-result-box {
  border: 1px solid var(--primary);
  background: var(--primary-soft);
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 16px;
  display: grid;
  gap: 8px;
}

.token-result-box code {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px dashed var(--line-strong);
  padding: 12px 14px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  color: var(--ink);
}

.device-pairing-spotlight {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid color-mix(in srgb, var(--primary) 26%, transparent);
  background: color-mix(in srgb, var(--primary-soft) 70%, white);
  color: var(--ink);
  border-radius: var(--radius-lg);
}

.device-pairing-spotlight-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.device-pairing-code-box {
  display: grid;
  gap: 8px;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--panel);
}

.device-pairing-code-box small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.device-pairing-code-box code {
  display: block;
  font-family: "JetBrains Mono", monospace;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--primary-strong);
}

.device-pairing-helper {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--line-strong);
  background: rgba(255, 255, 255, 0.7);
}

.device-pairing-helper ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  display: grid;
  gap: 4px;
}

.notification-device-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.notification-device-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.notification-device-card.is-paired {
  border-color: color-mix(in srgb, var(--primary) 26%, var(--line));
}

.notification-device-card.is-pending {
  border-color: rgba(197, 139, 62, 0.24);
}

.notification-device-card.is-revoked {
  border-color: rgba(184, 87, 87, 0.22);
  background: color-mix(in srgb, var(--danger-soft) 22%, white);
}

.notification-device-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.notification-device-card-head strong {
  display: block;
  font-size: 1rem;
  color: var(--ink);
  margin-bottom: 4px;
}

.notification-device-card-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.notification-device-card-body > div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--panel-muted);
}

.notification-device-card-body strong {
  color: var(--ink);
  font-size: 0.94rem;
  line-height: 1.35;
}

.notification-device-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn.warning {
  background: #fff7ea;
  color: #9a6b2b;
  border-color: rgba(197, 139, 62, 0.24);
}

@media (max-width: 920px) {
  .device-pairing-spotlight-head,
  .notification-device-card-head {
    flex-direction: column;
    align-items: stretch;
  }

  .notification-device-card-body {
    grid-template-columns: 1fr;
  }
}

.hidden { display: none !important; }

/* =============================
   Login
   ============================= */

.login-body {
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(600px 400px at 10% 0%, var(--primary-soft), transparent 60%),
    radial-gradient(500px 400px at 100% 100%, var(--accent-soft), transparent 60%),
    var(--bg);
}

.login-shell {
  width: min(100%, 460px);
}

.login-card {
  padding: 28px;
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  font-size: 1.5rem;
  margin: 6px 0 6px;
}

.login-card > .muted { font-size: 0.9rem; margin-bottom: 18px; }

.bootstrap-box {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.bootstrap-box h2 { font-size: 1rem; margin-bottom: 4px; }

/* =============================
   Responsivo
   ============================= */

/* Até 960px: drawer lateral (hambúrguer) */
@media (max-width: 960px) {
  :root { --topbar-h: 56px; }

  .menu-toggle { display: inline-grid; }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    width: min(320px, 85vw);
  }

  body.drawer-open .sidebar { transform: translateX(0); }
  body.drawer-open .drawer-backdrop { display: block; }

  .app-shell {
    margin-left: 0;
    padding: 16px 16px 80px;
  }

  .topbar {
    margin-bottom: 18px;
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 10px 0;
    background: linear-gradient(var(--bg) 70%, transparent);
    backdrop-filter: blur(6px);
  }

  .cards-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .metric-card { padding: 14px; }
  .metric-card strong { font-size: 1.6rem; }

  .dashboard-filter-panel {
    grid-template-columns: 1fr;
  }

  .agenda-form { grid-template-columns: 1fr; }

  .patient-identity-grid,
  .device-assignment-grid {
    grid-template-columns: 1fr;
  }

  .notification-step-row {
    grid-template-columns: 44px 1fr;
    grid-auto-rows: auto;
  }

  .notification-step-row > label { grid-column: 2 / 3; }
  .notification-step-row > .step-order { grid-row: 1 / span 2; }
  .notification-step-row > .step-move-actions,
  .notification-step-row > .btn { grid-column: 2 / 3; justify-self: start; }

  .test-notification-box { grid-template-columns: 1fr; }

  /* Agenda vira stack e cada campo ganha label visual */
  .agenda-card {
    grid-template-columns: 1fr 1fr;
    gap: 10px 14px;
    padding: 14px;
  }

  .agenda-card > .switch-control {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .agenda-card > .btn { grid-column: 1 / -1; }

  .panel { padding: 16px; border-radius: var(--radius-lg); }

  h1 { font-size: 1.25rem; }
}

/* Até 640px: 1 coluna nos grids e cards */
@media (max-width: 640px) {
  .cards-grid { grid-template-columns: 1fr; }

  .panel-head,
  .agenda-toolbar,
  .medication-toolbar,
  .patient-toolbar,
  .notification-toolbar,
  .form-title-row {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-head > .btn,
  .form-title-row > .btn,
  .panel-head > div + .btn {
    width: 100%;
  }

  .agenda-card { grid-template-columns: 1fr; }

  .topbar-right .user-pill { display: none; }

  .btn { padding: 10px 14px; font-size: 0.9rem; }
  .btn.compact { padding: 7px 10px; font-size: 0.82rem; }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
  }
}

/* Touch devices: aumenta área tocável */
@media (hover: none) and (pointer: coarse) {
  .btn { min-height: 40px; }
  .nav-item { padding: 12px 14px; }
  input, textarea, select { font-size: 16px; } /* evita zoom no iOS */
}

/* =========================================================================
   Sali-IA admin visual refresh
   ========================================================================= */

body.sali-admin-theme {
  --bg: #f6f2ea;
  --bg-elev: rgba(255, 255, 255, 0.76);
  --bg-subtle: #f9f5ee;
  --bg-hover: #f1eadf;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-muted: #faf7f1;

  --ink: #31513f;
  --ink-soft: #4a4a4a;
  --muted: #75847a;
  --muted-strong: #627167;
  --line: rgba(95, 175, 122, 0.12);
  --line-strong: rgba(95, 175, 122, 0.22);

  --primary: #5faf7a;
  --primary-strong: #2e6f4e;
  --primary-soft: #edf5ef;
  --primary-ink: #ffffff;

  --accent: #7fb995;
  --accent-soft: #dbe9dd;

  --warn: #b88b43;
  --warn-soft: #f6ead2;

  --danger: #c56b67;
  --danger-soft: #fce6e2;

  --success: #2e6f4e;
  --success-soft: #dcebdd;

  --ring: 0 0 0 3px rgba(95, 175, 122, 0.18);
  --shadow-sm: 0 8px 20px rgba(74, 98, 78, 0.08);
  --shadow-md: 0 18px 40px rgba(63, 100, 77, 0.12);
  --shadow-lg: 0 32px 60px rgba(63, 100, 77, 0.16);
  --sidebar-w: 292px;

  background:
    radial-gradient(900px 420px at -10% -10%, rgba(168, 213, 186, 0.5), transparent 60%),
    radial-gradient(800px 420px at 110% 0%, rgba(236, 228, 212, 0.9), transparent 58%),
    linear-gradient(180deg, #fcf9f2 0%, #f6f2ea 100%);
  color: var(--ink-soft);
  font-family: "Inter", system-ui, sans-serif;
}

body.sali-admin-theme .ambient {
  background:
    radial-gradient(1100px 540px at -10% -10%, rgba(168, 213, 186, 0.42), transparent 60%),
    radial-gradient(900px 520px at 110% -10%, rgba(236, 228, 212, 0.75), transparent 60%);
  opacity: 1;
}

body.sali-admin-theme h1,
body.sali-admin-theme h2,
body.sali-admin-theme h3,
body.sali-admin-theme h4,
body.sali-admin-theme .brand strong,
body.sali-admin-theme .btn,
body.sali-admin-theme .nav-item {
  font-family: "Nunito", "Inter", system-ui, sans-serif;
}

body.sali-admin-theme .sidebar {
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(10px);
  border-right: 1px solid var(--line);
  padding: 22px 18px;
  gap: 22px;
}

body.sali-admin-theme .brand {
  padding: 6px 8px;
  align-items: center;
  gap: 14px;
}

body.sali-admin-theme .brand-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  flex-shrink: 0;
}

body.sali-admin-theme .brand strong {
  font-size: 1.1rem;
  color: var(--primary-strong);
}

body.sali-admin-theme .brand small,
body.sali-admin-theme .muted {
  color: var(--muted);
}

body.sali-admin-theme .brand-mark {
  display: none;
}

body.sali-admin-theme .nav {
  gap: 6px;
}

body.sali-admin-theme .nav-item {
  min-height: 46px;
  border-radius: 16px;
  padding: 0 14px;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 700;
}

body.sali-admin-theme .nav-item:hover {
  background: rgba(95, 175, 122, 0.08);
  color: var(--primary-strong);
}

body.sali-admin-theme .nav-item.active {
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  color: var(--primary-ink);
  box-shadow: 0 10px 20px rgba(95, 175, 122, 0.24);
}

body.sali-admin-theme .app-shell {
  padding: 24px 28px 48px;
}

body.sali-admin-theme .topbar {
  margin-bottom: 22px;
}

body.sali-admin-theme .eyebrow {
  color: var(--primary);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
}

body.sali-admin-theme h1 {
  color: var(--ink);
  font-size: 2rem;
}

body.sali-admin-theme .user-pill,
body.sali-admin-theme .icon-btn {
  background: rgba(255, 255, 255, 0.94);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
  color: var(--primary-strong);
}

body.sali-admin-theme .panel,
body.sali-admin-theme .metric-card,
body.sali-admin-theme .list-item,
body.sali-admin-theme .agenda-card,
body.sali-admin-theme .patient-card,
body.sali-admin-theme .medication-card,
body.sali-admin-theme .notification-type-card,
body.sali-admin-theme .data-grid-cell {
  background: var(--panel);
  border: 1px solid rgba(95, 175, 122, 0.06);
  box-shadow: var(--shadow-sm);
}

body.sali-admin-theme .panel {
  border-radius: 26px;
  box-shadow: var(--shadow-md);
}

body.sali-admin-theme .panel-head h2 {
  color: var(--ink);
  font-size: 1.35rem;
}

body.sali-admin-theme .cards-grid {
  gap: 14px;
}

body.sali-admin-theme .metric-card {
  border-radius: 24px;
  padding: 20px;
}

body.sali-admin-theme .metric-card strong {
  color: var(--ink);
  font-size: 2rem;
}

body.sali-admin-theme .metric-card span.muted {
  color: var(--muted);
}

body.sali-admin-theme .dashboard-filter-panel,
body.sali-admin-theme .dashboard-status-filter,
body.sali-admin-theme .search,
body.sali-admin-theme input,
body.sali-admin-theme textarea,
body.sali-admin-theme select {
  background: var(--panel-muted);
  border-color: var(--line);
}

body.sali-admin-theme input,
body.sali-admin-theme textarea,
body.sali-admin-theme select,
body.sali-admin-theme .search {
  border-radius: 16px;
}

body.sali-admin-theme input:focus,
body.sali-admin-theme textarea:focus,
body.sali-admin-theme select:focus,
body.sali-admin-theme .search:focus {
  box-shadow: var(--ring);
  border-color: rgba(95, 175, 122, 0.28);
}

body.sali-admin-theme .btn {
  border-radius: 999px;
  font-weight: 800;
}

body.sali-admin-theme .btn.primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  color: var(--primary-ink);
  border-color: transparent;
  box-shadow: 0 12px 22px rgba(95, 175, 122, 0.24);
}

body.sali-admin-theme .btn.primary:hover {
  filter: brightness(1.02);
}

body.sali-admin-theme .btn.ghost,
body.sali-admin-theme .btn:not(.primary) {
  background: rgba(255, 255, 255, 0.94);
  border-color: var(--line);
  color: var(--primary-strong);
}

body.sali-admin-theme .agenda-card,
body.sali-admin-theme .patient-card,
body.sali-admin-theme .medication-card,
body.sali-admin-theme .notification-type-card,
body.sali-admin-theme .list-item {
  border-radius: 22px;
}

body.sali-admin-theme .toast {
  border-radius: 16px;
  border-color: transparent;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  box-shadow: var(--shadow-md);
}

body.sali-admin-theme .toast.success {
  box-shadow: 0 16px 30px rgba(95, 175, 122, 0.18);
}

body.sali-admin-theme .toast.error {
  box-shadow: 0 16px 30px rgba(197, 107, 103, 0.18);
}

@media (max-width: 960px) {
  body.sali-admin-theme .sidebar {
    width: min(320px, 88vw);
  }

  body.sali-admin-theme .app-shell {
    padding: 16px 16px 42px;
  }

  body.sali-admin-theme .topbar {
    background: linear-gradient(rgba(246, 242, 234, 0.92) 70%, transparent);
  }
}

body.sali-admin-theme.login-body {
  background:
    radial-gradient(700px 420px at 8% 0%, rgba(168, 213, 186, 0.6), transparent 56%),
    radial-gradient(560px 420px at 100% 100%, rgba(236, 228, 212, 0.92), transparent 58%),
    linear-gradient(180deg, #fcf9f2 0%, #f6f2ea 100%);
}

body.sali-admin-theme .login-shell {
  width: min(100%, 520px);
}

body.sali-admin-theme .login-card {
  padding: 30px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(95, 175, 122, 0.08);
  box-shadow: var(--shadow-lg);
}

body.sali-admin-theme .login-brand {
  gap: 16px;
  padding: 0;
}

body.sali-admin-theme .login-brand-logo {
  width: 86px;
  height: 86px;
  object-fit: contain;
  flex-shrink: 0;
}

body.sali-admin-theme .login-card h1 {
  font-family: "Nunito", "Inter", system-ui, sans-serif;
  font-size: 2rem;
  line-height: 1.05;
  color: var(--ink);
  margin: 8px 0 10px;
}

body.sali-admin-theme .login-card > .muted {
  font-size: 0.98rem;
  line-height: 1.55;
  margin-bottom: 18px;
}

body.sali-admin-theme .bootstrap-box {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid rgba(95, 175, 122, 0.12);
}

body.sali-admin-theme .bootstrap-box h2 {
  font-family: "Nunito", "Inter", system-ui, sans-serif;
  font-size: 1.15rem;
  color: var(--ink);
}

@media (max-width: 640px) {
  body.sali-admin-theme .login-card {
    padding: 22px;
  }

  body.sali-admin-theme .login-brand-logo {
    width: 74px;
    height: 74px;
  }

  body.sali-admin-theme .login-card h1 {
    font-size: 1.75rem;
  }
}
