:root {
  --c1: #2d6760;
  --c2: #768e42;
  --c3: #d2e8dd;
  --c4: #79bbb5;
  --c5: #cec295;
  --c6: #5d7c89;
  --c7: #9ab1ba;
  --c8: #9abc50;
  --ink: #1f2937;
  --white: #ffffff;
  --topbar-h: 73px;
}

* { box-sizing: border-box; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  color: var(--ink);
  background: linear-gradient(140deg, var(--c3) 0%, #e8f3ef 48%, #f7f7f3 100%);
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
}

img,
svg {
  max-width: 100%;
}

.login-body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: min(92vw, 520px) !important;
  margin: 0 auto !important;
}

html.no-scroll,
body.no-scroll { overflow: hidden !important; }

.layout {
  min-height: calc(100dvh - var(--topbar-h));
  width: 100%;
  max-width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--topbar-h);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  justify-content: flex-end;
}

.topbar-welcome {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(42vw, 520px);
}

.menu-toggle {
  width: 2.5rem !important;
  min-width: 2.5rem !important;
  height: 2.5rem !important;
  min-height: 2.5rem !important;
  padding: 0 !important;
  border-radius: 0.7rem;
  border: 1px solid var(--c7) !important;
  background: #fff !important;
  color: #2f4a58 !important;
  box-shadow: 0 4px 12px rgba(93, 124, 137, 0.14);
}

.menu-toggle:hover {
  border-color: var(--c4) !important;
  background: #f0f7f5 !important;
  color: var(--c1) !important;
}

.menu-toggle-icon {
  display: inline-block;
  width: 1.1rem;
  height: 2px;
  border-radius: 99px;
  background: currentColor;
  position: relative;
}

.menu-toggle-icon::before,
.menu-toggle-icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 1.1rem;
  height: 2px;
  border-radius: 99px;
  background: currentColor;
}

.menu-toggle-icon::before { top: -0.34rem; }
.menu-toggle-icon::after { top: 0.34rem; }

.menu {
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: transform 0.25s ease, opacity 0.25s ease;
  min-height: 0;
}

.menu button {
  width: 100%;
  text-align: left;
  border-radius: 0.75rem;
  border: 1px solid var(--c7);
  background: var(--white);
  color: #2f4a58 !important;
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.18s ease;
}

.menu button:hover {
  background: #f3f8f7;
  border-color: var(--c4);
}

.menu button.active {
  background: var(--c1);
  border-color: var(--c1);
  color: #fff !important;
  box-shadow: 0 10px 20px rgba(45, 103, 96, 0.22);
}

.content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.panel { display: none; }
.panel.active {
  display: block;
  animation: panelEnter 180ms ease-out;
  min-width: 0;
  width: 100%;
}

.panel > * {
  max-width: 100%;
}

#paymentForm,
#expenseForm,
#conceptForm,
#userForm,
#parcelForm,
#representativeForm,
#profileForm {
  width: 100% !important;
  max-width: none !important;
}

@keyframes panelEnter {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

h3 {
  margin: 0.9rem 0 0.55rem;
  font-size: 1rem;
  font-weight: 700;
  color: #214a57;
}

.section-head {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.section-head h3 {
  margin: 0;
}

.grid-form > h3 {
  grid-column: 1 / -1;
  margin-top: 0.25rem;
  padding-top: 0.35rem;
  border-top: 1px solid rgba(154, 177, 186, 0.45);
}

.listing-title {
  margin-top: 1.25rem;
  margin-bottom: 0.7rem;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--c1);
}

.grid-form {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 0.9rem;
}

.form-vertical {
  width: 100%;
  max-width: none;
}

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

#paymentForm .file-upload-group,
#paymentForm button[type="submit"],
#expenseForm button[type="submit"],
#profileForm .form-actions,
#parcelForm .form-actions,
#userForm .form-actions,
#representativeForm .form-actions {
  grid-column: 1 / -1;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.inline-form > * {
  flex: 1 1 220px;
}

.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.inline-form .inline-field {
  flex: 1 1 240px;
}

.inline-form .inline-field select {
  width: 100%;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.8rem;
}

.subpanel {
  border: 1px solid var(--c7);
  border-radius: 0.75rem;
  background: #f3f8f7;
  padding: 0.75rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #2f4a58;
}

input, select, button {
  font: inherit;
  border-radius: 0.65rem;
  line-height: 1.2;
}

input,
select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--c7);
  background: var(--white);
  color: #24414d;
  min-height: 2.75rem !important;
  width: 100% !important;
  padding: 0.65rem 0.95rem !important;
  text-indent: 0 !important;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.35 !important;
  outline: none;
  box-sizing: border-box !important;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

select {
  padding-right: 2.2rem !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='%235d7c89' d='M5.6 7.4a1 1 0 0 1 1.4 0L10 10.4l3-3a1 1 0 1 1 1.4 1.4l-3.7 3.7a1 1 0 0 1-1.4 0L5.6 8.8a1 1 0 0 1 0-1.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.72rem center;
  background-size: 0.95rem;
}

textarea {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--c7);
  background: var(--white);
  color: #24414d;
  min-height: 2.75rem !important;
  width: 100% !important;
  padding: 0.65rem 0.95rem !important;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.35 !important;
  border-radius: 0.65rem;
  outline: none;
  box-sizing: border-box !important;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

input::placeholder {
  color: #87a0aa;
  font-weight: 500;
}

textarea::placeholder {
  color: #87a0aa;
  font-weight: 500;
}

input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder {
  color: #87a0aa;
  font-weight: 500;
}

input::-moz-placeholder,
textarea::-moz-placeholder {
  color: #87a0aa;
  font-weight: 500;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--c1);
  box-shadow: 0 0 0 3px rgba(45, 103, 96, 0.15);
  background: #fff;
}

button,
.btn {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 2.75rem !important;
  padding: 0.65rem 1.05rem;
  border: 1px solid var(--c1);
  border-radius: 0.7rem;
  background: linear-gradient(180deg, #2f746c 0%, var(--c1) 100%);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  box-shadow: 0 8px 20px rgba(45, 103, 96, 0.2);
  transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.08s ease;
}

button:hover,
.btn:hover {
  background: linear-gradient(180deg, #2a6861 0%, #245a54 100%);
  border-color: #245a54;
  box-shadow: 0 12px 24px rgba(45, 103, 96, 0.25);
}

button:active,
.btn:active {
  transform: translateY(1px);
  box-shadow: 0 5px 14px rgba(45, 103, 96, 0.2);
}

button.ghost,
.btn.ghost {
  background: #fff !important;
  color: #2f4a58 !important;
  border-color: var(--c7);
  box-shadow: 0 4px 10px rgba(93, 124, 137, 0.12);
}

button.ghost:hover,
.btn.ghost:hover {
  background: #f0f7f5 !important;
  color: var(--c1);
  border-color: var(--c4);
  box-shadow: 0 8px 16px rgba(93, 124, 137, 0.16);
}

button[disabled],
.btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

button:focus-visible,
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(45, 103, 96, 0.16);
}

.inline-form input,
.inline-form select {
  min-width: 220px;
}

.inline-form button,
.inline-form .btn {
  flex: 0 0 auto;
  min-width: 9.25rem;
}

.filter-btn {
  min-width: 9.25rem !important;
  padding-inline: 1.15rem !important;
  color: #fff !important;
}

.form-actions button,
.form-actions .btn {
  min-width: 10.5rem;
}

.topbar-actions .btn,
.topbar-actions button {
  min-width: 6.5rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.form-actions button[type="submit"],
.form-actions .btn:not(.ghost) {
  background: linear-gradient(180deg, #2f746c 0%, var(--c1) 100%) !important;
  border-color: var(--c1) !important;
  color: #fff !important;
  box-shadow: 0 10px 22px rgba(45, 103, 96, 0.24);
}

.form-actions button[type="submit"]:hover,
.form-actions .btn:not(.ghost):hover {
  background: linear-gradient(180deg, #2a6861 0%, #245a54 100%) !important;
  border-color: #245a54 !important;
}

.form-actions button.ghost,
.form-actions .btn.ghost {
  background: #fff !important;
  color: #2f4a58 !important;
  border-color: var(--c7) !important;
  box-shadow: 0 4px 10px rgba(93, 124, 137, 0.12);
}

.primary-save-btn {
  min-width: 12rem !important;
  padding-inline: 1.35rem !important;
  background: linear-gradient(180deg, #2f746c 0%, var(--c1) 100%) !important;
  border-color: var(--c1) !important;
  color: #fff !important;
  box-shadow: 0 10px 22px rgba(45, 103, 96, 0.24);
}

.primary-save-btn:hover {
  background: linear-gradient(180deg, #2a6861 0%, #245a54 100%) !important;
  border-color: #245a54 !important;
}

.table-wrap {
  border: 1px solid var(--c7);
  border-radius: 0.75rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
  table-layout: auto;
}

.annual-summary-wrap table {
  min-width: 1280px;
}

.annual-summary-table th:first-child,
.annual-summary-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
}

.annual-summary-table th:first-child {
  z-index: 2;
}

.annual-summary-table td:first-child,
.annual-summary-table th:first-child {
  background: #f5faf8;
}

.annual-summary-parcel {
  font-weight: 800;
  color: var(--c1);
  min-width: 7.5rem;
}

.annual-summary-cell {
  display: grid;
  gap: 0.16rem;
  min-width: 7.75rem;
}

.annual-summary-cell--button {
  width: 100%;
  min-height: 0 !important;
  padding: 0.55rem 0.65rem !important;
  border: 1px solid rgba(121, 187, 181, 0.42);
  border-radius: 0.7rem;
  background: linear-gradient(180deg, #f4fbf8 0%, #e9f5f1 100%) !important;
  color: #24414d !important;
  box-shadow: none;
  justify-items: start;
  text-align: left;
}

.annual-summary-cell--button:hover {
  border-color: var(--c4);
  background: linear-gradient(180deg, #edf8f4 0%, #deefe9 100%) !important;
  color: var(--c1) !important;
  box-shadow: 0 8px 18px rgba(45, 103, 96, 0.12);
}

.annual-summary-cell strong {
  font-size: 0.88rem;
  color: #214a57;
}

.annual-summary-cell span,
.annual-summary-empty {
  font-size: 0.78rem;
  color: #607a86;
}

.annual-summary-empty {
  display: inline-block;
  white-space: nowrap;
}

th,
td {
  padding: 0.58rem 0.65rem;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.9rem;
  text-align: left;
}

th {
  background: #edf6f3;
  color: #2f4a58;
  font-weight: 700;
}

.rep-badge {
  display: inline-flex;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.75rem;
  font-weight: 700;
}

.rep-principal { background: #e5f3ef; border-color: var(--c4); color: var(--c1); }
.rep-secundario { background: #f6f0df; border-color: var(--c5); color: #6b5f39; }

.file-upload-group { display: grid; gap: 0.35rem; }
.file-upload-label { font-size: 0.9rem; font-weight: 700; color: #334155; }
.file-dropzone {
  display: grid;
  gap: 0.35rem;
  justify-items: center;
  text-align: center;
  border: 1px dashed var(--c6);
  border-radius: 0.75rem;
  background: #f2f8f6;
  padding: 0.9rem;
  cursor: pointer;
}
.file-dropzone:hover,
.file-dropzone:focus-visible,
.file-dropzone.dragover {
  border-color: var(--c1);
  background: #e7f3ef;
  outline: none;
}
.file-dropzone input[type="file"] { display: none; }
.file-dropzone p { margin: 0; font-weight: 700; color: #214a57; }
.file-name {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.1rem;
  padding: 0.3rem 0.7rem;
  border-radius: 0.7rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: #5b7682;
  word-break: break-word;
  text-align: center;
  transition: background-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.file-name.has-file {
  border: 1px solid var(--c4);
  background: linear-gradient(180deg, #eef7f4 0%, #e2f1ec 100%);
  color: var(--c1);
  box-shadow: inset 0 0 0 1px rgba(121, 187, 181, 0.16);
}

.toast-stack {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 55;
  display: grid;
  gap: 0.5rem;
  width: min(92vw, 360px);
}

.alert {
  border-radius: 0.75rem;
  border: 1px solid transparent;
  padding: 0.62rem 0.7rem;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.14);
  font-size: 0.9rem;
}
.alert.success { background: #e5f3ef; border-color: var(--c4); color: var(--c1); }
.alert.error { background: #fde8e8; border-color: #f6b1b1; color: #9f2f2f; }
.alert.info { background: #e1f0ee; border-color: #9fd0cc; color: #245a54; }
.alert.warning { background: #f6f0df; border-color: var(--c5); color: #75693e; }

.proof-open-btn {
  min-width: 34px;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 !important;
  border-radius: 0.55rem;
  border: 1px solid var(--c7);
  background: #fff !important;
  color: #2f4a58 !important;
  font-weight: 700;
  box-shadow: 0 3px 10px rgba(93, 124, 137, 0.16);
}

.proof-open-btn svg {
  width: 0.95rem;
  height: 0.95rem;
  fill: currentColor;
}

.proof-open-btn:hover {
  border-color: var(--c4);
  color: var(--c1) !important;
  background: #f0f7f5 !important;
}

.concept-actions,
.table-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.icon-btn {
  width: 2.25rem !important;
  min-width: 2.25rem !important;
  height: 2.25rem !important;
  min-height: 2.25rem !important;
  padding: 0 !important;
  border-radius: 0.65rem;
  border: 1px solid var(--c7);
  background: #fff !important;
  color: #2f4a58 !important;
  box-shadow: 0 3px 9px rgba(93, 124, 137, 0.14);
}

.icon-btn svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: currentColor;
}

.icon-btn:hover {
  border-color: var(--c4);
  background: #f0f7f5 !important;
  color: var(--c1) !important;
}

.icon-btn--toggle:hover {
  border-color: #d3b88a;
  background: #f8f3e6 !important;
  color: #8a6b2d !important;
}

.icon-btn--danger:hover {
  border-color: #efb4b4;
  background: #fdecec !important;
  color: #b33a3a !important;
}

.topbar-profile,
.topbar-exit {
  min-width: 7rem !important;
  padding-inline: 1.1rem !important;
}

.topbar-profile {
  background: linear-gradient(180deg, #2f746c 0%, var(--c1) 100%) !important;
  border-color: var(--c1) !important;
  color: #fff !important;
  box-shadow: 0 8px 18px rgba(45, 103, 96, 0.22);
}

.topbar-profile:hover {
  background: linear-gradient(180deg, #2a6861 0%, #245a54 100%) !important;
  border-color: #245a54 !important;
  color: #fff !important;
}

.topbar-exit {
  background: linear-gradient(180deg, #f3d9d9 0%, #e8bcbc 100%) !important;
  border-color: #dba8a8 !important;
  color: #7a2f2f !important;
  box-shadow: 0 8px 18px rgba(186, 96, 96, 0.16);
}

.topbar-exit:hover {
  background: linear-gradient(180deg, #efcfcf 0%, #e2b0b0 100%) !important;
  border-color: #cf9494 !important;
  color: #662222 !important;
}

.proof-modal,
.profile-modal {
  display: none;
  position: fixed;
  inset: 0;
}

.proof-modal { z-index: 70; }
.profile-modal { z-index: 80; }

.proof-modal.is-open,
.profile-modal.is-open { display: block; }

.proof-modal__backdrop,
.profile-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(45, 103, 96, 0.45);
}

.proof-modal__dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(84vw, 1200px);
  height: min(84vh, 820px);
  transform: translate(-50%, -50%);
  margin: 0;
  border: 1px solid var(--c7);
  border-radius: 0.9rem;
  background: #fff;
  box-shadow: 0 24px 50px rgba(45, 103, 96, 0.28);
  padding: 0.55rem;
  display: grid;
  grid-template-rows: 1fr;
  overflow: hidden;
}

.proof-modal__close,
.profile-modal__close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  min-width: 36px;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid var(--c7);
  background: #fff;
  color: #2f4a58;
  font-size: 1.2rem;
  line-height: 1;
  padding: 0;
}

.proof-modal__content {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 0.7rem;
  background: #edf6f3;
}

.proof-modal__content img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
}

.profile-modal__dialog {
  position: relative;
  z-index: 1;
  width: min(94vw, 620px);
  margin: 4vh auto;
  border: 1px solid var(--c7);
  border-radius: 0.9rem;
  background: #fff;
  box-shadow: 0 20px 42px rgba(45, 103, 96, 0.24);
  padding: 0.9rem;
}

.profile-modal__dialog h3 { margin: 0 0 0.7rem; }

.parcel-notes-modal__dialog {
  width: min(94vw, 720px);
}

.parcel-notes-modal__content {
  min-height: 9rem;
  border: 1px solid var(--c7);
  border-radius: 0.85rem;
  background: linear-gradient(180deg, rgba(242, 248, 246, 0.96), rgba(237, 246, 243, 0.98));
  padding: 1rem 1.05rem;
  color: var(--c1);
  font-size: 1rem;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.annual-summary-detail-modal__dialog {
  width: min(96vw, 980px);
}

.annual-summary-detail-wrap table {
  min-width: 760px;
}

body.sidebar-collapsed .layout { grid-template-columns: 0 minmax(0, 1fr); }
body.sidebar-collapsed .menu {
  transform: translateX(-110%);
  opacity: 0;
  pointer-events: none;
}

.menu-backdrop { display: none; }

@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr !important; }
  .layout { max-width: 100% !important; width: 100% !important; }
  .content { padding: 0.85rem !important; }
  .panel { padding: 0.95rem !important; }
  .menu {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: min(82vw, 320px);
    z-index: 60;
    transform: translateX(-110%);
    opacity: 1;
    pointer-events: none;
    overflow-y: auto;
    border-right: 1px solid var(--c7);
    box-shadow: 0 24px 50px rgba(45, 103, 96, 0.2);
  }
  body.sidebar-mobile-open .menu {
    transform: translateX(0);
    pointer-events: auto;
  }
  .menu-backdrop {
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    z-index: 50;
    background: rgba(45, 103, 96, 0.38);
  }
  body.sidebar-mobile-open .menu-backdrop { display: block; }

  .grid-form,
  .grid-form.form-vertical {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) !important;
  }
  .admin-grid {
    grid-template-columns: 1fr !important;
  }
  .form-vertical {
    width: 100% !important;
    max-width: 100% !important;
  }
  .inline-form {
    width: 100%;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(180px, 1fr)) !important;
    gap: 0.55rem !important;
    align-items: stretch !important;
  }
  .inline-form input,
  .inline-form select,
  .inline-form button {
    min-width: 0 !important;
    width: 100% !important;
  }
  .inline-field {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }

  input,
  select,
  textarea,
  button,
  .btn {
    font-size: 16px !important;
  }

  table {
    min-width: 560px;
  }
  th, td {
    font-size: 0.84rem;
  }

  .proof-modal__dialog {
    width: min(94vw, 1200px) !important;
    height: min(82dvh, 820px) !important;
  }

  .login-card {
    width: min(94vw, 520px) !important;
    padding: 1.05rem !important;
  }

  .login-logo {
    width: min(58vw, 220px) !important;
    max-width: 220px !important;
    height: auto !important;
  }
}

@media (max-width: 860px) {
  .topbar {
    flex-wrap: wrap;
  }

  .topbar-left,
  .topbar-actions {
    width: 100%;
    padding-top: 0.45rem !important;
    padding-bottom: 0.45rem !important;
  }

  .topbar-left {
    justify-content: flex-start;
    gap: 0.55rem;
  }

  .topbar-brand {
    min-width: 0;
    flex: 1;
    overflow: hidden;
  }

  .topbar-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.45rem;
  }

  .topbar-welcome {
    width: 100%;
    text-align: right;
    font-size: 0.8rem;
    line-height: 1.25;
    max-width: none;
    white-space: normal;
  }

  .topbar-brand-text {
    font-size: 0.95rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-logo {
    max-height: 34px !important;
  }
}

@media (max-width: 640px) {
  .grid-form,
  .grid-form.form-vertical,
  .admin-grid {
    grid-template-columns: 1fr !important;
  }

  .content {
    padding: 0.7rem !important;
    gap: 0.8rem;
  }

  .panel {
    padding: 0.8rem !important;
    border-radius: 0.85rem !important;
  }

  .menu {
    width: min(88vw, 340px);
  }

  .topbar-left,
  .topbar-actions {
    padding-left: 0.7rem !important;
    padding-right: 0.7rem !important;
  }

  .topbar-logo {
    max-height: 30px !important;
  }

  .topbar-brand-text {
    font-size: 0.9rem !important;
  }

  .topbar-profile,
  .topbar-exit {
    min-width: 5.8rem !important;
    padding-inline: 0.85rem !important;
  }

  .topbar-welcome {
    font-size: 0.76rem !important;
  }

  .inline-form {
    grid-template-columns: 1fr !important;
  }

  table {
    min-width: 520px;
  }

  th,
  td {
    font-size: 0.8rem;
    padding: 0.5rem 0.52rem;
  }

  .proof-modal__dialog {
    width: min(95vw, 1200px) !important;
    height: min(78dvh, 820px) !important;
  }
}

/* ════════════════════════════════════════════════════
   RESPONSIVE — Tablas tipo tarjeta en móvil (≤ 640px)
   ════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  /* Tablas de datos normales → layout tarjeta */
  .table-wrap:not(.annual-summary-wrap):not(.annual-summary-detail-wrap) table {
    display: block;
    min-width: 0;
  }
  .table-wrap:not(.annual-summary-wrap):not(.annual-summary-detail-wrap) thead {
    display: none;
  }
  .table-wrap:not(.annual-summary-wrap):not(.annual-summary-detail-wrap) tbody {
    display: block;
    padding: 0.45rem;
    background: #f8fbf9;
  }
  .table-wrap:not(.annual-summary-wrap):not(.annual-summary-detail-wrap) tr {
    display: block;
    background: #fff;
    border: 1px solid #dde8e5;
    border-radius: 0.75rem;
    margin-bottom: 0.45rem;
    padding: 0.4rem 0.65rem 0.5rem;
    box-shadow: 0 2px 6px rgba(45, 103, 96, 0.07);
  }
  .table-wrap:not(.annual-summary-wrap):not(.annual-summary-detail-wrap) td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.3rem 0;
    border-bottom: 1px solid #edf3f1;
    font-size: 0.82rem;
    text-align: right;
    min-height: 0;
  }
  .table-wrap:not(.annual-summary-wrap):not(.annual-summary-detail-wrap) td:last-child {
    border-bottom: none;
    padding-bottom: 0.1rem;
  }
  .table-wrap:not(.annual-summary-wrap):not(.annual-summary-detail-wrap) td::before {
    content: attr(data-label);
    font-weight: 700;
    color: #2f4a58;
    text-align: left;
    flex-shrink: 0;
    font-size: 0.77rem;
    padding-top: 0.06rem;
    max-width: 48%;
  }

  /* Modal de detalle mensual → también tarjeta */
  .annual-summary-detail-wrap table {
    display: block;
    min-width: 0;
  }
  .annual-summary-detail-wrap thead { display: none; }
  .annual-summary-detail-wrap tbody {
    display: block;
    padding: 0.45rem;
  }
  .annual-summary-detail-wrap tr {
    display: block;
    background: #fff;
    border: 1px solid #dde8e5;
    border-radius: 0.75rem;
    margin-bottom: 0.45rem;
    padding: 0.4rem 0.65rem 0.5rem;
    box-shadow: 0 2px 6px rgba(45, 103, 96, 0.07);
  }
  .annual-summary-detail-wrap td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.3rem 0;
    border-bottom: 1px solid #edf3f1;
    font-size: 0.82rem;
    text-align: right;
    min-height: 0;
  }
  .annual-summary-detail-wrap td:last-child { border-bottom: none; }
  .annual-summary-detail-wrap td::before {
    content: attr(data-label);
    font-weight: 700;
    color: #2f4a58;
    text-align: left;
    flex-shrink: 0;
    font-size: 0.77rem;
    padding-top: 0.06rem;
    max-width: 48%;
  }

  /* Resumen anual: reducir min-width y asegurar scroll suave */
  .annual-summary-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .annual-summary-wrap table {
    min-width: 900px;
  }
}

/* ════════════════════════════════════════════════════
   RESPONSIVE — Móvil real (≤ 480px)
   ════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  /* Topbar: una sola fila sin texto de marca */
  .topbar {
    flex-wrap: nowrap !important;
    min-height: 52px;
  }
  .topbar-left {
    width: auto !important;
    flex-wrap: nowrap !important;
    flex: 1;
    padding-top: 0.4rem !important;
    padding-bottom: 0.4rem !important;
    padding-left: 0.6rem !important;
    padding-right: 0.4rem !important;
    gap: 0.4rem !important;
  }
  .topbar-actions {
    width: auto !important;
    flex-wrap: nowrap !important;
    flex-shrink: 0;
    padding-top: 0.4rem !important;
    padding-bottom: 0.4rem !important;
    padding-right: 0.6rem !important;
    gap: 0.35rem !important;
  }
  .topbar-brand-text {
    display: none !important;
  }
  .topbar-logo {
    max-height: 26px !important;
  }
  .topbar-welcome {
    display: none !important;
  }
  .topbar-profile,
  .topbar-exit {
    min-width: auto !important;
    min-height: 2.2rem !important;
    padding-inline: 0.6rem !important;
    font-size: 0.78rem !important;
  }

  /* Sidebar: ancho más contenido */
  .menu {
    width: min(78vw, 260px) !important;
  }

  /* Espaciado general */
  .content {
    padding: 0.55rem !important;
    gap: 0.6rem;
  }
  .panel {
    padding: 0.6rem !important;
  }

  /* Resumen anual: reducir aún más */
  .annual-summary-wrap table {
    min-width: 720px;
  }

  /* Modales */
  .proof-modal__dialog {
    width: 96vw !important;
    height: 82dvh !important;
    padding: 0.3rem !important;
  }
  .profile-modal__dialog {
    width: 95vw !important;
    margin: 2vh auto !important;
    padding: 0.7rem !important;
  }
  .annual-summary-detail-modal__dialog {
    width: 96vw !important;
    padding: 0.55rem !important;
  }
  .parcel-notes-modal__dialog {
    width: 95vw !important;
  }

  /* Botones de acciones: que no se corten */
  .form-actions {
    gap: 0.45rem;
  }
  .form-actions button,
  .form-actions .btn {
    min-width: auto !important;
    flex: 1 1 auto;
  }

  /* Dropzone compacto */
  .file-dropzone {
    padding: 0.65rem 0.5rem !important;
    gap: 0.25rem !important;
  }
  .file-dropzone p {
    font-size: 0.82rem;
  }
  .file-name {
    font-size: 0.78rem;
  }

  /* Toast */
  .toast-stack {
    width: min(96vw, 340px);
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
  }
}

/* ── Period selects ─────────────────────────────────────────── */
.period-selects {
  display: flex;
  gap: 0.5rem;
}
.period-selects select {
  flex: 1;
}
.period-hint {
  display: block;
  font-size: 0.78rem;
  color: var(--color-muted, #64748b);
  margin-top: 0.25rem;
  min-height: 1rem;
}
.period-hint--active {
  color: var(--color-primary, #0d6efd);
  font-weight: 500;
}
.period-badge {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-primary, #0d6efd);
  background: color-mix(in srgb, var(--color-primary, #0d6efd) 10%, transparent);
  border-radius: 4px;
  padding: 0.1em 0.45em;
  letter-spacing: 0.02em;
}

/* ── Sortable table headers (single toggle arrow) ─── */
th.sortable { white-space: nowrap; }
th.sortable .sort-label { cursor: default; }
th.sortable .sort-arrow {
  background: transparent;
  border: 0;
  padding: 0;
  margin-left: 0.35em;
  width: 10px;
  height: 10px;
  cursor: pointer;
  opacity: 0.35;
  vertical-align: middle;
  line-height: 1;
  transition: opacity 120ms ease, transform 80ms ease;
}
th.sortable .sort-arrow::before {
  content: "";
  display: block;
  width: 0;
  height: 0;
  margin: 0 auto;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}
th.sortable.sort-asc .sort-arrow::before {
  border-top: 0;
  border-bottom: 5px solid currentColor;
}
th.sortable .sort-arrow:hover { opacity: 0.75; }
th.sortable .sort-arrow:active { transform: scale(0.9); }
th.sortable.sort-asc .sort-arrow,
th.sortable.sort-desc .sort-arrow {
  opacity: 1;
  color: var(--color-primary, #0d6efd);
}

/* ── Pagination ─── */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}
.pagination-size {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.pagination-size select {
  padding: 0.25rem 0.45rem;
}
.pagination-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.pagination-btn {
  padding: 0.25rem 0.6rem;
  min-width: 2rem;
  line-height: 1;
}
.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.pagination-info {
  color: var(--color-muted, #64748b);
  min-width: 10rem;
  text-align: center;
}
