:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --panel: #ffffff;
  --panel-soft: #eef4ee;
  --text: #1b2520;
  --muted: #64716b;
  --line: #dce4de;
  --accent: #22765a;
  --accent-strong: #0f513f;
  --warning: #b7791f;
  --blue: #245b9f;
  --shadow: 0 18px 42px rgba(27, 37, 32, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.auth-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 24px;
  background: #17241f;
}

.auth-locked {
  grid-template-columns: 1fr;
}

.auth-locked .auth-view {
  display: grid;
}

.auth-locked .sidebar,
.auth-locked .shell {
  display: none;
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid rgba(215, 240, 223, 0.2);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
}

.login-logo {
  display: block;
  width: min(260px, 100%);
  height: auto;
  max-height: 110px;
  margin: 0 auto 26px;
  object-fit: contain;
}

.login-fields {
  display: grid;
  gap: 14px;
}

.login-fields label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.login-fields input {
  height: 44px;
  width: 100%;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--text);
  font: inherit;
}

.login-fields input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(34, 118, 90, 0.16);
}

.login-error {
  min-height: 20px;
  margin: 13px 0;
  color: #b42318;
  font-size: 0.9rem;
  font-weight: 750;
}

.login-button,
.logout-button {
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
}

.login-button {
  width: 100%;
  height: 44px;
  background: var(--accent);
  color: #ffffff;
}

.login-button:hover {
  background: var(--accent-strong);
}

.login-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.logout-button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
}

.logout-button:hover {
  color: var(--text);
}

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 28px 20px;
  background: #17241f;
  color: #f7fbf8;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #d7f0df;
  color: #173126;
  font-weight: 800;
}

.brand strong {
  display: block;
}

.brand-logo-frame {
  display: inline-flex;
  align-items: center;
  width: 128px;
  height: 30px;
  margin-top: 5px;
  padding: 4px 8px;
  border: 1px solid rgba(215, 240, 223, 0.72);
  border-radius: 7px;
  background: #f7fbf8;
}

.brand-logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: left center;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav a {
  padding: 11px 12px;
  border-radius: 8px;
  color: #d9e6dd;
  text-decoration: none;
  font-weight: 650;
}

.nav a.active,
.nav a:hover {
  background: rgba(215, 240, 223, 0.13);
  color: #ffffff;
}

.sidebar-session {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.sidebar-session .session-clock,
.sidebar-session .logout-button {
  width: 100%;
}

.sidebar-session .session-clock {
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 12px;
  align-items: end;
  justify-items: start;
  text-align: left;
}

.shell {
  width: min(1180px, 100%);
  height: 100vh;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.topbar-title {
  min-width: 0;
}

.top-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
}

.top-meta span {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 750;
}

.developed-by {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.developed-logo-frame {
  display: inline-flex;
  align-items: center;
  width: 118px;
  height: 27px;
  padding: 0;
  border: 0;
  background: transparent;
}

.developed-logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.private-label {
  margin: 0;
  width: fit-content;
  padding: 7px 10px;
  border: 1px solid rgba(34, 118, 90, 0.22);
  border-radius: 8px;
  background: #e8f3ec;
  color: var(--accent-strong);
  font-size: 0.92rem;
  font-weight: 850;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 2.8rem);
}

h2 {
  font-size: 1.15rem;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 700;
}

.session-clock {
  display: grid;
  gap: 3px;
  min-width: 92px;
  min-height: 38px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.session-clock span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  line-height: 1;
}

.session-clock strong {
  color: var(--accent-strong);
  font-size: 1rem;
  line-height: 1;
}

.session-clock small {
  display: block;
  max-width: 100%;
  padding-bottom: 1px;
  overflow: hidden;
  color: var(--blue);
  font-size: 0.74rem;
  font-weight: 750;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-clock.warning strong {
  color: var(--warning);
}

.session-clock.expired strong {
  color: #b42318;
}

.project-switcher {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.project-switcher select {
  min-width: 190px;
  height: 38px;
  padding: 0 36px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--warning);
}

.dot.ok {
  background: var(--accent);
}

.grid,
.content-grid {
  display: grid;
  gap: 16px;
}

.metrics-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric {
  padding: 20px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.metric strong {
  display: block;
  margin: 8px 0 5px;
  font-size: 2.25rem;
  line-height: 1;
}

.content-grid {
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  margin-bottom: 16px;
}

.panel {
  padding: 20px;
}

.panel.wide {
  min-height: 320px;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.bar-list,
.activity-list,
.system-list,
.loan-grid,
.alert-list {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(120px, 2fr) 46px;
  align-items: center;
  gap: 12px;
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--panel-soft);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.mini-chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  align-items: end;
  gap: 10px;
  min-height: 180px;
}

.chart-bar {
  display: grid;
  align-items: end;
  min-height: 160px;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.chart-bar span {
  display: block;
  min-height: 22px;
  border-radius: 8px 8px 3px 3px;
  background: var(--blue);
}

.activity-item {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.tag {
  width: fit-content;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 800;
}

.activity-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activity-item time {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.loan-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.loan-card,
.alert-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.loan-card span,
.alert-item span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.loan-card strong {
  display: block;
  margin-top: 7px;
  font-size: 1.75rem;
  line-height: 1;
}

.alert-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
}

.alert-level {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 999px;
  background: var(--accent);
}

.alert-level.warning {
  background: var(--warning);
}

.alert-level.danger {
  background: #b42318;
}

.alert-item strong {
  display: block;
  margin-bottom: 3px;
}

.system-list {
  margin: 0;
}

.system-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.system-list dt {
  color: var(--muted);
  font-weight: 800;
}

.system-list dd {
  margin: 0;
  font-weight: 800;
}

@media (max-width: 980px) {
  body {
    height: auto;
    overflow: auto;
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    min-height: auto;
  }

  .metrics-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .shell {
    height: auto;
    overflow: visible;
    padding: 22px;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .project-switcher select,
  .status,
  .session-clock,
  .logout-button {
    width: 100%;
  }

  .metrics-grid {
    gap: 12px;
  }

  .activity-item,
  .bar-row,
  .loan-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Configuracion por proyecto: clientes ---------- */

.config-section {
  margin-bottom: 16px;
}

.config-muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1.5;
}

.config-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fef3f2;
  color: #b42318;
  font-size: 0.9rem;
  font-weight: 750;
}

.clients-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(0, 1.1fr);
  align-items: start;
  gap: 24px;
}

.client-form {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.client-form h3,
.clients-side h3 {
  margin: 0;
  font-size: 1rem;
}

.client-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.client-form small {
  font-weight: 600;
}

.client-form input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

.client-form input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(34, 118, 90, 0.16);
}

.email-field {
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.email-field:focus-within {
  border-color: var(--accent);
  outline: 3px solid rgba(34, 118, 90, 0.16);
}

.client-form .email-field input {
  min-width: 0;
  border: 0;
  border-radius: 0;
}

.client-form .email-field input:focus {
  outline: none;
}

.email-field > span {
  padding: 0 12px;
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.client-form .login-error {
  min-height: 0;
  margin: 0;
}

.clients-side,
.client-list {
  display: grid;
  gap: 12px;
}

.client-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.client-item.inactive {
  opacity: 0.65;
}

.client-item strong,
.client-item span,
.client-item small {
  display: block;
}

.client-item span {
  overflow-wrap: anywhere;
  font-weight: 700;
}

.client-item small {
  margin-top: 3px;
  color: var(--muted);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.client-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.client-actions .tag {
  display: inline-block;
}

.tag.off {
  background: #f2f4f3;
  color: var(--muted);
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.small-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.small-button.danger:hover {
  border-color: #b42318;
  color: #b42318;
}

.small-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.password-box {
  padding: 16px;
  border: 1px solid rgba(34, 118, 90, 0.35);
  border-radius: 8px;
  background: var(--panel-soft);
}

.password-box > p {
  margin: 0 0 8px;
}

.password-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.password-row code {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  user-select: all;
}

@media (max-width: 1100px) {
  .clients-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .client-item {
    grid-template-columns: 1fr;
  }

  .client-actions {
    justify-content: flex-start;
  }
}
