:root {
  --bg-a: #f8efe7;
  --bg-b: #f5f8ef;
  --surface: #ffffff;
  --text: #2b2d33;
  --muted: #5f6470;
  --line: #e4dccf;
  --accent: #176b58;
  --accent-soft: #dff0ea;
  --danger: #b24630;
  --ok: #137548;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, var(--bg-a), transparent 40%),
    radial-gradient(circle at bottom right, var(--bg-b), transparent 45%),
    #f7f5f1;
}

.app-shell {
  width: min(980px, 94vw);
  margin: 24px auto 60px;
  display: grid;
  gap: 16px;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-gate-card {
  width: min(560px, 94vw);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 18px 40px rgba(48, 39, 22, 0.12);
}

.auth-gate-card h1 {
  margin: 0;
  font-size: clamp(1.45rem, 4vw, 2rem);
}

.auth-gate-card p {
  margin: 8px 0 14px;
  color: var(--muted);
}

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

.auth-gate-actions {
  margin-top: 10px;
}

.screen-view {
  display: grid;
  gap: 16px;
}

.hidden-screen {
  display: none;
}

.hero {
  background: linear-gradient(120deg, #fffaf3, #f0f7f4);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.hero-actions {
  display: grid;
  gap: 8px;
}

.hero p {
  margin: 8px 0 0;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.94rem;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid #ccc6ba;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

.primary {
  background: var(--accent);
  color: #fff;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.secondary {
  background: #f3efe6;
  color: var(--text);
  border: 1px solid #d3cab9;
}

.primary:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

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

.form-grid > button {
  grid-column: 1 / -1;
}

.grid-two {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-filters {
  max-width: 460px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.kpi {
  background: #faf8f4;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.kpi strong {
  display: block;
  margin-top: 4px;
  font-size: 1.12rem;
}

.stack {
  display: grid;
  gap: 10px;
}

.row {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.row-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
}

.badge.ok {
  background: #e5f5ec;
  color: var(--ok);
  border-color: #b5dcc6;
}

.badge.pending {
  background: #fff3e9;
  color: var(--danger);
  border-color: #f1d4bf;
}

.inline-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.auth-actions {
  margin: 10px 0;
}

.top-actions {
  margin-top: 12px;
}

.month-grid-toolbar {
  display: grid;
  gap: 10px;
}

#authStatus {
  display: block;
}

.inline-controls input[type="date"] {
  max-width: 180px;
}

.projection-line {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 7px;
}

.projection-scroll {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.projection-table-head,
.projection-table-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  align-items: center;
  padding: 10px;
}

.projection-table-head {
  background: #f7f4ee;
  font-size: 0.82rem;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1;
}

.projection-table-body {
  max-height: 300px;
  overflow: auto;
}

.projection-table-row {
  border-bottom: 1px dashed var(--line);
  background: #fffdfa;
}

.projection-table-row:last-child {
  border-bottom: 0;
}

.sidmar-projection-head,
.sidmar-projection-row {
  grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
}

.sidmar-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.sidmar-form {
  margin-bottom: 12px;
}

.sidmar-payment-row {
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
}

.sidmar-payment-row > button {
  grid-column: auto;
  height: 42px;
  white-space: nowrap;
}

.sidmar-grid-actions {
  margin: 10px 0;
}

.sidmar-scroll {
  margin-top: 8px;
}

.sidmar-month-grid-header,
.sidmar-month-grid-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 0.8fr 0.8fr;
  gap: 8px;
  align-items: center;
}

.sidmar-month-grid-header {
  font-size: 0.84rem;
  color: #3f443f;
  background: #edf5f2;
  font-weight: 600;
  border-bottom: 1px solid #d9e7e1;
  padding: 10px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.sidmar-month-grid {
  display: grid;
  gap: 0;
  max-height: 280px;
  overflow: auto;
}

.sidmar-month-grid-row {
  border-bottom: 1px solid #ece7dc;
  padding: 10px;
  background: #fff;
}

.sidmar-month-grid-row:last-child {
  border-bottom: 0;
}

.sidmar-month-grid-row.residual-item {
  background: #fff7ec;
}

.month-grid-header,
.month-grid-row {
  display: grid;
  grid-template-columns: 1.2fr 0.7fr 0.8fr 1fr 0.8fr 0.7fr 1fr 1fr;
  gap: 8px;
  align-items: center;
}

.month-grid-shell {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  max-height: 430px;
  background: #fff;
}

.month-grid-header {
  font-size: 0.84rem;
  color: #3f443f;
  background: #edf5f2;
  font-weight: 600;
  border-bottom: 1px solid #d9e7e1;
  padding: 10px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.month-grid {
  display: grid;
  gap: 0;
}

.month-grid-row {
  border: 0;
  border-bottom: 1px solid #ece7dc;
  padding: 10px;
  background: #fff;
}

.month-grid-row.is-paid {
  background: #f3fbf6;
}

.month-grid-row.is-paid strong {
  color: #1f5f46;
}

.month-grid-row:last-child {
  border-bottom: 0;
}

.month-grid-row strong {
  font-size: 0.95rem;
}

.actions-cell {
  display: flex;
  gap: 6px;
  align-items: center;
}

.icon-btn {
  min-width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid #d3cab9;
  background: #f8f4eb;
  color: #2b2d33;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.icon-btn.status {
  background: #e9f6ef;
  border-color: #c2e3d0;
}

.icon-btn.delete {
  background: #fff2ec;
  border-color: #f1d3c6;
}

.cell-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.cell-date input {
  max-width: 160px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(36, 34, 28, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}

.modal-backdrop.show {
  display: flex;
}

.modal-panel {
  width: min(760px, 96vw);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.muted {
  color: var(--muted);
  margin-top: -5px;
}

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

@media (max-width: 760px) {
  .form-grid,
  .grid-two,
  .summary,
  .sidmar-kpis {
    grid-template-columns: 1fr;
  }

  .sidmar-payment-row > button {
    grid-column: 1 / -1;
    height: auto;
  }

  .month-grid-header {
    display: none;
  }

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

  .month-grid-row {
    grid-template-columns: 1fr;
  }

  .month-grid-row > div::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    color: var(--muted);
    margin-bottom: 2px;
  }

  .projection-table-head,
  .projection-table-row {
    grid-template-columns: 1fr;
  }

  .sidmar-projection-head,
  .sidmar-projection-row {
    grid-template-columns: 1fr;
  }

  .sidmar-month-grid-header {
    display: none;
  }

  .sidmar-month-grid-row {
    grid-template-columns: 1fr;
  }

  .sidmar-month-grid-row > div::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    color: var(--muted);
    margin-bottom: 2px;
  }

  .projection-table-row > div::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    color: var(--muted);
    margin-bottom: 2px;
  }

  .app-shell {
    width: min(680px, 94vw);
  }
}
