:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --panel-strong: #f6efe2;
  --sidebar: #13231d;
  --sidebar-muted: #c7d0c6;
  --text: #17221c;
  --muted: #5d6b63;
  --line: #d7d0c1;
  --accent: #b85c38;
  --accent-dark: #8f472b;
  --success: #2f7d52;
  --warning: #b58817;
  --danger: #b64545;
  --shadow: 0 18px 60px rgba(18, 26, 23, 0.08);
  --shadow-soft: 0 10px 30px rgba(18, 26, 23, 0.05);
  --radius: 22px;
  --radius-sm: 12px;
  --radius-xs: 10px;
  --input-height: 46px;
  --button-height: 44px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top right, rgba(184, 92, 56, 0.16), transparent 25%),
    linear-gradient(180deg, #f5f1e8 0%, #efebe2 100%);
  color: var(--text);
  font-family: var(--font);
  overflow-x: hidden;
}

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

button {
  border: 0;
  border-radius: var(--radius-sm);
  min-height: var(--button-height);
  min-width: 132px;
  padding: 0.72rem 1rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
  letter-spacing: 0.01em;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-dark);
  box-shadow:
    inset 0 -1px 0 rgba(0, 0, 0, 0.12),
    0 8px 20px rgba(143, 71, 43, 0.16);
}

button.secondary {
  background: #eadcc8;
  color: var(--text);
  box-shadow: none;
}

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: none;
}

button.danger-outline {
  color: var(--danger);
  border-color: rgba(182, 69, 69, 0.35);
}

.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
  gap: 1rem;
  padding: 1rem 1rem 0 1rem;
}

.sidebar {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 35%),
    linear-gradient(180deg, #13231d 0%, #1e3229 100%);
  color: white;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 1rem;
  height: calc(100vh - 2rem);
  border-radius: 26px;
  overflow: hidden;
}

.brand h1,
.topbar h2,
.page-section h3 {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: -0.03em;
}

.brand h1 {
  margin: 0.35rem 0;
  font-size: 1.58rem;
}

.brand-kicker,
.page-kicker {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: #f0cfa5;
}

.brand p,
.sidebar-card p {
  color: var(--sidebar-muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.sidebar-nav {
  display: grid;
  gap: 0.25rem;
}

.sidebar-nav a {
  color: #eff4ee;
  text-decoration: none;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  display: block;
  font-size: 0.93rem;
}

.sidebar-nav a.active,
.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-card,
.surface,
.page-hero,
.table-card,
.feed-card {
  background: var(--panel);
  border: 1px solid rgba(215, 208, 193, 0.7);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}

.sidebar-card {
  color: var(--text);
  padding: 0.85rem;
  margin-top: auto;
  margin-bottom: 0.15rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  background: rgba(184, 92, 56, 0.12);
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 700;
}

.main-shell {
  min-width: 0;
  padding: 1rem 0 1rem 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 1.25rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0;
}

.topbar h2 {
  margin: 0.3rem 0 0;
  font-size: 2.25rem;
}

.topbar-actions {
  display: flex;
  gap: 0.8rem;
  align-items: end;
}

.topbar-user {
  align-self: center;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 280px;
  text-align: right;
}

.field {
  display: grid;
  gap: 0.42rem;
  color: var(--muted);
  font-size: 0.9rem;
  align-content: start;
}

.field.compact {
  min-width: 230px;
}

.field > span {
  color: #425148;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.field-hint {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.form-section-title {
  margin-top: 0.35rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(215, 208, 193, 0.9);
  color: var(--accent-dark);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field-optional {
  color: #7b867f;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 0.78rem 0.95rem;
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

input,
select {
  min-height: var(--input-height);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(184, 92, 56, 0.52);
  box-shadow: 0 0 0 4px rgba(184, 92, 56, 0.12);
}

textarea {
  min-height: 132px;
  resize: vertical;
  line-height: 1.52;
}

textarea.tall {
  min-height: 176px;
}

.surface > h3,
.table-card > h3,
.feed-card > h3 {
  margin: 0;
  font-size: 1.32rem;
}

.surface-header {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1.15rem;
}

.surface-header p {
  margin: 0;
}

.card-stack {
  display: grid;
  gap: 1rem;
}

.card-section {
  display: grid;
  gap: 0.9rem;
  padding-top: 0.2rem;
}

.card-section + .card-section {
  padding-top: 1rem;
  border-top: 1px solid #ece4d5;
}

.card-section-head {
  display: grid;
  gap: 0.25rem;
}

.card-section-head h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.card-section-head p {
  margin: 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.form-shell {
  display: grid;
  gap: 1.1rem;
}

.form-grid {
  display: grid;
  gap: 1rem 1rem;
}

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

.form-grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid.cols-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.span-2 {
  grid-column: span 2;
}

.span-3 {
  grid-column: span 3;
}

.span-5 {
  grid-column: span 5;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: flex-end;
  padding-top: 0.25rem;
}

.form-actions.split {
  justify-content: space-between;
}

.form-actions .muted {
  margin-right: auto;
}

.form-divider {
  height: 1px;
  background: #ece4d5;
}

.surface-subtle {
  padding: 1rem;
  border-radius: 18px;
  border: 1px solid #ece4d5;
  background: linear-gradient(180deg, #fffdf9, #fbf6ee);
}

.inline-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.inline-actions a,
.inline-actions button {
  min-width: 0;
}

.inline-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem;
}

.checkbox-grid.is-disabled {
  opacity: 0.55;
}

.checkbox-chip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid #e7dcc8;
  border-radius: 14px;
  background: #fffaf2;
  color: var(--text);
}

.checkbox-chip input {
  width: auto;
  min-height: 0;
  margin: 0;
}

.tag {
  display: inline-flex;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid #e7dcc8;
  background: #fffaf2;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.inline-actions button {
  min-width: 0;
  min-height: 36px;
  padding: 0.45rem 0.7rem;
}

.danger-action {
  background: linear-gradient(180deg, #c85b4a, #a43f32);
}

.page-root {
  display: grid;
  gap: 1.35rem;
  min-width: 0;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.95rem 1.2rem 1.15rem;
  color: var(--muted);
  font-size: 0.84rem;
  border-top: 1px solid rgba(215, 208, 193, 0.8);
}

.page-hero {
  display: grid;
  gap: 1rem;
  padding: 1.4rem;
  background:
    linear-gradient(135deg, rgba(184, 92, 56, 0.12), rgba(255, 255, 255, 0.92)),
    var(--panel);
}

.page-hero h3 {
  margin: 0;
  font-size: 1.7rem;
}

.page-grid,
.stats-grid,
.dual-grid,
.triple-grid {
  display: grid;
  gap: 1rem;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.dual-grid {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.triple-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.surface,
.table-card,
.feed-card {
  padding: 1.35rem;
}

.metric-card {
  padding: 1rem;
  border-radius: 20px;
  background: linear-gradient(180deg, #fff, #fbf6ee);
  border: 1px solid var(--line);
}

.metric-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.metric-card strong {
  font-size: 1.35rem;
}

.patrimony-list {
  display: grid;
  gap: 1rem;
}

.patrimony-card {
  display: grid;
  gap: 0.9rem;
}

.patrimony-page-hero {
  gap: 1.15rem;
}

.patrimony-page-hero > p.muted {
  max-width: 860px;
  margin: 0;
}

.patrimony-card-head,
.patrimony-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.patrimony-card-head h3,
.patrimony-hero strong {
  margin: 0;
}

.patrimony-qr {
  width: 110px;
  height: 110px;
  object-fit: contain;
  border-radius: 16px;
  border: 1px solid #ece4d5;
  background: white;
  padding: 0.55rem;
}

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

.patrimony-gallery a {
  display: block;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid #ece4d5;
  background: #fffaf2;
}

.patrimony-gallery img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
}

.patrimony-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.4rem;
  padding: 1rem 1.1rem;
  border: 1px solid #ece4d5;
  border-radius: 18px;
  background: linear-gradient(180deg, #fffdf9, #f8f2e7);
}

.patrimony-pagination .tag {
  flex-shrink: 0;
}

.patrimony-pagination button {
  min-width: 168px;
}

.filters-row {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.patrimony-filters-row {
  align-items: end;
  margin-top: 0.1rem;
}

.patrimony-toolbar-actions {
  gap: 0.65rem;
  align-items: center;
}

.patrimony-card-actions {
  gap: 0.6rem;
  padding-top: 0.1rem;
}

.patrimony-card-actions button {
  flex: 0 0 auto;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.78rem 0.55rem;
  text-align: left;
  border-bottom: 1px solid #ece4d5;
  font-size: 0.92rem;
}

th {
  color: var(--muted);
  font-weight: 700;
}

.status {
  display: inline-flex;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.status.ok {
  background: rgba(47, 125, 82, 0.12);
  color: var(--success);
}

.status.warn {
  background: rgba(181, 136, 23, 0.15);
  color: var(--warning);
}

.status.danger {
  background: rgba(182, 69, 69, 0.12);
  color: var(--danger);
}

.feed-list,
.note-list {
  display: grid;
  gap: 0.8rem;
}

.feed-item,
.note-item {
  padding: 1rem;
  border-radius: 16px;
  border: 1px solid #ece4d5;
  background: #fffaf2;
}

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

.login-shell {
  min-height: calc(100vh - 4rem);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(560px, 100%);
  padding: 2rem;
  background: var(--panel);
  border: 1px solid rgba(215, 208, 193, 0.7);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}

.login-card h3 {
  margin: 0.35rem 0 0.6rem;
  font-size: 2rem;
  font-family: Georgia, "Times New Roman", serif;
}

.login-actions {
  justify-content: stretch;
}

.login-actions button {
  width: 100%;
}

.vault-grid {
  display: grid;
  gap: 0.9rem;
}

.vault-group-list {
  display: grid;
  gap: 1rem;
}

.vault-group {
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
  border-radius: 18px;
  border: 1px solid #ece4d5;
  background: linear-gradient(180deg, #fffdf9, #fbf6ee);
}

.vault-group-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  cursor: pointer;
  list-style: none;
}

.vault-group-head::-webkit-details-marker {
  display: none;
}

.vault-group-head h4 {
  margin: 0;
  font-size: 1.1rem;
}

.vault-group-meta {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.vault-group-toggle::after {
  content: "Abrir";
  color: var(--muted);
  font-size: 0.92rem;
}

.vault-group[open] .vault-group-toggle::after {
  content: "Fechar";
}

.vault-card {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: 18px;
  border: 1px solid #ece4d5;
  background: linear-gradient(180deg, #fffdf9, #fbf6ee);
}

.vault-line {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 0.7rem;
  align-items: center;
}

.vault-line code {
  padding: 0.6rem 0.75rem;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  overflow: auto;
}

body.auth-mode .main-shell {
  width: 100%;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.75rem;
}

.calendar-cell {
  min-height: 180px;
  padding: 0.8rem;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fff;
}

.calendar-cell strong {
  display: block;
  margin-bottom: 0.45rem;
}

.planning-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.planning-day-card {
  display: grid;
  gap: 0.9rem;
  min-height: auto;
  padding: 1rem;
  background: linear-gradient(180deg, #fffdf9, #f9f3e8);
}

.planning-day-head {
  display: grid;
  gap: 0.2rem;
}

.planning-day-head strong {
  margin: 0;
  text-transform: capitalize;
}

.planning-meta {
  font-size: 0.8rem;
}

.planning-description {
  min-height: 140px;
}

.planning-actions {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: 1fr 1fr;
}

.planning-actions button {
  width: 100%;
  min-width: 0;
}

.planning-foot {
  font-size: 0.82rem;
  padding-top: 0.2rem;
  border-top: 1px solid #ece4d5;
}

.campaign-picker-card {
  display: grid;
  gap: 0.6rem;
}

.campaign-picker-card p {
  margin: 0;
}

.month-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.65rem;
}

.calendar-weekday {
  padding: 0.6rem 0.4rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.calendar-day {
  min-height: 110px;
  align-items: flex-start;
  justify-content: flex-start;
  display: grid;
  gap: 0.35rem;
  padding: 0.8rem;
  background: #fff;
  color: var(--text);
  border: 1px solid #e8dfcf;
}

.calendar-day span {
  font-weight: 700;
}

.calendar-day small {
  text-align: left;
  color: var(--muted);
  line-height: 1.35;
}

.calendar-day.has-event {
  border-color: rgba(184, 92, 56, 0.42);
  background: linear-gradient(180deg, #fff9f2, #f5eadb);
}

.calendar-day.outside-month {
  opacity: 0.5;
}

.app-modal {
  width: min(780px, calc(100vw - 2rem));
  border: 0;
  border-radius: 26px;
  padding: 0;
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.24);
}

.app-modal::backdrop {
  background: rgba(11, 15, 13, 0.45);
}

.modal-head,
.modal-body {
  padding: 1rem 1.2rem;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.chat-log {
  display: grid;
  gap: 0.8rem;
  min-height: 520px;
  max-height: 60vh;
  overflow: auto;
}

.chat-item {
  padding: 0.95rem;
  border-radius: 18px;
  background: #fffaf2;
  border: 1px solid #eee2cc;
  max-width: 82%;
}

.chat-shell {
  padding: 1rem;
  border-radius: 22px;
  border: 1px solid #e8dfcf;
  background: linear-gradient(180deg, #fffefb, #f8f2e7);
}

.ai-layout {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(0, 1.8fr) minmax(320px, 0.95fr);
  align-items: start;
}

.ai-sidebar {
  display: grid;
  gap: 1rem;
}

.chat-card {
  min-height: 100%;
}

.chat-toolbar {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.chat-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.8rem;
}

.chat-composer {
  display: grid;
  gap: 0.9rem;
  margin-top: 1rem;
}

.chat-composer textarea {
  min-height: 110px;
  resize: vertical;
}

.chat-item.user {
  background: linear-gradient(180deg, #eadcc8, #e2cfb3);
  border-color: #dcc6a6;
  margin-left: auto;
}

.chat-item.assistant {
  background: #fff;
  margin-right: auto;
}

.chat-item strong {
  display: block;
  margin-bottom: 0.35rem;
}

.chat-info {
  display: grid;
  gap: 0.2rem;
  padding: 0.85rem 1rem;
  border-radius: 16px;
  border: 1px dashed #d9c6a5;
  background: rgba(255, 251, 243, 0.95);
  color: var(--muted);
}

.pre {
  white-space: pre-wrap;
}

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .ai-layout,
  .chat-toolbar {
    grid-template-columns: 1fr;
  }

  .chat-meta {
    flex-direction: column;
    align-items: stretch;
  }

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

  .span-5 {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .main-shell {
    padding: 1rem;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .calendar-grid {
    grid-template-columns: 1fr;
  }

  .month-calendar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .planning-actions {
    grid-template-columns: 1fr;
  }

  .patrimony-pagination {
    flex-direction: column;
    align-items: stretch;
  }

  .patrimony-pagination button {
    width: 100%;
  }

  .form-grid.cols-2,
  .form-grid.cols-3,
  .form-grid.cols-5 {
    grid-template-columns: 1fr;
  }

  .span-2,
  .span-3,
  .span-5 {
    grid-column: auto;
  }

  .form-actions,
  .form-actions.split {
    justify-content: stretch;
  }

  .form-actions button {
    width: 100%;
  }
}
