:root {
  --bg: #f7f6f2;
  --panel: #ffffff;
  --ink: #202124;
  --muted: #687076;
  --line: #d8d5cc;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --success: #166534;
  --soft: #eef4f3;
  --soft-warm: #fff8e8;
  --shadow: 0 10px 28px rgba(31, 35, 40, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

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

a {
  color: inherit;
  text-decoration: none;
}

.app {
  width: min(1320px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.app.narrow {
  width: min(720px, calc(100% - 32px));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.brand h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.1;
  font-weight: 760;
}

.brand p {
  margin: 7px 0 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-radius: 7px;
  background: #e9e5da;
  color: var(--ink);
  font-weight: 740;
  border: 1px solid #d6d0c2;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: #dfdacd;
}

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

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

.btn.danger {
  background: #fff2ef;
  border-color: #ffd5cc;
  color: var(--danger);
}

.btn.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 14px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.62fr);
  gap: 18px;
  align-items: start;
}

.grid > *,
.two-col > *,
.panel,
.stack {
  min-width: 0;
}

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

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

.narrow-panel {
  width: min(620px, 100%);
}

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

.panel-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 760;
}

.panel-body {
  padding: 18px;
}

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

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

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

.field.span-4 {
  grid-column: span 4;
}

.align-end {
  align-content: end;
}

.field label {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 780;
}

.field input,
.field select,
.field textarea,
.row-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cfcac0;
  border-radius: 7px;
  padding: 9px 10px;
  color: var(--ink);
  background: white;
  outline: none;
}

.field textarea {
  min-height: 180px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.row-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.13);
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: white;
}

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

th {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 800;
  background: #faf9f5;
}

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

td.calc,
.mono {
  font-variant-numeric: tabular-nums;
  font-weight: 720;
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  background: #fffefa;
  min-height: 86px;
}

.metric .label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 780;
  margin-bottom: 6px;
}

.metric .value {
  font-size: 24px;
  line-height: 1.1;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.metric .sub {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.metric.total {
  background: var(--soft);
  border-color: #b8d9d4;
}

.metric.internal {
  background: var(--soft-warm);
  border-color: #f2d391;
}

.sheet-preview {
  position: relative;
  width: min(100%, 330px);
  margin: 0 auto;
  aspect-ratio: 12 / 18;
  border: 2px solid #858078;
  background: #fbfaf5;
  border-radius: 4px;
  overflow: hidden;
}

.sheet-margin {
  position: absolute;
  border: 1px dashed #b8b1a6;
  background: rgba(15, 118, 110, 0.05);
}

.tile {
  position: absolute;
  border: 1px solid rgba(15, 118, 110, 0.68);
  background: rgba(15, 118, 110, 0.18);
  border-radius: 2px;
}

.whatsapp-text {
  min-height: 190px;
}

.alert {
  padding: 11px 12px;
  border-radius: var(--radius);
  border: 1px solid #d9ead7;
  background: #f3fbf1;
  color: var(--success);
  font-weight: 680;
  margin-bottom: 12px;
}

.alert.danger {
  border-color: #ffd5cc;
  background: #fff6f4;
  color: var(--danger);
}

.status {
  min-height: 20px;
  color: var(--accent-strong);
  font-weight: 700;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

@media (max-width: 1400px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app {
    width: min(100% - 20px, 1320px);
    padding-top: 14px;
  }

  .topbar {
    display: grid;
  }

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

  .top-actions .btn {
    flex: 1 1 130px;
  }

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

  .field.span-2,
  .field.span-4 {
    grid-column: span 1;
  }
}
