:root {
  --ink: #1e2328;
  --muted: #5b5f5f;
  --bg: #f6f1e7;
  --bg-soft: #efe6d7;
  --brand: #e26d3e;
  --brand-strong: #c4572f;
  --brand-cool: #2f6f7e;
  --card: #ffffff;
  --border: #e5d8c6;
  --border-strong: #d3c1a8;
  --shadow: 0 20px 44px rgba(43, 34, 24, 0.1);
  --shadow-sm: 0 8px 18px rgba(43, 34, 24, 0.06);
  --radius: 20px;
  --sidebar-width: 4.5rem;
  --font-base: "Roboto", "Segoe UI", sans-serif;
  --font-display: "Roboto", "Segoe UI", sans-serif;

  /* Feedback */
  --positive: #2f7a5a;
  --negative: #b3261e;
  --attention: #a86a1b;

  /* Controles de formulario e botoes */
  --field-radius: 12px;
  --field-radius-sm: 10px;
  --field-height: 2.75rem;
  --field-height-sm: 2.25rem;
  /* Botoes sao deliberadamente mais compactos que os campos. */
  --btn-height: 2.15rem;
  --btn-height-sm: 1.85rem;
  --btn-height-lg: 2.7rem;
  --placeholder: #a4998a;
  --ring: 0 0 0 3px rgba(226, 109, 62, 0.22);
  --ring-cool: 0 0 0 3px rgba(47, 111, 126, 0.22);
  --ring-danger: 0 0 0 3px rgba(179, 38, 30, 0.16);
  --ease: 160ms cubic-bezier(0.2, 0.8, 0.3, 1);
}

* {
  box-sizing: border-box;
}

body {
  font-family: var(--font-base);
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 20%, rgba(226, 109, 62, 0.12), transparent 55%),
    radial-gradient(circle at 85% 10%, rgba(47, 111, 126, 0.12), transparent 45%),
    linear-gradient(180deg, #f8f2e9 0%, #f2e8d9 100%);
  min-height: 100vh;
}

a {
  color: var(--brand-strong);
}

.app-shell {
  background: transparent;
}

.app-main {
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  padding: 2rem 2.5rem 3rem;
  min-width: 0;
}

.app-container {
  max-width: 100%;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.25em;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--brand-cool);
  margin-bottom: 0.5rem;
}

.page-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 3vw, 2.8rem);
  margin: 0;
}

.subtitle {
  color: var(--muted);
  margin: 0.35rem 0 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: rgba(47, 111, 126, 0.12);
  color: var(--brand-cool);
  font-weight: 600;
  margin-left: 0.4rem;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ==========================================================================
   Botoes
   ========================================================================== */

.btn {
  --btn-lift: -1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--btn-height);
  padding: 0.3rem 0.75rem;
  border-radius: var(--field-radius-sm);
  border-width: 1px;
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1.2;
  text-decoration: none;
  transition: background-color var(--ease), border-color var(--ease), color var(--ease),
    box-shadow var(--ease), transform var(--ease);
}

.btn:hover:not(:disabled):not(.disabled) {
  transform: translateY(var(--btn-lift));
}

.btn:active:not(:disabled):not(.disabled) {
  transform: translateY(0) scale(0.985);
}

/* Anel de foco unico e visivel apenas na navegacao por teclado. */
.btn:focus {
  box-shadow: none;
}

.btn:focus-visible {
  outline: 2px solid var(--brand-strong);
  outline-offset: 2px;
  box-shadow: none;
}

.btn:disabled,
.btn.disabled,
fieldset:disabled .btn {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-sm {
  min-height: var(--btn-height-sm);
  padding: 0.2rem 0.55rem;
  border-radius: 8px;
  font-size: 0.78rem;
  gap: 0.3rem;
}

.btn-lg {
  min-height: var(--btn-height-lg);
  padding: 0.55rem 1.2rem;
  font-size: 0.95rem;
  border-radius: var(--field-radius);
}

/* Botao apenas com icone: quadrado, sem texto, rotulo via aria-label + tooltip. */
.btn-icon {
  width: var(--btn-height);
  min-width: var(--btn-height);
  padding: 0;
  gap: 0;
}

.btn-icon.btn-sm {
  width: var(--btn-height-sm);
  min-width: var(--btn-height-sm);
}

.btn-icon.btn-lg {
  width: var(--btn-height-lg);
  min-width: var(--btn-height-lg);
}

.btn-icon i {
  font-size: 0.85rem;
}

.btn i {
  font-size: 0.9em;
  line-height: 1;
}

/* Agrupamento de acoes so-icone dentro de listas e cartoes. */
.icon-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.icon-actions form {
  display: inline-flex;
  margin: 0;
}

.btn-brand {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 6px 16px rgba(226, 109, 62, 0.26);
}

.btn-brand:hover,
.btn-brand:focus-visible {
  background: var(--brand-strong);
  border-color: var(--brand-strong);
  color: #fff;
}

.btn-brand:hover:not(:disabled) {
  box-shadow: 0 10px 22px rgba(226, 109, 62, 0.32);
}

.btn-outline-brand {
  border-color: var(--brand);
  color: var(--brand-strong);
  background: transparent;
}

.btn-outline-brand:hover,
.btn-outline-brand:focus-visible {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-check:checked + .btn-outline-brand,
.btn-outline-brand.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.btn-outline-secondary {
  border-color: var(--border-strong);
  color: var(--muted);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus-visible {
  background: var(--bg-soft);
  border-color: var(--muted);
  color: var(--ink);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover,
.btn-ghost:focus-visible {
  background: rgba(226, 109, 62, 0.1);
  color: var(--brand-strong);
}

/* Estado de envio: evita duplo clique e sinaliza progresso. */
.btn[data-loading] {
  pointer-events: none;
  position: relative;
  color: transparent !important;
}

.btn[data-loading] > * {
  visibility: hidden;
}

.btn[data-loading]::after {
  content: "";
  position: absolute;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: inherit;
  animation: btn-spin 0.6s linear infinite;
}

.btn-brand[data-loading]::after,
.btn-danger[data-loading]::after {
  border-color: #fff;
  border-top-color: transparent;
}

.btn-outline-brand[data-loading]::after {
  border-color: var(--brand);
  border-top-color: transparent;
}

.btn-outline-secondary[data-loading]::after,
.btn-ghost[data-loading]::after {
  border-color: var(--muted);
  border-top-color: transparent;
}

.btn-outline-danger[data-loading]::after {
  border-color: var(--negative);
  border-top-color: transparent;
}

@keyframes btn-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   Campos de formulario
   ========================================================================== */

.form-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #4a4f52;
  margin-bottom: 0.3rem;
}

.form-control,
.form-select {
  min-height: var(--field-height);
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--field-radius);
  background-color: var(--card);
  color: var(--ink);
  font-size: 0.95rem;
  transition: border-color var(--ease), box-shadow var(--ease), background-color var(--ease);
}

.form-control:hover:not(:disabled):not([readonly]):not(:focus),
.form-select:hover:not(:disabled):not(:focus) {
  border-color: var(--border-strong);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--brand);
  box-shadow: var(--ring);
  background-color: var(--card);
  color: var(--ink);
}

.form-control::placeholder {
  color: var(--placeholder);
  opacity: 1;
}

.form-control:disabled,
.form-control[readonly],
.form-select:disabled {
  background-color: var(--bg-soft);
  border-color: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

.form-control-sm,
.form-select-sm {
  min-height: var(--field-height-sm);
  padding: 0.35rem 0.65rem;
  border-radius: var(--field-radius-sm);
  font-size: 0.88rem;
}

.form-control-lg,
.form-select-lg {
  min-height: 3.1rem;
  font-size: 1rem;
  border-radius: 14px;
}

textarea.form-control {
  min-height: 6rem;
  line-height: 1.5;
}

/* Seta propria, alinhada a paleta. */
.form-select {
  padding-right: 2.4rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%235b5f5f' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 1rem;
}

.form-select-sm {
  padding-right: 2rem;
  background-position: right 0.6rem center;
  background-size: 0.85rem;
}

/* Feedback nativo de validacao apos interacao do usuario. */
.form-control:user-invalid,
.form-select:user-invalid {
  border-color: var(--negative);
}

.form-control:user-invalid:focus,
.form-select:user-invalid:focus {
  box-shadow: var(--ring-danger);
}

.form-control.is-invalid,
.form-select.is-invalid {
  border-color: var(--negative);
}

.invalid-feedback,
.form-error {
  color: var(--negative);
  font-size: 0.82rem;
}

/* Marcador de obrigatorio derivado do proprio campo. */
.form-field:has(:required) > .form-label::after,
.settings-field:has(:required) > .form-label::after {
  content: "*";
  color: var(--brand-strong);
  margin-left: 0.2rem;
}

/* Spinners de numero apenas quando o campo esta em uso. */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  opacity: 0;
  transition: opacity var(--ease);
}

input[type="number"]:hover::-webkit-outer-spin-button,
input[type="number"]:hover::-webkit-inner-spin-button,
input[type="number"]:focus::-webkit-outer-spin-button,
input[type="number"]:focus::-webkit-inner-spin-button {
  opacity: 1;
}

/* Grupos: o anel de foco envolve o conjunto, nao so o input. */
.input-group {
  border-radius: var(--field-radius);
  transition: box-shadow var(--ease);
}

.input-group:focus-within {
  box-shadow: var(--ring);
}

.input-group:focus-within .form-control,
.input-group:focus-within .form-select {
  box-shadow: none;
}

.input-group-text {
  background-color: var(--bg-soft);
  border-color: var(--border);
  color: var(--muted);
  border-radius: var(--field-radius);
  font-size: 0.9rem;
}

.input-group-sm > .input-group-text,
.input-group-sm > .form-control,
.input-group-sm > .form-select,
.input-group-sm > .btn {
  border-radius: var(--field-radius-sm);
}

.form-check-input {
  border-color: var(--border-strong);
  transition: background-color var(--ease), border-color var(--ease), box-shadow var(--ease);
}

.form-check-input:checked {
  background-color: var(--brand);
  border-color: var(--brand);
}

.form-check-input:focus {
  border-color: var(--brand);
  box-shadow: var(--ring);
}

.form-check-label {
  cursor: pointer;
}

.form-text {
  color: var(--muted);
  font-size: 0.82rem;
}

/* Foco visivel consistente em elementos interativos fora do .btn */
.nav-link:focus-visible,
.dropdown-item:focus-visible,
.icon-option:focus-visible,
.wizard-step:focus-visible,
.page-link:focus-visible,
a:focus-visible {
  outline: 2px solid var(--brand-strong);
  outline-offset: 2px;
  box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .form-control,
  .form-select,
  .icon-option,
  .nav-link i {
    transition: none;
  }

  .btn:hover:not(:disabled),
  .btn:active:not(:disabled),
  .icon-option:hover {
    transform: none;
  }

  .btn[data-loading]::after {
    animation-duration: 2s;
  }
}

/* Em telas de toque, campos e botoes ganham area minima confortavel. */
@media (max-width: 576px) {
  .form-control,
  .form-select {
    font-size: 1rem; /* evita zoom automatico no iOS */
  }

  .form-control-sm,
  .form-select-sm {
    min-height: 2.5rem;
    font-size: 0.95rem;
  }

  /* Botoes seguem compactos; apenas os so-icone garantem area de toque. */
  .btn-icon.btn-sm {
    width: var(--btn-height);
    min-width: var(--btn-height);
    min-height: var(--btn-height);
  }
}

.section-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--card);
}

.section-card .card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  font-weight: 600;
}

.section-card .card-body {
  padding: 1.5rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.section-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  margin: 0;
}

.section-subtitle {
  color: var(--muted);
  margin: 0.4rem 0 0;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow);
}

.stat-card.highlight {
  background: linear-gradient(135deg, rgba(226, 109, 62, 0.1), rgba(47, 111, 126, 0.08));
}

.stat-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-caption {
  margin-top: 0.4rem;
  color: var(--muted);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.main-col,
.side-col {
  display: grid;
  gap: 1.5rem;
  align-content: start;
  min-width: 0;
}

.main-col > .section-card,
.side-col > .section-card {
  margin-bottom: 0;
}

.tag {
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  background: rgba(226, 109, 62, 0.12);
  color: var(--brand-strong);
  font-weight: 600;
  font-size: 0.8rem;
}

.tag-success {
  background: rgba(47, 111, 126, 0.16);
  color: var(--brand-cool);
}

.tag-danger {
  background: rgba(226, 109, 62, 0.18);
  color: var(--brand-strong);
}

.kind-item {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.8rem 1rem;
  background: rgba(244, 236, 223, 0.4);
}

.kind-title {
  font-weight: 600;
  color: var(--muted);
}

.kind-value {
  font-size: 1.2rem;
  font-weight: 700;
}

.callout {
  margin-top: 1.2rem;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  background: rgba(47, 111, 126, 0.1);
  color: var(--brand-cool);
}

.category-list,
.summary-list {
  display: grid;
  gap: 0.8rem;
}

.category-item,
.summary-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(244, 236, 223, 0.35);
}

  .category-name {
    font-weight: 600;
  }

  .category-icon {
    font-size: 1rem;
    color: var(--ink);
  }

  .category-item .category-name {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 0.5rem;
  }

.summary-title {
  font-weight: 600;
}

.category-meta,
.summary-meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.category-value,
.summary-value {
  font-weight: 700;
}

.app-table th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.app-table td {
  vertical-align: middle;
}

.icon-input {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.icon-input input {
  min-width: 140px;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.icon-preview {
  min-width: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-preview i {
  font-size: 1rem;
}

.icon-option {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.6rem 0.7rem;
  background: rgba(244, 236, 223, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--ink);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.icon-option i {
  font-size: 1.2rem;
}

.icon-option:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(43, 34, 24, 0.12);
}

.form-section-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
  font-weight: 600;
  margin-top: 0.4rem;
}

.form-hint {
  margin-top: 0.4rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.wizard-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.75rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(244, 236, 223, 0.4);
}

.wizard-step {
  border: 1px solid transparent;
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}

.wizard-step .wizard-index {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(47, 111, 126, 0.12);
  color: var(--brand-cool);
  font-size: 0.85rem;
}

.wizard-step.is-active {
  color: var(--ink);
  border-color: rgba(226, 109, 62, 0.3);
  background: rgba(226, 109, 62, 0.12);
}

.wizard-step.is-complete .wizard-index {
  background: rgba(47, 111, 126, 0.2);
  color: var(--brand-cool);
}

.wizard-panel {
  display: none;
}

.wizard-panel.is-active {
  display: block;
}

.wizard-actions .is-hidden {
  display: none;
}

.summary-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.9);
}

.form-preview {
  border-style: dashed;
  background: rgba(244, 236, 223, 0.45);
}

.form-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.form-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.form-preview-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.preview-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  font-weight: 600;
}

.preview-value {
  font-weight: 600;
}

.form-preview-note {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

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

.is-hidden {
  display: none;
}

.app-sidebar {
  background: linear-gradient(180deg, #f9f3e8 0%, #efe2d2 100%);
  box-shadow: 0 12px 28px rgba(43, 34, 24, 0.15);
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1030;
  border-right: 1px solid var(--border);
}

.app-sidebar .sidebar-brand img {
  max-height: 70px;
}

.app-sidebar .nav-link {
  color: var(--ink);
}

.auth-body {
  min-height: 100vh;
  padding: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-shell {
  width: min(980px, 100%);
}

.auth-card {
  border: 1px solid var(--border);
  border-radius: 26px;
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.auth-split {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
}

.auth-panel {
  padding: 2.6rem 2.8rem;
  background: linear-gradient(160deg, rgba(226, 109, 62, 0.2), rgba(47, 111, 126, 0.18));
  position: relative;
  overflow: hidden;
}

.auth-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.35), transparent 40%),
    radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.2), transparent 45%);
  opacity: 0.7;
  pointer-events: none;
}

.auth-logo {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  z-index: 1;
}

.auth-logo img {
  width: 54px;
  height: 54px;
  object-fit: contain;
}

.auth-brand {
  font-weight: 700;
  font-size: 1.2rem;
}

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

.auth-headline {
  font-family: var(--font-display);
  font-size: 2rem;
  margin: 0 0 0.7rem;
  position: relative;
  z-index: 1;
}

.auth-copy {
  color: var(--muted);
  margin-bottom: 1.8rem;
  position: relative;
  z-index: 1;
}

.auth-points {
  display: grid;
  gap: 0.85rem;
  position: relative;
  z-index: 1;
}

.auth-point {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
}

.auth-point i {
  color: var(--brand-strong);
  margin-top: 0.15rem;
}

.auth-footer {
  margin-top: 2rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  color: var(--muted);
  position: relative;
  z-index: 1;
}

.auth-form {
  padding: 2.6rem;
  background: #fff;
}

.auth-form .form-control {
  border-radius: 12px;
}

.auth-form-header .page-title {
  font-size: 2.1rem;
}

.auth-alt {
  margin-top: 1.8rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

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

.auth-link {
  font-weight: 600;
  text-decoration: none;
}

.auth-link:hover {
  text-decoration: underline;
}

.profile-grid {
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
}

.profile-hero {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: linear-gradient(140deg, rgba(226, 109, 62, 0.2), rgba(47, 111, 126, 0.24));
  color: var(--brand-strong);
  font-size: 1.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}

.profile-name {
  font-size: 1.2rem;
  font-weight: 700;
}

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

.profile-badges {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.profile-meta {
  display: grid;
  gap: 0.65rem;
  margin-top: 1.2rem;
}

.profile-meta-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  background: rgba(244, 236, 223, 0.35);
}

.profile-meta-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.profile-meta-value {
  font-weight: 600;
  text-align: right;
}

.profile-link {
  color: var(--ink);
  text-decoration: none;
}

.profile-link:hover {
  color: var(--ink);
  background: rgba(244, 236, 223, 0.6);
}

@media (max-width: 992px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

  .app-main {
    padding: 1.5rem;
  }

  .auth-split {
    grid-template-columns: 1fr;
  }

  .auth-panel {
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 768px) {
  .page-header {
    align-items: flex-start;
  }

  .auth-body {
    padding: 1.25rem;
  }

  .app-shell {
    flex-direction: column;
  }

  .app-sidebar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    flex-direction: row !important;
    align-items: center;
    padding: 0.5rem 0.75rem calc(0.5rem + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-top: 1px solid var(--border);
  }

  .app-sidebar .sidebar-brand {
    padding: 0.35rem 0.5rem !important;
  }

  .app-sidebar .sidebar-brand img {
    max-height: 44px;
  }

  .app-sidebar .nav {
    flex-direction: row !important;
    flex-wrap: nowrap;
    flex: 1;
    justify-content: center;
    gap: 0.4rem;
    margin-bottom: 0 !important;
  }

  .app-sidebar .nav-link {
    border: 0 !important;
    padding: 0.6rem 0.75rem !important;
  }

  .app-sidebar .dropdown {
    border-top: 0 !important;
    margin-left: auto;
  }

  .app-sidebar .dropdown > a {
    padding: 0.35rem 0.5rem !important;
  }

  .app-main {
    margin-left: 0;
    width: 100%;
    padding: 0rem 0 calc(4.75rem + env(safe-area-inset-bottom));
  }

  .transaction-card .card-header,
  .transaction-card .card-body {
    padding: 1.1rem;
  }

  .transaction-card .section-header {
    align-items: flex-start;
  }

  .transaction-card .section-header .tag {
    margin-top: 0.35rem;
  }

  .transaction-form .wizard-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
    padding: 0.6rem;
  }

  .transaction-form .wizard-step {
    flex-direction: column;
    justify-content: center;
    text-align: center;
    gap: 0.35rem;
    padding: 0.4rem 0.5rem;
  }

  .transaction-form .wizard-step .wizard-index {
    width: 1.4rem;
    height: 1.4rem;
    font-size: 0.75rem;
  }

  .transaction-form .wizard-step .wizard-label {
    font-size: 0.75rem;
  }

  .transaction-form .btn-group {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .transaction-form .btn-group > .btn,
  .transaction-form .btn-group > .btn-check + .btn {
    border-radius: 12px;
    margin-left: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    padding: 0.65rem 0.9rem;
  }

  .transaction-form .form-preview {
    padding: 0.85rem;
  }

  .transaction-form .form-preview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .transaction-form .wizard-actions {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.6rem;
  }

  .transaction-form .wizard-actions > div {
    width: 100%;
    display: grid;
    gap: 0.6rem;
  }

  .transaction-form .wizard-actions > button,
  .transaction-form .wizard-actions .btn {
    width: 100%;
  }
}

/* ==========================================================================
   Bases da carteira (contas, cartoes, categorias, regras)
   ========================================================================== */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat-card .stat-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(47, 111, 126, 0.12);
  color: var(--brand-cool);
  margin-bottom: 0.75rem;
}

.stat-card .stat-icon.is-brand {
  background: rgba(226, 109, 62, 0.14);
  color: var(--brand-strong);
}

.stat-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  margin-top: 0.6rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.stat-breakdown > span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.value-positive {
  color: var(--positive);
}

.value-negative {
  color: var(--negative);
}

.value-attention {
  color: var(--attention);
}

/* --- Navegacao entre as bases --- */

.bases-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.4rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow-sm);
}

.bases-nav .nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid transparent;
  transition: background-color var(--ease), color var(--ease), border-color var(--ease);
}

.bases-nav .nav-link:hover {
  color: var(--ink);
  background: rgba(226, 109, 62, 0.08);
}

.bases-nav .nav-link.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.bases-nav .nav-count {
  min-width: 1.5rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: rgba(47, 111, 126, 0.14);
  color: var(--brand-cool);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
}

.bases-nav .nav-link.active .nav-count {
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
}

/* Cabecalho de secao das bases: o botao de acao fica na mesma linha do titulo. */
.tab-content .section-header > div:first-child {
  flex: 1 1 auto;
  min-width: 0;
}

/* --- Barra de acoes de cada base --- */

.base-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.base-toolbar .search-field {
  position: relative;
  flex: 1 1 240px;
  max-width: 22rem;
}

.search-field i {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--placeholder);
  pointer-events: none;
  font-size: 0.85rem;
}

.search-field .form-control {
  padding-left: 2.3rem;
  border-radius: 999px;
}

/* --- Cartao de item (conta, cartao, categoria) --- */

.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.entity-grid.is-compact {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.entity-card {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.1rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--ease), border-color var(--ease);
}

.entity-card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 12px 26px rgba(43, 34, 24, 0.12);
}

.entity-card.is-blocked {
  background: linear-gradient(180deg, rgba(244, 236, 223, 0.55), rgba(255, 255, 255, 0.9));
}

.entity-head {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.entity-avatar {
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(140deg, rgba(226, 109, 62, 0.16), rgba(47, 111, 126, 0.18));
  color: var(--brand-strong);
  font-size: 1rem;
}

.entity-heading {
  min-width: 0;
  flex: 1;
}

.entity-name {
  font-weight: 700;
  font-size: 1.02rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entity-meta {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.status-badge::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.is-active {
  background: rgba(47, 122, 90, 0.14);
  color: var(--positive);
}

.status-badge.is-blocked {
  background: rgba(168, 106, 27, 0.16);
  color: var(--attention);
}

/* --- Metricas dentro do cartao --- */

.entity-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.6rem 0.9rem;
}

/* Rotulos longos (Fatura atual, Vencimento) cabem melhor em 2 colunas fixas. */
.entity-metrics.is-2col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Linha de contexto abaixo do cabecalho, com a largura toda do cartao. */
.entity-meta-row {
  margin-top: -0.35rem;
}

.entity-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

/* Status + acao no cabecalho, para cartoes sem metricas. */
.entity-head-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.metric-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 600;
}

.metric-value {
  font-weight: 700;
  font-size: 0.98rem;
  overflow-wrap: anywhere;
}

.metric-value.is-strong {
  font-size: 1.25rem;
}

.meter {
  display: grid;
  gap: 0.35rem;
}

.meter-track {
  height: 0.5rem;
  border-radius: 999px;
  background: rgba(43, 34, 24, 0.09);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--brand-cool);
  transition: width var(--ease);
}

.meter-fill.is-warning {
  background: var(--attention);
}

.meter-fill.is-danger {
  background: var(--negative);
}

.meter-caption {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.entity-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.35rem;
  border-top: 1px dashed var(--border);
}

.entity-actions {
  justify-content: flex-end;
}

.entity-edit {
  border-top: 1px dashed var(--border);
  padding-top: 0.85rem;
}

/* --- Painel de criacao --- */

.create-panel {
  border: 1px dashed var(--border-strong);
  border-radius: 16px;
  background: rgba(244, 236, 223, 0.4);
  padding: 1.15rem;
  margin-bottom: 1.25rem;
}

.create-panel .form-section-title {
  margin-top: 0;
}

/* --- Regras agrupadas por categoria --- */

.rule-group {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem;
}

.rule-group-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.keyword-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.keyword-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.35rem 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(244, 236, 223, 0.5);
  font-size: 0.85rem;
  font-weight: 600;
  transition: border-color var(--ease), background-color var(--ease);
}

.keyword-chip:hover {
  border-color: var(--border-strong);
  background: rgba(244, 236, 223, 0.85);
}

.keyword-chip .btn-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  transition: background-color var(--ease), color var(--ease);
}

.keyword-chip .btn-chip-remove:hover {
  background: rgba(179, 38, 30, 0.12);
  color: var(--negative);
  transform: none;
}

/* --- Estado vazio --- */

.base-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2.5rem 1.5rem;
  border: 1px dashed var(--border-strong);
  border-radius: 16px;
  background: rgba(244, 236, 223, 0.35);
  text-align: center;
  color: var(--muted);
}

.base-empty i {
  font-size: 1.6rem;
  color: var(--brand-cool);
}

.base-empty-title {
  font-weight: 700;
  color: var(--ink);
}

/* --- Seletor de icones --- */

.icon-picker-search {
  margin-bottom: 1rem;
}

.icon-option.is-selected {
  border-color: var(--brand);
  background: rgba(226, 109, 62, 0.14);
  color: var(--brand-strong);
}

@media (max-width: 768px) {
  .bases-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    border-radius: 16px;
    scrollbar-width: none;
  }

  .bases-nav::-webkit-scrollbar {
    display: none;
  }

  .bases-nav .nav-link {
    white-space: nowrap;
  }

  .entity-grid,
  .entity-grid.is-compact {
    grid-template-columns: 1fr;
  }

  .base-toolbar .search-field {
    max-width: none;
  }

  .base-toolbar > .btn:not(.btn-icon) {
    width: 100%;
  }
}

/* --------------------------------------------------------------------------
 * Indicador de carregamento htmx (spec 012): oculto por padrao, visivel
 * enquanto o elemento que disparou a requisicao esta em `.htmx-request`.
 * Definido aqui (em vez de depender so do CSS injetado pelo proprio htmx)
 * para garantir o comportamento mesmo se `includeIndicatorStyles` mudar.
 * -------------------------------------------------------------------------- */
.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-block;
}
