/* Tá na Porta — admin panel. Inherits the courier design language from
 * app.css (Inter, palette, radii, shadows, class-based dark mode, entrance
 * animations); this file adds the panel chrome and desktop-density pieces. */

.panel-main {
  max-width: 1040px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-12);
  animation: fadeIn 0.15s ease-out;
}

/* ── Top bar ──────────────────────────────────────────────────────────── */
.panel-top {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
html.dark .panel-top {
  background: #111827;
}
.panel-brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.panel-brand .brand-logo {
  height: 26px;
  width: auto;
}
.panel-nav {
  display: flex;
  gap: var(--space-4);
  flex: 1;
}
.panel-nav a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  transition: color 0.15s;
}
.panel-nav a:hover {
  color: var(--primary);
}
.panel-logout {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0;
}
.panel-user {
  color: var(--muted);
  font-size: 0.875rem;
}
.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: color 0.15s;
}
.btn-link:hover {
  color: var(--primary-hover);
}

/* ── Panel-density buttons (auto width, not the mobile full-width) ────── */
.panel .btn-primary {
  display: inline-flex;
  width: auto;
  padding: var(--space-3) var(--space-5);
  font-size: 0.875rem;
}
.panel .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-5);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s;
  cursor: pointer;
}
.panel .btn-ghost {
  border: 1px solid var(--primary);
  color: var(--primary);
  background: transparent;
}
.panel .btn-ghost:hover {
  background: var(--primary);
  color: #ffffff;
}

/* ── Forms ────────────────────────────────────────────────────────────── */
.panel .input {
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--input-bg);
  padding: var(--space-2) var(--space-3);
  color: var(--text);
  font-size: 0.9rem;
}
.panel .input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 1px var(--primary);
}
.panel .input::placeholder {
  color: var(--muted-2);
}
.panel .field {
  margin-bottom: var(--space-4);
}
.panel .field label {
  margin-bottom: var(--space-1);
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-3);
}
.panel .field .input {
  width: 100%;
}
.field-error {
  border-radius: var(--radius);
  border: 1px solid var(--red-border);
  background: var(--red-bg);
  color: var(--red-text);
  padding: var(--space-3) var(--space-4);
  font-size: 0.875rem;
  margin-bottom: var(--space-4);
}
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-top: var(--space-3);
}
.inline-form .input {
  flex: 1;
  min-width: 8rem;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.875rem;
  color: var(--text-2);
}

.muted {
  color: var(--muted);
}

/* ── Login card ───────────────────────────────────────────────────────── */
.login-card {
  max-width: 24rem;
  margin: 10vh auto 0;
  padding: var(--space-7);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  animation: scaleIn 0.15s ease-out;
}
html.dark .login-card {
  background: #111827;
}
.login-card h1 {
  margin: 0 0 var(--space-1);
  font-size: 1.5rem;
}
.login-card > .muted {
  margin-bottom: var(--space-4);
}
.login-card form {
  /* Flex gap does not margin-collapse — spacing here is what it says. */
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.login-card form .field {
  margin-bottom: 0;
}
.login-card .btn-primary {
  width: 100%;
  display: flex;
  /* gap (--space-4) + this = --space-7, matching the card padding. */
  margin-top: var(--space-3);
}
.login-logo {
  margin: var(--space-1) 0 var(--space-5);
  display: flex;
  justify-content: center;
}
.login-logo .brand-logo {
  height: 58px; /* 48px + 20%, rounded to the pixel */
  width: auto;
}

/* ── Dashboard cards ──────────────────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-5);
}
.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
}
html.dark .card {
  background: #111827;
}
.card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}
.card-title {
  font-weight: 700;
}
.card-text {
  color: var(--muted);
  font-size: 0.875rem;
}

/* ── Tables ───────────────────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: var(--space-4);
}
.table th,
.table td {
  text-align: left;
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.9rem;
}
.table th {
  color: var(--muted);
  font-weight: 600;
}
.table tr:hover td {
  background: var(--surface-2);
}
html.dark .table tr:hover td {
  background: #111827;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}
.badge {
  display: inline-block;
  padding: var(--space-1) var(--space-2);
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.2;
}
.badge-ok {
  background: var(--green-icon-bg);
  color: var(--green-title);
}
.badge-pending {
  background: var(--amber-bg);
  color: var(--amber-icon);
}

/* Card children are spaced by the flex gap alone: the global reset zeroes
 * paragraph margins, so without the gap card content sits line-on-line. */
.pause-box {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin: var(--space-4) 0 var(--space-6);
}
html.dark .pause-box {
  background: #111827;
}
.pause-box h2 {
  margin: 0;
  font-size: 1.05rem;
}
.pause-box .hint,
.pause-box .inline-form {
  margin: 0;
}

/* Panel headings breathe a little. Section headings only: scoping to direct
 * children of the page body keeps the margin out of cards — `.panel h2` would
 * tie with `.pause-box h2` on specificity and win by source order. */
.panel h1 {
  font-size: 1.5rem;
  margin: var(--space-2) 0;
}
.panel-main > h2 {
  font-size: 1.125rem;
  margin: var(--space-6) 0 var(--space-1);
}

/* Theme toggle in the top bar. */
.panel-top .theme-toggle {
  margin-left: calc(-1 * var(--space-1));
}

/* ── Feedback banners ─────────────────────────────────────────────────── */
.banner {
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  font-size: 0.875rem;
  font-weight: 500;
  margin: var(--space-3) 0;
  animation: bannerIn 0.25s ease-out;
}
.banner-ok {
  border: 1px solid var(--green-border);
  background: var(--green-bg);
  color: var(--green-title);
}
.banner-error {
  border: 1px solid var(--red-border);
  background: var(--red-bg);
  color: var(--red-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.banner-close {
  color: inherit;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 var(--space-1);
  opacity: 0.7;
  transition: opacity 0.15s;
}
.banner-close:hover {
  opacity: 1;
}
@keyframes bannerIn {
  from {
    opacity: 0;
    transform: translateY(-0.375rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Active nav item ──────────────────────────────────────────────────── */
.panel-nav a {
  position: relative;
  padding: var(--space-1) 0;
}
.panel-nav a[aria-current="page"] {
  color: var(--primary);
  font-weight: 600;
}
.panel-nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.7rem;
  height: 2px;
  border-radius: 1px;
  background: var(--primary);
  animation: navUnderline 0.2s ease-out;
}
@keyframes navUnderline {
  from {
    transform: scaleX(0.4);
    opacity: 0;
  }
  to {
    transform: scaleX(1);
    opacity: 1;
  }
}

/* ── Unit tree ────────────────────────────────────────────────────────── */
.tree-cell {
  white-space: nowrap;
}
.tree-branch {
  color: var(--muted-2);
  margin-right: var(--space-2);
  font-size: 0.8rem;
}
.tree-name {
  font-weight: 500;
}
.badge-level {
  background: var(--surface-2);
  color: var(--text-3);
  border: 1px solid var(--border-soft);
}
html.dark .badge-level {
  background: #1f2937;
}
.input-num {
  max-width: 6.5rem;
  flex: 0 1 auto;
}
.hint {
  font-size: 0.8rem;
  margin: var(--space-2) 0 0;
}

/* ── Dashboard stats ──────────────────────────────────────────────────── */
.card-stat {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

/* ── Motion: rows and sections ease in; hovers lift ───────────────────── */
.panel-main > * {
  animation: fadeUp 0.25s ease-out both;
}
.panel-main > *:nth-child(2) {
  animation-delay: 0.03s;
}
.panel-main > *:nth-child(3) {
  animation-delay: 0.06s;
}
.panel-main > *:nth-child(4) {
  animation-delay: 0.09s;
}
.panel-main > *:nth-child(n + 5) {
  animation-delay: 0.12s;
}
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(0.375rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.card:hover {
  transform: translateY(-2px);
}
.card:active {
  transform: translateY(0);
}
.table tbody tr {
  transition: background 0.15s ease;
}
.panel .btn:active,
.panel .btn-primary:active {
  transform: scale(0.98);
}
#parent-select.htmx-added,
#parent-select.htmx-settling {
  animation: fadeUp 0.2s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .panel-main,
  .panel-main > *,
  .banner,
  .panel-nav a[aria-current="page"]::after,
  .login-card,
  #parent-select.htmx-added,
  #parent-select.htmx-settling {
    animation: none;
  }
  .card:hover,
  .card:active,
  .panel .btn:active,
  .panel .btn-primary:active {
    transform: none;
  }
}

/* ── Structure editor: two panes ──────────────────────────────────────── */
[x-cloak] {
  display: none !important;
}
.split {
  display: flex;
  gap: var(--space-5);
  align-items: flex-start;
  margin-top: var(--space-4);
}
.split-side {
  width: 280px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 14rem);
  position: sticky;
  top: 1rem;
}
html.dark .split-side {
  background: #111827;
}
.split-pane {
  flex: 1;
  min-width: 0;
}
.side-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.side-tab {
  flex: 1;
  padding: var(--space-3) 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.side-tab--on {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.side-body {
  padding: var(--space-3);
  overflow-y: auto;
  flex: 1;
}
.side-root {
  display: block;
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  margin-bottom: var(--space-1);
}
.side-home {
  color: var(--muted);
}
.side-row {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  border-radius: var(--radius);
  padding: var(--space-1) var(--space-2);
  transition: background 0.15s;
}
.side-row:hover,
.side-root:hover {
  background: var(--surface-2);
}
html.dark .side-row:hover,
html.dark .side-root:hover {
  background: #1f2937;
}
.side-on {
  background: var(--primary-soft);
  color: var(--primary);
}
.side-chevron {
  width: 1.1rem;
  text-align: center;
  color: var(--muted-2);
  font-size: 0.9rem;
  transition: transform 0.15s;
  cursor: pointer;
}
.side-chevron--open {
  transform: rotate(90deg);
}
.side-chevron--leaf {
  cursor: default;
}
.side-link {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
  font-size: 0.875rem;
}
.side-count {
  font-size: 0.72rem;
  color: var(--muted-2);
  background: var(--surface-3);
  border-radius: 9999px;
  padding: 0 var(--space-2);
}
html.dark .side-count {
  background: #1f2937;
}
.side-nest {
  margin-left: var(--space-4);
  border-left: 1px solid var(--border-soft);
  padding-left: var(--space-1);
}
.side-foot {
  border-top: 1px solid var(--border);
  padding: var(--space-3);
}
.side-add {
  width: 100%;
  text-decoration: none;
}
.side-config {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.side-config label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-3);
  margin-top: var(--space-2);
}
.side-config .input[disabled] {
  opacity: 0.65;
  cursor: not-allowed;
}

/* Breadcrumb */
.crumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  font-size: 0.9rem;
}
.crumb-link {
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
}
.crumb-link:hover {
  color: var(--primary);
}
.crumb-sep {
  color: var(--muted-2);
}

/* Children group */
.group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
}
html.dark .group {
  background: #111827;
}
.group--nested {
  border-style: dashed;
  box-shadow: none;
  margin: var(--space-2) 0 var(--space-1) 0;
  background: transparent;
}
.group-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.group-title {
  font-weight: 700;
  font-size: 0.95rem;
}
.group-cfg {
  margin-left: auto;
}
.level-strip {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  background: var(--surface-2);
}
html.dark .level-strip {
  background: #0d1626;
}
.strip-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}
.strip-row label:first-child {
  width: 8.5rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-3);
}
.strip-row .input {
  flex: 1;
  min-width: 10rem;
}
.strip-row--end {
  justify-content: flex-end;
  margin-bottom: 0;
}

/* Accordion items */
.group-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.acc {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
html.dark .acc {
  background: #0f1a2c;
}
.acc:hover {
  border-color: var(--border-strong);
}
.acc.just-added {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.acc-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
}
.acc-grip {
  color: var(--muted-2);
  cursor: grab;
  touch-action: none;
  user-select: none;
  font-size: 0.9rem;
}
.drag-item {
  opacity: 0.92;
  box-shadow: var(--shadow-lg);
  position: relative;
}
.drag-item .acc-grip {
  cursor: grabbing;
}
.acc-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  min-width: 0;
  text-align: left;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0 0;
}
.acc-chevron {
  color: var(--muted-2);
  transition: transform 0.15s;
  display: inline-block;
}
.acc-toggle--open .acc-chevron {
  transform: rotate(90deg);
}
.acc-badge {
  font-size: 0.78rem;
  white-space: nowrap;
}
.acc-remove {
  color: var(--muted-2);
  font-size: 0.85rem;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
}
.acc-remove[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}
.acc-body {
  padding: 0 var(--space-3) var(--space-3) var(--space-8);
}
.group-add {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.group-add .input {
  flex: 1;
}
.first-child form {
  margin-top: var(--space-1);
}

/* Residents inside an end unit */
.res-list {
  display: flex;
  flex-direction: column;
}
.res-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.875rem;
}
.res-name {
  font-weight: 600;
}
.res-contact {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.res-add {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-3);
}
.res-add .input {
  flex: 1;
  min-width: 8rem;
}

@media (max-width: 900px) {
  .split {
    flex-direction: column;
  }
  .split-side {
    width: 100%;
    position: static;
    max-height: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .side-chevron,
  .acc-chevron,
  .side-row,
  .acc {
    transition: none;
  }
}

/* ── Session-expired re-login modal ───────────────────────────────────── */
.relogin-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgba(3, 7, 18, 0.55);
  backdrop-filter: blur(2px);
  animation: fadeIn 0.15s ease-out;
}
/* The modal reuses the login card verbatim; only the page-centering margin
 * is neutralized inside the overlay. */
.relogin-overlay .login-card {
  margin: 0;
  width: 100%;
  box-shadow: var(--shadow-xl);
}
@media (prefers-reduced-motion: reduce) {
  .relogin-overlay,
  .relogin-overlay .login-card,
  .modal-overlay,
  .modal-card {
    animation: none;
  }
}

/* Lazy accordion loading stub — tall enough that the first slide stage does
 * not look like a sliver, with the shared spinner. */
.acc-lazy {
  min-height: 3.25rem;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.acc-lazy-spin {
  color: var(--muted-2);
  display: inline-flex;
}
.acc-lazy-spin svg {
  height: 1.1rem;
  width: 1.1rem;
}

/* Empty-unit chooser: resident vs. deeper level as peer CTAs. */
.chooser-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin: var(--space-2) 0 var(--space-3);
}
.chooser-on {
  background: var(--primary);
  color: #ffffff;
}

/* ── Danger-zone dialog (same posture as the re-login overlay) ────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgba(3, 7, 18, 0.55);
  backdrop-filter: blur(2px);
  animation: fadeIn 0.15s ease-out;
}
.modal-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  max-width: 26rem;
  padding: var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  animation: scaleIn 0.15s ease-out;
}
html.dark .modal-card {
  background: #111827;
}
.modal-card h2 {
  margin: 0;
  font-size: 1.05rem;
}
.modal-card .hint {
  margin: 0;
}
.modal-card .input {
  width: 100%;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-1);
}
.panel .btn-danger {
  background: #dc2626;
  color: #ffffff;
}
.panel .btn-danger:hover {
  background: #b91c1c;
}
/* Labeled outline variant for the card-foot delete: quiet at rest, fills
 * red on hover (the .btn transition animates it, mirroring .btn-ghost). */
.panel .btn-danger-ghost {
  border: 1px solid var(--red-text);
  color: var(--red-text);
  background: transparent;
}
.panel .btn-danger-ghost:hover {
  background: #dc2626;
  border-color: #dc2626;
  color: #ffffff;
}
/* The card's danger action sits at the card foot, out of the reading flow. */
.pause-box > .btn-danger-ghost {
  align-self: flex-end;
}
.panel .btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}
/* A disabled danger submit must not darken as if it were actionable. */
.panel .btn-danger[disabled]:hover {
  background: #dc2626;
}

/* WhatsApp pairing QR: a fixed square that stays scannable on any screen. */
.qr-image {
  display: block;
  width: 16rem;
  max-width: 100%;
  image-rendering: pixelated;
  background: #fff;
  padding: 0.75rem;
  border-radius: 0.5rem;
  margin: 0.75rem 0;
}
