:root {
  --bg: #f5f7f2;
  --panel: #ffffff;
  --ink: #18211f;
  --muted: #68746f;
  --line: #dfe7df;
  --primary: #0f6b5d;
  --primary-dark: #09483f;
  --accent: #d8ed73;
  --danger: #b83245;
  --shadow: 0 16px 40px rgba(28, 44, 38, .10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

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

button,
input,
select {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-left)) 12px max(16px, env(safe-area-inset-right));
  background: rgba(245, 247, 242, .92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand,
.nav-actions,
.nav-actions form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  font-weight: 800;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: #fff;
  background: var(--primary);
  border-radius: 8px;
}

.nav-actions a,
.nav-actions button,
.secondary-link {
  min-height: 38px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.nav-actions button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px 14px 104px;
}

.center-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.flash {
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #e7f6ee;
  border: 1px solid #b8e1ca;
}

.flash.error {
  background: #fdecee;
  border-color: #f5bbc4;
}

.login-panel {
  width: min(420px, 100%);
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.eyebrow,
.hint,
.muted,
small {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(1.55rem, 7vw, 2.35rem);
}

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

.form-grid,
.optional-fields,
.filters {
  display: grid;
  gap: 12px;
}

label span,
.field-title {
  display: block;
  margin-bottom: 7px;
  font-size: .88rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 48px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.primary-btn {
  display: inline-grid;
  place-items: center;
  min-height: 52px;
  padding: 12px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.hello-row,
.page-title,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.title-actions,
.report-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.title-actions .primary-btn {
  text-decoration: none;
}

.dashboard-actions,
.stats-grid {
  display: grid;
  gap: 14px;
}

.dashboard-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 16px 0 20px;
}

.action-card,
.stat-card {
  display: grid;
  gap: 8px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.action-card {
  color: var(--ink);
}

.action-card strong,
.stat-card strong {
  font-size: 1.05rem;
}

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

.stat-card span {
  color: var(--muted);
  font-size: .9rem;
}

.today-card {
  min-width: 128px;
  padding: 12px;
  background: var(--primary-dark);
  color: #fff;
  border-radius: 8px;
}

.today-card span,
.today-card small {
  display: block;
  color: rgba(255,255,255,.74);
}

.today-card strong {
  display: block;
  margin: 4px 0;
  font-size: 1.35rem;
}

.touch-form {
  display: grid;
  gap: 16px;
  margin: 12px 0 22px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  background: #edf2ed;
  border-radius: 8px;
}

.segmented button,
.quick-weights button,
.chip {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}

.segmented .active {
  background: var(--primary);
  color: #fff;
}

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

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

.chip {
  border-color: color-mix(in srgb, var(--chip-color, var(--line)) 35%, var(--line));
}

.chip.selected {
  background: color-mix(in srgb, var(--chip-color, var(--primary)) 18%, #fff);
  border-color: var(--chip-color, var(--primary));
  box-shadow: inset 0 0 0 2px var(--chip-color, var(--primary));
}

.chip:disabled {
  opacity: .38;
  cursor: not-allowed;
  box-shadow: none;
}

.progressive-section {
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: background .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.progressive-section summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
}

.progressive-section summary::-webkit-details-marker {
  display: none;
}

.progressive-label {
  display: block;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
}

.progressive-value {
  display: block;
  margin-left: auto;
  font-size: .98rem;
  text-align: right;
}

.progressive-section summary::after {
  content: '+';
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #eef3ef;
  color: var(--primary-dark);
  font-size: 1rem;
  font-weight: 900;
  flex-shrink: 0;
}

.progressive-section:not([open]) {
  background: color-mix(in srgb, var(--section-color, var(--panel)) 12%, #fff);
  border-color: color-mix(in srgb, var(--section-color, var(--line)) 28%, var(--line));
}

.progressive-section:not([open]) summary::after {
  background: color-mix(in srgb, var(--section-color, #eef3ef) 18%, #eef3ef);
}

.progressive-section[open] summary::after {
  content: '-';
}

.progressive-body {
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
}

.weight-panel {
  display: grid;
  gap: 10px;
}

.weight-panel input {
  min-height: 64px;
  font-size: 1.8rem;
  font-weight: 800;
}

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

.submit-btn {
  min-height: 58px;
  font-size: 1.05rem;
}

.section-grid {
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 16px;
}

.section-heading {
  margin: 12px 0 8px;
}

.section-heading span,
.section-heading a {
  color: var(--muted);
  font-size: .9rem;
}

.balance-list,
.pending-list,
.movement-list,
.history-table {
  display: grid;
  gap: 8px;
}

.history-sections {
  display: grid;
  gap: 12px;
}

.history-accordion {
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.history-accordion summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

.history-accordion summary::after {
  content: '+';
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #eef3ef;
  color: var(--primary-dark);
  font-size: 1rem;
  font-weight: 900;
  flex-shrink: 0;
}

.history-accordion[open] summary::after {
  content: '-';
}

.history-accordion summary::-webkit-details-marker {
  display: none;
}

.history-accordion summary small {
  color: var(--muted);
  font-weight: 700;
}

.history-accordion .history-table {
  padding: 0 10px 10px;
}

.pending-item,
.balance-item,
.movement-item,
.history-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pending-item {
  cursor: pointer;
}

.pending-item.tinted {
  background: color-mix(in srgb, var(--item-color, var(--primary)) 10%, #fff);
  border-color: color-mix(in srgb, var(--item-color, var(--primary)) 28%, var(--line));
}

.pending-item input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  margin: 0;
  accent-color: var(--primary);
}

.pending-item small {
  display: block;
}

.balance-item strong,
.movement-item strong,
.history-row strong {
  display: block;
}

.dot {
  width: 12px;
  height: 42px;
  border-radius: 99px;
}

.movement-type {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #e7f6ee;
  color: var(--primary);
  font-weight: 900;
}

.movement-type.retirada {
  background: #fdecee;
  color: var(--danger);
}

.filters {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  margin: 14px 0;
}

.history-filters {
  gap: 10px;
}

.filter-row {
  display: grid;
  gap: 12px;
}

.filter-row-dates {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.filter-row-actions {
  grid-template-columns: 1fr;
  align-items: end;
}

.filter-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.filter-inline .primary-btn {
  min-width: 132px;
}

.history-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.history-main {
  display: grid;
  gap: 2px;
}

.history-side {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.history-row p {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  min-width: 38px;
  min-height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.icon-btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 28%, var(--line));
  background: color-mix(in srgb, var(--danger) 8%, #fff);
}

.report-page {
  display: grid;
  gap: 18px;
  color: #111;
  min-width: 0;
  overflow-x: hidden;
}

.report-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid #222;
  min-width: 0;
}

.report-group {
  break-inside: avoid;
  page-break-inside: avoid;
  min-width: 0;
}

.pending-groups {
  display: grid;
  gap: 18px;
}

.pending-group {
  display: grid;
  gap: 10px;
}

.pending-group-title {
  margin: 0;
}

.pending-group-title h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bottom-tabs {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  width: min(420px, calc(100% - 20px));
  padding: 6px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.96), rgba(241, 246, 241, .96));
  backdrop-filter: blur(18px);
  border: 1px solid rgba(203, 215, 207, .95);
  border-radius: 20px;
  box-shadow: 0 18px 40px rgba(17, 35, 30, .16);
  transform: translateX(-50%);
}

.bottom-tab {
  display: grid;
  place-items: center;
  min-height: 46px;
  padding: 5px 8px;
  border-radius: 12px;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .01em;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}

.bottom-tab.active {
  color: var(--primary-dark);
  background: rgba(15, 107, 93, .10);
  transform: translateY(-1px);
}

.report-group h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  padding: 8px 0;
}

.report-color {
  width: 12px;
  height: 24px;
  border-radius: 99px;
}

.report-table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.report-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  background: #fff;
  font-size: .88rem;
}

.report-table th,
.report-table td {
  padding: 8px;
  border: 1px solid #cfd6d1;
  text-align: left;
  vertical-align: top;
}

.report-table thead th,
.report-table tfoot th {
  background: #edf2ed;
}

.report-table .num {
  text-align: right;
  white-space: nowrap;
}

.empty {
  margin: 0;
  padding: 16px;
  color: var(--muted);
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
  }

  .nav-actions {
    gap: 6px;
  }

  .hello-row,
  .page-title {
    align-items: flex-start;
  }

  .section-grid,
  .filters,
  .dashboard-actions,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .filter-inline {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    /* grid-template-columns: 1fr; */
  }

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

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

  .report-header {
    display: grid;
    min-width: 0;
  }
}

@media (max-width: 420px) {
  .brand span:last-child {
    display: none;
  }

  .balance-item,
  .movement-item,
  .pending-item {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .balance-item b,
  .movement-item b,
  .pending-item b {
    grid-column: 2;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  body {
    background: #fff;
  }

  .topbar,
  .bottom-tabs,
  .report-actions,
  .flash {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    max-width: none;
    padding: 0;
  }

  .report-header {
    margin-bottom: 8px;
  }

  .report-table-wrap {
    overflow: visible;
  }

  .report-table {
    min-width: 0;
    font-size: 10px;
  }

  .report-table th,
  .report-table td {
    padding: 5px;
  }
}
