:root {
  --green: #0a5b2a;
  --green-dark: #084a22;
  --green-soft: #e9f5e9;
  --line: #dce9dc;
  --text: #123322;
  --muted: #5b6d60;
  --panel: rgba(255, 255, 255, 0.94);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
}

body {
  background:
    radial-gradient(circle at top left, rgba(127, 207, 138, 0.18), transparent 34rem),
    linear-gradient(135deg, #f8fbf6, #eef6ef);
  color: var(--text);
  margin: 0;
  min-height: 100vh;
}

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

input,
select,
textarea {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  min-height: 50px;
  padding: 0.82rem 0.95rem;
  width: 100%;
}

textarea {
  line-height: 1.45;
  resize: vertical;
}

button,
.back-link,
.sidebar a {
  cursor: pointer;
}

.private-shell {
  min-height: 100vh;
}

.login-view {
  display: grid;
  gap: clamp(1.5rem, 4vw, 4rem);
  grid-template-columns: minmax(0, 1.05fr) minmax(300px, 0.75fr);
  margin: 0 auto;
  max-width: 1180px;
  min-height: 100vh;
  padding: clamp(1rem, 5vw, 4.5rem);
  place-items: center;
}

.brand-panel h1,
.workspace-header h1,
.intro-card h2 {
  color: var(--green-dark);
  letter-spacing: -0.045em;
  line-height: 1.02;
  margin: 0;
}

.brand-panel h1 {
  font-size: clamp(2.35rem, 5.5vw, 5.5rem);
  max-width: 11ch;
  text-transform: uppercase;
}

.brand-panel p,
.intro-card p,
.access-grid p {
  color: #263d2c;
  line-height: 1.55;
}

.brand-panel > p {
  font-size: clamp(1rem, 1.4vw, 1.22rem);
  max-width: 42rem;
}

.eyebrow {
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  margin: 0 0 0.55rem;
  text-transform: uppercase;
}

.back-link {
  color: var(--green);
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 850;
  margin-bottom: 2rem;
  text-decoration: none;
  text-transform: uppercase;
}

.security-note,
.login-card,
.workspace,
.sidebar,
.intro-card,
.access-grid article,
.access-grid a,
.metric-grid article,
.simple-table-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 22px 60px rgba(8, 74, 34, 0.1);
}

.security-note {
  display: grid;
  gap: 0.35rem;
  margin-top: 2rem;
  max-width: 32rem;
  padding: 1.15rem;
}

.security-note strong {
  color: var(--green-dark);
}

.security-note span {
  color: var(--muted);
  line-height: 1.4;
}

.login-card {
  display: grid;
  gap: 1rem;
  max-width: 420px;
  padding: clamp(1.2rem, 4vw, 2rem);
  width: 100%;
}

.login-card img {
  height: auto;
  max-width: 190px;
}

.login-card h2 {
  color: var(--green-dark);
  font-size: 1.65rem;
  margin: 0;
}

.login-card label {
  color: var(--green-dark);
  display: grid;
  font-weight: 800;
  gap: 0.45rem;
}

button,
.sidebar a {
  border: 0;
  border-radius: 999px;
  font-weight: 900;
  min-height: 48px;
  padding: 0.8rem 1.05rem;
  text-decoration: none;
  transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

button {
  background: var(--green);
  color: #fff;
}

.secondary-button {
  background: var(--green-soft);
  color: var(--green-dark);
}

button:hover,
button:focus-visible,
.sidebar a:hover,
.sidebar a:focus-visible {
  transform: translateY(-1px);
}

.form-message {
  min-height: 1.4rem;
  margin: 0;
}

.setup-warning {
  background: #fff9e8;
  border: 1px solid #f2d68b;
  border-radius: 14px;
  color: #5c3e00;
  line-height: 1.45;
  padding: 0.85rem;
}

.app-view {
  display: grid;
  gap: 1rem;
  grid-template-columns: 290px minmax(0, 1fr);
  margin: 0 auto;
  max-width: 1280px;
  min-height: 100vh;
  padding: clamp(0.8rem, 3vw, 1.6rem);
}

.sidebar {
  align-self: start;
  display: grid;
  gap: 1rem;
  padding: 1.1rem;
  position: sticky;
  top: 1rem;
}

.sidebar h2 {
  color: var(--green-dark);
  line-height: 1.05;
  margin: 0;
}

.sidebar p {
  color: var(--muted);
  margin: 0.35rem 0 0;
}

.sidebar nav {
  display: grid;
  gap: 0.55rem;
}

.sidebar a {
  background: var(--green-soft);
  color: var(--green-dark);
  display: flex;
  justify-content: center;
  text-align: center;
}

.sidebar a.is-active {
  background: var(--green);
  color: #fff;
}

.logout-button {
  background: #eff6ef;
  color: var(--green-dark);
}

.workspace {
  padding: clamp(1rem, 3vw, 1.8rem);
}

.workspace-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
}

.workspace-header h1 {
  font-size: clamp(2rem, 4vw, 4rem);
  text-transform: uppercase;
}

.institution-pill {
  background: var(--green-soft);
  border-radius: 999px;
  color: var(--green-dark);
  font-size: 0.86rem;
  font-weight: 900;
  padding: 0.7rem 1rem;
  text-align: center;
}

.route-panel {
  display: grid;
  gap: 1rem;
}

.intro-card {
  padding: clamp(1.1rem, 3vw, 1.8rem);
}

.intro-card h2 {
  font-size: clamp(1.8rem, 4vw, 3.6rem);
  text-transform: uppercase;
}

.intro-card p {
  font-size: 1.02rem;
  max-width: 62rem;
}

.warning-card {
  border-color: #f2d68b;
}

.access-grid,
.metric-grid {
  display: grid;
  gap: 1rem;
}

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

.access-grid article,
.access-grid a {
  color: inherit;
  display: block;
  min-height: 170px;
  padding: 1.1rem;
  text-decoration: none;
}

.access-grid span {
  color: #7fcf8a;
  font-size: 2.5rem;
  font-weight: 950;
  line-height: 1;
}

.access-grid h3 {
  color: var(--green-dark);
  font-size: 1.25rem;
  margin: 0.7rem 0 0.35rem;
}

.access-grid p {
  margin: 0;
}

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

.metric-grid article {
  min-height: 132px;
  padding: 1rem;
}

.metric-grid strong {
  color: var(--green-dark);
  display: block;
  font-size: clamp(2.2rem, 5vw, 4rem);
  line-height: 0.9;
}

.metric-grid span {
  color: var(--muted);
  display: block;
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  margin-top: 0.75rem;
  text-transform: uppercase;
}

.simple-table-card {
  padding: 1rem;
}

.panel-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.members-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(300px, 0.85fr) minmax(0, 1.15fr);
}

.member-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 22px 60px rgba(8, 74, 34, 0.1);
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 3vw, 1.35rem);
}

.member-form label,
.member-filters label {
  color: var(--green-dark);
  display: grid;
  font-size: 0.82rem;
  font-weight: 900;
  gap: 0.42rem;
}

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

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

.form-actions button {
  flex: 1 1 160px;
}

.members-panel {
  min-width: 0;
}

.members-heading strong {
  background: var(--green-soft);
  border-radius: 999px;
  color: var(--green-dark);
  font-size: 1.5rem;
  min-width: 3.5rem;
  padding: 0.45rem 0.8rem;
  text-align: center;
}

.member-filters {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: minmax(220px, 1fr) minmax(150px, 0.45fr) minmax(180px, 0.55fr);
  margin-bottom: 0.9rem;
}

.members-table strong {
  color: var(--green-dark);
  display: block;
}

.members-table small {
  color: var(--muted);
  display: block;
  font-size: 0.76rem;
  font-weight: 800;
  margin-top: 0.2rem;
}

.status-pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  padding: 0.35rem 0.62rem;
  text-transform: uppercase;
}

.status-activo {
  background: #e4f6e5;
  color: #0a5b2a;
}

.status-baja {
  background: #f2f2f2;
  color: #59645d;
}

.status-suspendido {
  background: #fff4d8;
  color: #8a4d00;
}

.status-pagado {
  background: #e4f6e5;
  color: #0a5b2a;
}

.status-debe {
  background: #fff0ea;
  color: #9a3412;
}

.status-parcial {
  background: #fff4d8;
  color: #8a4d00;
}

.table-action {
  background: var(--green-soft);
  color: var(--green-dark);
  min-height: 38px;
  padding: 0.45rem 0.75rem;
}

.payment-filters {
  grid-template-columns: minmax(210px, 1fr) repeat(3, minmax(120px, 0.42fr)) minmax(170px, 0.55fr);
}

.payments-table small,
.debts-table small {
  color: var(--muted);
  display: block;
  font-size: 0.76rem;
  font-weight: 800;
  margin-top: 0.2rem;
  text-transform: capitalize;
}

.debt-months {
  color: var(--text);
  line-height: 1.35;
}

.panel-heading h3 {
  color: var(--green-dark);
  font-size: 1.4rem;
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
}

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

/* Keep the action button reachable even when a wide table needs to scroll
   horizontally on desktop, and let institution/user tables fit their card
   width instead of overflowing. */
.table-wrap table td:last-child,
.table-wrap table th:last-child {
  background: var(--panel);
  position: sticky;
  right: 0;
}

.institutions-table,
.users-table {
  table-layout: fixed;
}

.institutions-table th,
.institutions-table td {
  overflow-wrap: break-word;
}

.institutions-table th:nth-child(1),
.institutions-table td:nth-child(1) {
  width: 24%;
}

.institutions-table th:nth-child(2),
.institutions-table td:nth-child(2) {
  width: 15%;
}

.institutions-table th:nth-child(3),
.institutions-table td:nth-child(3) {
  width: 17%;
}

.institutions-table th:nth-child(4),
.institutions-table td:nth-child(4) {
  width: 19%;
}

.institutions-table th:nth-child(5),
.institutions-table td:nth-child(5) {
  width: 13%;
}

.institutions-table th:nth-child(6),
.institutions-table td:nth-child(6) {
  width: 12%;
}

.users-table th,
.users-table td {
  overflow-wrap: break-word;
}

.users-table th:nth-child(1),
.users-table td:nth-child(1) {
  width: 28%;
}

.users-table th:nth-child(2),
.users-table td:nth-child(2) {
  width: 14%;
}

.users-table th:nth-child(3),
.users-table td:nth-child(3) {
  width: 18%;
}

.users-table th:nth-child(4),
.users-table td:nth-child(4) {
  width: 14%;
}

.users-table th:nth-child(5),
.users-table td:nth-child(5) {
  width: 26%;
}

/* A <td> must stay display:table-cell to keep its table-layout:fixed width —
   overriding it to flex breaks column sizing in some browsers. Stack the two
   action buttons with an inner wrapper instead. */
.user-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.table-action {
  white-space: nowrap;
}

.table-action-danger {
  background: #fff0ea;
  color: #9a3412;
}

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

th {
  color: var(--green-dark);
  font-size: 0.74rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .login-view,
  .app-view {
    grid-template-columns: 1fr;
  }

  .brand-panel h1 {
    max-width: 14ch;
  }

  .sidebar {
    position: static;
  }

  .sidebar nav,
  .access-grid,
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .members-layout {
    grid-template-columns: 1fr;
  }

  .member-filters {
    grid-template-columns: 1fr 1fr;
  }

  .payment-filters {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .login-view {
    align-content: center;
    min-height: 100svh;
    place-items: stretch;
  }

  .brand-panel h1 {
    font-size: clamp(2rem, 12vw, 3.4rem);
    max-width: 12ch;
  }

  .back-link {
    margin-bottom: 1rem;
  }

  .login-card {
    border-radius: 18px;
  }

  .app-view {
    padding: 0.7rem;
  }

  .workspace-header {
    align-items: stretch;
    flex-direction: column;
  }

  .sidebar nav,
  .access-grid,
  .metric-grid,
  .form-grid,
    .member-filters,
    .payment-filters {
    grid-template-columns: 1fr;
  }

  input,
  select,
  textarea,
  button,
  .sidebar a {
    min-height: 48px;
  }

  .access-grid article,
  .access-grid a {
    min-height: 130px;
  }

  .metric-grid article {
    min-height: 112px;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tr {
    border-bottom: 1px solid var(--line);
    padding: 0.75rem 0;
  }

  td {
    align-items: baseline;
    border-bottom: 0;
    display: grid;
    gap: 1rem;
    grid-template-columns: 0.8fr 1.2fr;
    padding: 0.35rem 0;
  }

  td::before {
    color: var(--muted);
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .members-table td:last-child {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .members-table td:last-child::before {
    display: none;
  }

  .table-action {
    width: 100%;
  }
}
