:root {
  --bg: #f5f7f4;
  --panel: #ffffff;
  --panel-soft: #eef3ee;
  --line: #d8ded6;
  --text: #17201c;
  --muted: #637066;
  --ink: #10221d;
  --accent: #17765f;
  --accent-strong: #0f5d4b;
  --blue: #2d65b8;
  --amber: #b87812;
  --red: #b34842;
  --shadow: 0 18px 45px rgba(22, 32, 27, 0.12);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, rgba(23, 118, 95, 0.14), transparent 44%),
    linear-gradient(310deg, rgba(45, 101, 184, 0.12), transparent 48%),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  gap: 18px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-brand {
  align-items: flex-start;
}

.brand-logo {
  display: block;
  object-fit: contain;
  flex: 0 0 auto;
}

.login-logo {
  width: 170px;
  max-width: 45%;
  height: auto;
  margin-top: 2px;
}

.sidebar-logo {
  width: 96px;
  height: 42px;
  padding: 6px;
  border-radius: var(--radius);
  background: #fff;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ink);
  color: white;
  font-weight: 800;
  letter-spacing: 0;
}

.login-panel h1 {
  margin: 0;
  font-size: 1.42rem;
}

.login-panel p {
  margin: 4px 0 0;
  color: var(--muted);
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 10px 11px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 92px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 118, 95, 0.14);
}

.primary-button,
.secondary-button,
.ghost-button,
.table-button {
  border: 1px solid transparent;
  border-radius: var(--radius);
  min-height: 40px;
  padding: 0 14px;
  font-weight: 750;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-button {
  background: var(--accent);
  color: white;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  background: #e9f2ee;
  color: var(--accent-strong);
  border-color: #cbe1d8;
}

.ghost-button,
.table-button {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.table-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.9rem;
}

.danger {
  color: var(--red);
}

.form-error {
  margin: 0;
  color: var(--red);
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
}

.sidebar {
  background: #111b18;
  color: white;
  min-height: 100vh;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
}

.sidebar .brand-mark {
  background: #eaf6ef;
  color: #12251f;
}

.sidebar-brand {
  padding: 4px 4px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-brand small,
.sidebar-footer small {
  display: block;
  color: rgba(255, 255, 255, 0.62);
  margin-top: 2px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-list button {
  min-height: 42px;
  text-align: left;
  border: 0;
  border-radius: var(--radius);
  color: rgba(255, 255, 255, 0.78);
  background: transparent;
  padding: 0 12px;
  font-weight: 700;
}

.nav-list button.active,
.nav-list button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 16px;
  display: grid;
  gap: 12px;
}

.sidebar-footer .ghost-button {
  color: white;
  border-color: rgba(255, 255, 255, 0.2);
}

.main-area {
  min-width: 0;
}

.topbar {
  height: 92px;
  padding: 18px 26px;
  background: rgba(245, 247, 244, 0.88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  position: sticky;
  top: 0;
  z-index: 5;
}

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

.kicker {
  color: var(--muted);
  margin: 0 0 2px;
  font-weight: 700;
}

.top-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.content-area {
  padding: 24px 26px 42px;
  display: grid;
  gap: 18px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.toolbar.with-extra {
  grid-template-columns: minmax(220px, 1fr) minmax(150px, 220px) auto auto;
}

.toolbar.compact {
  grid-template-columns: minmax(220px, 1fr) auto;
}

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

.metric-card,
.data-panel,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric-card {
  padding: 16px;
  min-height: 116px;
  display: grid;
  align-content: space-between;
}

.metric-card small {
  color: var(--muted);
  font-weight: 750;
}

.metric-card strong {
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.metric-card span {
  color: var(--muted);
  font-weight: 650;
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 14px;
}

.data-panel {
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header h3 {
  margin: 0;
  font-size: 1rem;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #fbfcfb;
}

tbody tr:hover {
  background: #f9fbf8;
}

.cell-title {
  font-weight: 800;
  color: var(--ink);
}

.cell-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.78rem;
  color: #0d1a16;
  background: #edf1ee;
  white-space: nowrap;
}

.badge.green {
  color: #075744;
  background: #dff3eb;
}

.badge.blue {
  color: #1d4f93;
  background: #e4efff;
}

.badge.amber {
  color: #754900;
  background: #fff0cf;
}

.badge.red {
  color: #8c2e2b;
  background: #fde7e4;
}

.badge.gray {
  color: #4e5a53;
  background: #edf0ed;
}

.money-positive {
  color: #086447;
  font-weight: 800;
}

.money-negative {
  color: var(--red);
  font-weight: 800;
}

.status-stack {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.status-row {
  display: grid;
  grid-template-columns: 120px 1fr 38px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-weight: 700;
}

.status-track,
.chart-track {
  height: 10px;
  border-radius: 999px;
  background: #e7ebe6;
  overflow: hidden;
}

.status-fill,
.chart-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.chart-list {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.chart-row {
  display: grid;
  grid-template-columns: 72px minmax(160px, 1fr) 116px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-weight: 700;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.whatsapp-settings-form {
  padding: 16px;
}

.whatsapp-settings-form .cell-sub {
  margin-top: 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(13, 24, 19, 0.5);
  display: grid;
  place-items: center;
  padding: 22px;
}

.modal-panel {
  width: min(880px, 100%);
  max-height: min(86vh, 900px);
  overflow: auto;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
}

.modal-close {
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 900;
}

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

.entity-form .wide {
  grid-column: 1 / -1;
}

.checkbox-label {
  grid-template-columns: auto 1fr;
  align-items: center;
  justify-content: start;
  gap: 10px;
  min-height: 42px;
}

.checkbox-label input {
  width: auto;
}

.task-check {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--ink);
  font-weight: 800;
}

.task-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.completed-title {
  color: var(--muted);
  text-decoration: line-through;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  background: var(--ink);
  color: white;
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-weight: 750;
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

  .sidebar {
    position: static;
    min-height: auto;
    padding: 14px;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .nav-list button {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .sidebar-footer {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .topbar {
    position: static;
    height: auto;
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar,
  .toolbar.with-extra,
  .toolbar.compact {
    grid-template-columns: 1fr;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions > * {
    flex: 1;
  }
}

@media (max-width: 640px) {
  body {
    background: #eef3ee;
  }

  input,
  select,
  textarea {
    min-height: 44px;
  }

  .login-screen {
    padding: 14px;
  }

  .login-panel {
    padding: 20px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .login-brand {
    align-items: center;
  }

  .login-logo {
    width: 142px;
    max-width: 48%;
  }

  .sidebar-logo {
    width: 88px;
    height: 38px;
  }

  .sidebar-brand {
    padding-bottom: 10px;
  }

  .nav-list button {
    min-height: 40px;
    padding: 0 11px;
  }

  .content-area,
  .topbar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar h2 {
    font-size: 1.32rem;
  }

  .kpi-grid,
  .entity-form {
    grid-template-columns: 1fr;
  }

  .chart-row {
    grid-template-columns: 64px 1fr;
  }

  .chart-row strong {
    grid-column: 2;
  }

  .metric-card {
    min-height: 96px;
  }

  .data-panel {
    overflow: visible;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
    padding: 10px;
    background: #f7faf6;
  }

  tbody tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: minmax(88px, 36%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    border-bottom: 1px solid var(--line);
    padding: 10px;
    min-height: 42px;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 850;
    text-transform: uppercase;
  }

  .actions {
    justify-content: flex-start;
  }

  .table-button {
    min-height: 38px;
  }

  .modal-backdrop {
    align-items: end;
    padding: 0;
  }

  .modal-panel {
    width: 100%;
    max-height: 92vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .form-actions {
    position: sticky;
    bottom: 0;
    background: var(--panel);
    border-top: 1px solid var(--line);
    padding: 12px 0 0;
  }

  .form-actions button {
    flex: 1;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }
}

html.is-mobile body {
  background: #eef3ee;
}

html.is-mobile,
html.is-mobile body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

html.is-mobile input,
html.is-mobile select,
html.is-mobile textarea {
  min-height: 44px;
}

html.is-mobile .app-shell {
  grid-template-columns: 1fr;
  width: 100vw;
  max-width: 100vw;
  min-width: 0;
  overflow-x: hidden;
}

html.is-mobile .sidebar {
  position: static;
  min-height: auto;
  padding: 14px;
  width: 100vw;
  max-width: 100vw;
}

html.is-mobile .sidebar-brand {
  padding-bottom: 10px;
}

html.is-mobile .nav-list {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding-bottom: 2px;
  width: calc(100vw - 28px);
  max-width: calc(100vw - 28px);
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}

html.is-mobile .nav-list button {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 11px;
  white-space: nowrap;
}

html.is-mobile .sidebar-footer {
  grid-template-columns: 1fr auto;
  align-items: center;
}

html.is-mobile .main-area {
  width: 100vw;
  max-width: 100vw;
  min-width: 0;
  overflow-x: hidden;
}

html.is-mobile .topbar {
  position: static;
  height: auto;
  align-items: stretch;
  flex-direction: column;
  padding-left: 12px;
  padding-right: 12px;
  width: 100vw;
  max-width: 100vw;
  min-width: 0;
}

html.is-mobile .topbar h2 {
  font-size: 1.32rem;
}

html.is-mobile .content-area {
  padding-left: 12px;
  padding-right: 12px;
  width: 100vw;
  max-width: 100vw;
  min-width: 0;
  overflow-x: hidden;
}

html.is-mobile .toolbar,
html.is-mobile .toolbar.with-extra,
html.is-mobile .toolbar.compact {
  grid-template-columns: 1fr;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

html.is-mobile .toolbar > * {
  max-width: 100%;
  min-width: 0;
}

html.is-mobile .top-actions {
  width: 100%;
}

html.is-mobile .top-actions > * {
  flex: 1;
}

html.is-mobile .kpi-grid,
html.is-mobile .entity-form {
  grid-template-columns: 1fr;
}

html.is-mobile .metric-card {
  min-height: 96px;
}

html.is-mobile .panel-grid {
  grid-template-columns: 1fr;
}

html.is-mobile .data-panel,
html.is-mobile .table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: visible;
}

html.is-mobile table,
html.is-mobile thead,
html.is-mobile tbody,
html.is-mobile tr,
html.is-mobile th,
html.is-mobile td {
  display: block;
}

html.is-mobile table {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

html.is-mobile thead {
  display: none;
}

html.is-mobile tbody {
  display: grid;
  gap: 10px;
  padding: 10px;
  background: #f7faf6;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

html.is-mobile tbody tr {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

html.is-mobile td {
  display: grid;
  grid-template-columns: minmax(88px, 36%) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  min-height: 42px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
}

html.is-mobile td:last-child {
  border-bottom: 0;
}

html.is-mobile td::before {
  content: attr(data-label);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 850;
  text-transform: uppercase;
}

html.is-mobile .chart-row {
  grid-template-columns: 64px 1fr;
}

html.is-mobile .chart-row strong {
  grid-column: 2;
}

html.is-mobile .actions {
  justify-content: flex-start;
}

html.is-mobile .table-button {
  min-height: 38px;
}

html.is-mobile .modal-backdrop {
  align-items: end;
  padding: 0;
}

html.is-mobile .modal-panel {
  width: 100%;
  max-height: 92vh;
  border-radius: var(--radius) var(--radius) 0 0;
}

html.is-mobile .form-actions {
  position: sticky;
  bottom: 0;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 12px 0 0;
}

html.is-mobile .form-actions button {
  flex: 1;
}

html.is-mobile .toast {
  left: 12px;
  right: 12px;
  bottom: 12px;
}
