:root {
  --bg: #eef3ff;
  --bg-soft: #f5f8ff;
  --sidebar: #0a1626;
  --sidebar-hover: #132338;
  --card: #ffffff;
  --text: #0a1626;
  --muted: #5b6b86;
  --line: #d7e0f2;
  --brand: #2f6bff;
  --brand-dark: #1f4fd6;
  --brand-soft: #dbe7ff;
  --accent: #2f6bff;
  --accent-ink: #ffffff;
  --danger: #e11d48;
  --ok: #16a34a;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(10, 22, 38, 0.08);
  --font: "Outfit", system-ui, sans-serif;
  --display: "Syne", "Outfit", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

/* ——— Login ——— */
html:has(body.login-page) {
  background: #2f6bff;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.18), transparent 36%),
    radial-gradient(circle at 85% 75%, rgba(20, 60, 180, 0.45), transparent 42%),
    linear-gradient(160deg, #2563eb 0%, #2f6bff 50%, #1d4ed8 100%) !important;
}

.login-card {
  width: min(420px, 100%);
  background: rgba(255, 255, 255, 0.96);
  border-radius: 28px;
  padding: 36px 32px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  animation: rise 0.45s ease both;
}

.login-brand {
  display: grid;
  gap: 10px;
  justify-items: center;
  margin-bottom: 28px;
  text-align: center;
}

.login-brand img {
  width: min(260px, 100%);
  height: auto;
}

.login-brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.form-stack {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(47, 107, 255, 0.15);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.chip:hover {
  border-color: var(--brand);
}

.chip.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.modal-lg {
  width: min(560px, 100%);
}

.toolbar-search {
  margin-bottom: 14px;
}

.agenda-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.agenda-toolbar input[type="date"] {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 10px 12px;
}

.agenda-list {
  display: grid;
  gap: 12px;
}

.agenda-card {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.agenda-card.status-cancelado {
  opacity: 0.65;
}

.agenda-card-time {
  display: grid;
  gap: 2px;
  text-align: center;
}

.agenda-card-time strong {
  font-size: 1.15rem;
  color: var(--brand);
}

.agenda-card-time small {
  color: var(--muted);
}

.agenda-card-body p {
  margin: 4px 0 8px;
  color: var(--muted);
}

.agenda-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.seg-control {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-soft);
}

.seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--brand);
  color: #fff;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.cal-head {
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 4px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cal-cell {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.cal-cell:hover {
  border-color: var(--brand);
  transform: translateY(-1px);
}

.cal-cell.empty-cell {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
  min-height: 48px;
  background: transparent;
  border-color: transparent;
}

.cal-cell.is-today {
  border-color: var(--brand);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.cal-cell.has-items {
  background: color-mix(in srgb, var(--brand) 8%, var(--card));
}

.cal-day {
  font-weight: 700;
}

.cal-count {
  margin-top: auto;
  font-size: 0.78rem;
  color: var(--brand);
  font-weight: 600;
}

.cal-count.muted {
  color: var(--muted);
  font-weight: 400;
}

@media (max-width: 900px) {
  .cal-cell {
    min-height: 56px;
    padding: 6px;
  }
}

.hint-vars {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
}

.hint-vars code {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px 6px;
  font-size: 0.85em;
}

.msg-preview {
  max-width: 420px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.var-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--brand);
  border-radius: 999px;
  padding: 4px 10px;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--brand);
}

.wa-preview {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  min-height: 120px;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.45;
}

.horario-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.horario-day {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.horario-times {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.horario-times input[type="time"] {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 8px 10px;
}

.horario-times input[type="time"]:disabled {
  opacity: 0.45;
}

@media (max-width: 900px) {
  .agenda-card {
    grid-template-columns: 64px 1fr;
  }

  .agenda-card-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .agenda-card-actions .btn {
    flex: 1;
  }

  .horario-row {
    grid-template-columns: 1fr;
  }
}

.toolbar-search input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}

.toolbar-search input:focus {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(47, 107, 255, 0.15);
}

.select-with-action {
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 8px;
  align-items: stretch;
}

.select-with-action select {
  width: 100%;
}

.btn-icon {
  min-width: 48px;
  padding-left: 0;
  padding-right: 0;
  font-size: 1.35rem;
  line-height: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-dark);
}

.btn-accent {
  background: var(--brand);
  color: #fff;
}

.btn-accent:hover {
  background: var(--brand-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.btn-danger {
  background: #fff1f2;
  color: var(--danger);
}

.btn-block {
  width: 100%;
}

.alert {
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.alert-error {
  background: #fff1f2;
  color: #be123c;
}

.alert-ok {
  background: #ecfdf5;
  color: #047857;
}

.alert[hidden] {
  display: none;
}

/* ——— App shell ——— */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px 1fr;
}

.sidebar {
  background: var(--sidebar);
  color: #d7dbe3;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 18px 14px 16px;
  gap: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 4px;
}

.sidebar-name {
  font-family: var(--display);
  font-size: 1.05rem;
  letter-spacing: -0.03em;
  color: #fff;
  line-height: 1.1;
}

.sidebar-logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: 0 0 0 2px rgba(47, 107, 255, 0.45);
}

.sidebar-logo img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  width: 100%;
  flex: 1;
  align-content: start;
}

.nav-btn {
  width: 100%;
  border: 0;
  background: transparent;
  color: #c5cedd;
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-btn svg {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}

.nav-btn span {
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.nav-logout {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-btn:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-btn.active {
  background: var(--brand);
  color: #fff;
}

.main {
  padding: 28px 32px 40px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.8rem, 2.4vw, 2.4rem);
  letter-spacing: -0.03em;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: 999px;
  padding: 8px 12px 8px 8px;
  box-shadow: var(--shadow);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.user-meta {
  display: grid;
  line-height: 1.2;
}

.user-meta strong {
  font-size: 0.92rem;
}

.user-meta span {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  animation: rise 0.4s ease both;
}

.stat-card:nth-child(2) {
  background: var(--brand);
  color: #fff;
}

.stat-card:nth-child(3) {
  background: var(--sidebar);
  color: #fff;
}

.stat-label {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  margin: 10px 0 0;
  font-family: var(--display);
  font-size: 2.2rem;
  letter-spacing: -0.03em;
}

.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  animation: rise 0.45s ease both;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
}

.table-wrap {
  overflow-x: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
}

table.data th,
table.data td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
  vertical-align: middle;
}

table.data th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-root {
  background: var(--sidebar);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(47, 107, 255, 0.5);
}

.badge-admin {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge-on {
  background: #dcfce7;
  color: #166534;
}

.badge-off {
  background: #fee2e2;
  color: #991b1b;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.row-actions .btn {
  padding: 8px 10px;
  font-size: 0.8rem;
  border-radius: 10px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
}

.view[hidden] {
  display: none !important;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 40;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(480px, 100%);
  background: #fff;
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.25);
  animation: rise 0.25s ease both;
}

.modal h3 {
  margin: 0 0 14px;
  font-family: var(--display);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.coming-soon {
  display: grid;
  gap: 8px;
}

.coming-soon ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ——— Toasts ——— */
.toast-root {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: 16px;
  left: auto;
  z-index: 99999;
  display: grid;
  gap: 10px;
  pointer-events: none;
  width: min(380px, calc(100vw - 32px));
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 14px;
  color: #fff;
  box-shadow: 0 14px 36px rgba(10, 22, 38, 0.28);
  opacity: 0;
  transform: translateY(-10px) scale(0.98);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast.toast-in {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast.toast-out {
  opacity: 0;
  transform: translateY(-10px) scale(0.98);
}

.toast-msg {
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.35;
}

.toast-close {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
  padding: 0;
}

.toast-success {
  background: linear-gradient(135deg, #16a34a, #15803d);
}

.toast-error {
  background: linear-gradient(135deg, #e11d48, #be123c);
}

.toast-info {
  background: linear-gradient(135deg, #2f6bff, #1f4fd6);
}

@media (max-width: 900px) {
  .nav-desktop-only {
    display: none !important;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .app-shell {
    display: block;
    min-height: 100dvh;
    background: var(--bg);
  }

  .sidebar {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    flex-direction: row !important;
    align-items: stretch !important;
    justify-content: stretch !important;
    gap: 0 !important;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    z-index: 50;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    background: #0a1626;
    box-shadow: 0 -10px 28px rgba(10, 22, 38, 0.28);
  }

  .sidebar-brand {
    display: none !important;
  }

  .nav-list {
    display: flex !important;
    flex-direction: row !important;
    align-items: stretch;
    justify-content: space-between;
    gap: 4px;
    width: 100%;
    flex: 1;
    align-content: stretch;
  }

  .nav-list li,
  .nav-logout {
    flex: 1 1 0;
    min-width: 0;
    margin-top: 0 !important;
  }

  .nav-btn {
    width: 100%;
    min-height: 58px;
    padding: 6px 2px;
    border-radius: 12px;
    gap: 3px;
    flex-direction: column;
    justify-content: center;
  }

  .nav-logout {
    padding-top: 0;
    border-top: 0;
  }

  .nav-btn svg {
    width: 18px;
    height: 18px;
  }

  .nav-btn span {
    display: block !important;
    font-size: 0.6rem;
    letter-spacing: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .nav-btn.active {
    background: var(--brand);
    color: #fff;
    box-shadow: 0 4px 14px rgba(47, 107, 255, 0.35);
  }

  .main {
    width: 100%;
    min-height: 100dvh;
    padding: 16px 14px calc(96px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
  }

  .topbar {
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
  }

  .topbar h1 {
    font-size: 1.45rem;
  }

  .topbar .btn {
    width: 100%;
  }

  .user-chip {
    width: 100%;
    justify-content: flex-start;
  }

  .stats {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .stat-card {
    padding: 16px;
  }

  .stat-value {
    font-size: 1.8rem;
  }

  .panel {
    border-radius: 16px;
    padding: 14px;
  }

  .table-wrap {
    margin: 0 -4px;
  }

  .modal-backdrop {
    place-items: end stretch;
    padding: 0;
  }

  .modal,
  .modal-lg {
    width: 100%;
    max-width: none;
    max-height: min(92dvh, 920px);
    overflow: auto;
    border-radius: 22px 22px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  }

  .toast-root {
    top: auto;
    bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    right: 12px;
    left: 12px;
    width: auto;
    margin: 0;
  }

  table.data th,
  table.data td {
    padding: 10px 8px;
    font-size: 0.85rem;
  }

  .row-actions {
    flex-direction: column;
  }

  .row-actions .btn {
    width: 100%;
  }
}

/* PWA standalone (instalado como app) */
@media (display-mode: standalone) {
  body {
    -webkit-user-select: none;
    user-select: none;
    overscroll-behavior-y: none;
  }

  input,
  textarea,
  select {
    -webkit-user-select: text;
    user-select: text;
  }

  .login-page {
    padding-top: env(safe-area-inset-top, 0px);
  }
}
