:root {
  --bg: #f7faf8;
  --surface: #ffffff;
  --surface-soft: #edf4f1;
  --surface-hover: #e8f0ee;
  --border: rgba(16, 32, 28, .18);
  --border-strong: rgba(16, 32, 28, .32);
  --text: #10201c;
  --text-main: #10201c;
  --text-muted: #425650;
  --brand: #006f5f;
  --brand-rgb: 0, 111, 95;
  --brand-strong: #00584c;
  --focus-ring: #007f6d;
  --shadow-card: 0 14px 36px rgba(22, 50, 42, .07);
  --shadow-lift: 0 20px 48px rgba(22, 50, 42, .12);
  --font-sans: "Manrope", sans-serif;
  --font-mono: "DM Mono", monospace;
}

html[data-theme="light"],
html {
  color-scheme: light;
}

body.auth-page,
body.admin-page,
body.client-page {
  background:
    radial-gradient(circle at 85% 8%, rgba(0, 122, 104, .1), transparent 30rem),
    linear-gradient(rgba(16, 32, 28, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 32, 28, .035) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 64px 64px, 64px 64px, auto;
  color: var(--text);
  font-family: var(--font-sans);
  min-width: 320px;
}

.skip-link {
  background: var(--text);
  border-radius: 0 0 10px 0;
  color: #fff;
  font-weight: 800;
  left: 0;
  padding: .8rem 1rem;
  position: fixed;
  top: -5rem;
  z-index: 1000;
}

.skip-link:focus {
  outline: 3px solid #fff;
  outline-offset: -6px;
  top: 0;
}

.auth-shell {
  padding: clamp(1rem, 4vw, 3rem);
}

.auth-panel {
  border-color: var(--border-strong);
  border-radius: 20px;
  box-shadow: 0 35px 90px rgba(22, 50, 42, .14);
  max-width: 510px;
  padding: clamp(1.5rem, 5vw, 3rem);
}

.auth-logo {
  display: inline-block;
}

.auth-logo img {
  margin-bottom: 2.8rem;
  max-width: 190px;
}

.auth-toolbar {
  margin-bottom: 1.5rem;
}

.portal-eyebrow,
.section-label {
  color: var(--brand-strong);
  font-family: var(--font-mono);
  font-size: .68rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.auth-panel h1,
.panel-heading h1,
.client-hero h1 {
  color: var(--text);
  font-weight: 650;
  letter-spacing: -.05em;
  line-height: 1.05;
}

.auth-intro {
  color: var(--text-muted);
  line-height: 1.7;
  margin: -1rem 0 1.6rem;
}

.auth-back {
  align-items: center;
  color: var(--text-muted);
  display: inline-flex;
  font-size: .78rem;
  font-weight: 700;
  gap: .5rem;
  margin-top: 1.5rem;
  min-height: 44px;
}

.auth-back:hover {
  color: var(--brand-strong);
}

.auth-account-link {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  font-size: .8rem;
  gap: .35rem .55rem;
  line-height: 1.5;
  margin-top: 1.25rem;
  padding: .85rem 1rem;
}

.auth-account-link a {
  color: var(--brand-strong);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.auth-account-link a:hover {
  color: var(--brand);
}

.auth-login-page .auth-shell {
  min-height: 100svh;
  padding: clamp(.65rem, 2vh, 1.25rem);
}

.auth-login-page .auth-panel {
  max-width: 440px;
  padding: clamp(1.2rem, 3vh, 1.8rem);
  position: relative;
}

.auth-login-page .auth-toolbar {
  margin: 0;
  position: absolute;
  right: 1.25rem;
  top: 1.15rem;
}

.auth-login-page .language-switcher button {
  min-height: 32px;
  min-width: 34px;
}

.auth-login-page .auth-logo img {
  margin-bottom: 1.15rem;
  max-width: 165px;
}

.auth-login-page .portal-eyebrow {
  display: block;
  margin-bottom: .4rem;
}

.auth-login-page .auth-panel h1 {
  font-size: clamp(1.7rem, 4vh, 2.15rem);
  margin-bottom: 1rem;
}

.auth-login-page .admin-form {
  gap: .72rem;
}

.auth-login-page .admin-form label {
  gap: .35rem;
}

.auth-login-page .admin-form input {
  min-height: 44px;
  padding-block: .62rem;
}

.auth-login-page .form-status {
  margin: 0;
  min-height: 1rem;
}

.auth-login-page .form-status:empty {
  display: none;
}

.auth-login-page .btn-submit {
  margin-top: 0;
  min-height: 44px;
}

.auth-login-page .auth-account-link {
  background: transparent;
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
  font-size: .75rem;
  line-height: 1.35;
  margin-top: .8rem;
  padding: .7rem 0 0;
}

.auth-login-page .auth-account-link + .auth-account-link {
  margin-top: .55rem;
  padding-top: .55rem;
}

.auth-login-page .auth-back {
  margin-top: .65rem;
  min-height: 36px;
}

@media (max-height: 650px) and (min-width: 520px) {
  .auth-login-page .auth-shell {
    align-items: start;
  }

  .auth-login-page .auth-panel {
    margin-top: .5rem;
  }

  .auth-login-page .auth-logo img {
    margin-bottom: .75rem;
    max-width: 145px;
  }

  .auth-login-page .auth-panel h1 {
    font-size: 1.65rem;
    margin-bottom: .75rem;
  }

  .auth-login-page .admin-form {
    gap: .55rem;
  }
}

.auth-success {
  background: #e8f7f1;
  border: 1px solid rgba(0, 111, 95, .28);
  border-radius: 10px;
  color: #00584c;
  line-height: 1.65;
  margin-bottom: 1.2rem;
  padding: .9rem 1rem;
}

.password-help {
  color: var(--text-muted);
  font-size: .74rem;
  line-height: 1.55;
  margin-top: -.2rem;
}

.admin-form {
  display: grid;
  gap: 1rem;
}

.admin-form label {
  color: var(--text);
  display: grid;
  font-size: .8rem;
  font-weight: 700;
  gap: .5rem;
}

.admin-form input,
.admin-form select,
.filters-panel input,
.filters-panel select,
.admin-form textarea {
  background: #f8fbf9;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  color: var(--text);
  min-height: 48px;
  outline: none;
  padding: .75rem .85rem;
}

.admin-form input::placeholder,
.admin-form textarea::placeholder,
.filters-panel input::placeholder {
  color: #596b65;
  opacity: 1;
}

.admin-form input:focus,
.admin-form select:focus,
.filters-panel input:focus,
.filters-panel select:focus,
.admin-form textarea:focus {
  background: #fff;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(0, 122, 104, .11);
}

.password-input {
  display: block;
  position: relative;
  width: 100%;
}

.password-input > input {
  padding-right: 3.25rem !important;
  width: 100%;
}

.password-toggle {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--text-muted);
  display: inline-flex;
  height: 40px;
  justify-content: center;
  padding: 0;
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
}

.password-toggle:hover {
  background: var(--surface-soft);
  color: var(--brand-strong);
}

.password-toggle:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

.password-toggle svg {
  fill: none;
  height: 21px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 21px;
}

.password-eye-closed,
.password-toggle.is-visible .password-eye-open {
  display: none;
}

.password-toggle.is-visible .password-eye-closed {
  display: block;
}

.btn-submit,
.admin-button {
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  border: 1px solid var(--brand-strong);
  border-radius: 999px;
  color: #fff;
  font-weight: 750;
  min-height: 46px;
  padding: .7rem 1rem;
  transition: box-shadow 160ms ease, transform 160ms ease, background-color 160ms ease;
}

.btn-submit {
  margin-top: .5rem;
  width: 100%;
}

.admin-button.secondary {
  background: #fff;
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-submit:hover:not(:disabled),
.admin-button:hover:not(:disabled) {
  box-shadow: 0 10px 24px rgba(var(--brand-rgb), .2);
  transform: translateY(-1px);
}

.btn-submit:disabled,
.admin-button:disabled,
.icon-button:disabled {
  cursor: wait;
  opacity: .58;
}

.btn-submit:focus-visible,
.admin-button:focus-visible,
.icon-button:focus-visible,
.language-switcher button:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 3px;
}

.language-switcher {
  align-items: center;
  background: rgba(255, 255, 255, .8);
  border: 1px solid var(--border);
  border-radius: 999px;
  display: inline-flex;
  padding: 3px;
}

.language-switcher button {
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: .66rem;
  font-weight: 600;
  min-height: 34px;
  min-width: 38px;
  padding: .35rem .55rem;
}

.language-switcher button.is-active,
.language-switcher button[aria-pressed="true"] {
  background: var(--text);
  color: #fff;
}

.admin-header {
  backdrop-filter: blur(18px);
  background: rgba(255, 255, 255, .9);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

@supports not (backdrop-filter: blur(1px)) {
  .admin-header {
    background: #fff;
  }
}

.admin-topbar {
  min-height: 78px;
}

.admin-header .logo {
  width: 170px;
}

.admin-header .logo-mark-dark {
  display: none !important;
}

.admin-header .logo-mark-light {
  display: block !important;
}

.admin-layout {
  background: transparent;
  display: block;
}

.admin-sidebar {
  background: rgba(247, 250, 248, .72);
  border-color: var(--border);
  max-width: 1440px;
  padding-block: .7rem;
}

.admin-tab {
  border-radius: 10px;
  margin: 0;
  min-height: 46px;
  width: auto;
}

.admin-tab.active,
.admin-tab:hover {
  background: #fff;
  border-color: var(--border);
  box-shadow: 0 8px 24px rgba(22, 50, 42, .06);
  color: var(--brand-strong);
}

.admin-tab[aria-selected="true"] {
  box-shadow: inset 0 -3px 0 var(--brand), 0 8px 24px rgba(22, 50, 42, .06);
}

.admin-content {
  min-width: 0;
  padding: clamp(1.25rem, 3vw, 2.5rem);
}

.metric-card,
.chart-card,
.detail-panel,
.table-wrap,
.admin-modal .modal-content {
  border-color: var(--border);
  border-radius: 14px;
  box-shadow: 0 14px 36px rgba(22, 50, 42, .06);
}

.table-wrap {
  overflow: auto;
  overscroll-behavior-inline: contain;
  scrollbar-color: var(--brand) var(--surface-soft);
  scrollbar-width: thin;
}

.table-wrap:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 3px;
}

.table-wrap::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: var(--brand);
  border: 2px solid var(--surface-soft);
  border-radius: 999px;
}

.table-wrap::-webkit-scrollbar-track {
  background: var(--surface-soft);
}

.client-shell {
  max-width: 1200px;
}

.client-hero {
  align-items: end;
  display: flex;
  gap: 2rem;
  justify-content: space-between;
  padding: clamp(2.5rem, 6vw, 4.5rem) 0 2rem;
}

.client-hero > div {
  max-width: 760px;
}

.client-hero p {
  color: var(--text-muted);
  line-height: 1.7;
  max-width: 620px;
}

.client-summary {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: clamp(2rem, 5vw, 3.5rem);
}

.client-stat {
  background: linear-gradient(145deg, rgba(255, 255, 255, .98), rgba(237, 244, 241, .9));
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  contain: layout paint;
  min-width: 0;
  padding: 1.25rem;
}

.client-stat span {
  color: var(--text-muted);
  display: block;
  font-family: var(--font-mono);
  font-size: .68rem;
  letter-spacing: .06em;
  margin-bottom: .65rem;
  text-transform: uppercase;
}

.client-stat strong {
  display: block;
  font-size: clamp(1.35rem, 2.7vw, 2rem);
  letter-spacing: -.04em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.client-content {
  background: rgba(255, 255, 255, .82);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-card);
  padding: clamp(1rem, 3vw, 1.5rem);
}

.client-section-head {
  align-items: end;
  display: flex;
  gap: 1.5rem;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.client-section-head h2,
.client-security h2 {
  font-size: clamp(1.45rem, 3vw, 2rem);
  letter-spacing: -.04em;
  margin-top: .35rem;
}

.client-search {
  color: var(--text-muted);
  display: grid;
  font-size: .76rem;
  font-weight: 750;
  gap: .4rem;
  min-width: min(100%, 280px);
}

.client-search input {
  background: #f8fbf9;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text);
  min-height: 46px;
  padding: .7rem 1rem;
  width: 100%;
}

.client-search input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(var(--brand-rgb), .12);
  outline: 0;
}

.client-invoice-table {
  box-shadow: none;
}

.client-invoice-table table {
  min-width: 760px;
}

.client-invoice-table tbody tr {
  transition: background-color 140ms ease;
}

.client-invoice-table tbody tr:hover {
  background: var(--surface-soft);
}

.invoice-date {
  color: var(--text-muted);
  display: block;
  font-size: .78rem;
  margin-top: .25rem;
}

.invoice-pdf-link {
  min-height: 40px;
  padding: .5rem .75rem;
  white-space: nowrap;
}

.badge.status-pagada {
  background: #e7f7ef;
  border-color: #9bd7b8;
  color: #075c37;
}

.badge.status-vencuda {
  background: #fff0f0;
  border-color: #efb0b0;
  color: #9b1c1c;
}

.badge.status-enviada,
.badge.status-parcial {
  background: #fff8e6;
  border-color: #e6ca7a;
  color: #765200;
}

.badge.status-esborrany {
  background: #f0f2f2;
  border-color: #c5cecb;
  color: #425650;
}

.client-security {
  align-items: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-card);
  display: grid;
  gap: clamp(1.5rem, 5vw, 4rem);
  grid-template-columns: minmax(0, .85fr) minmax(300px, 1fr);
  margin: 1.25rem 0 4rem;
  padding: clamp(1.25rem, 4vw, 2rem);
}

.client-security-copy p {
  color: var(--text-muted);
  line-height: 1.7;
  margin-top: .9rem;
  max-width: 520px;
}

.client-password-form {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.15rem;
}

.loading-line {
  align-items: center;
  color: var(--text-muted);
  display: inline-flex;
  gap: .65rem;
}

.loading-line::before {
  animation: portal-spin .8s linear infinite;
  border: 2px solid var(--border);
  border-radius: 50%;
  border-top-color: var(--brand);
  content: "";
  height: 16px;
  width: 16px;
}

@keyframes portal-spin {
  to { transform: rotate(1turn); }
}

@media (max-width: 840px) {
  .admin-sidebar {
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }

  .admin-tab {
    flex: 0 0 auto;
    margin: 0;
    width: auto;
  }

  .client-hero {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .client-security {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .auth-shell {
    align-items: start;
    padding: .75rem;
  }

  .auth-panel {
    border-radius: 16px;
    margin-block: auto;
    padding: 1.25rem;
  }

  .auth-logo img {
    margin-bottom: 2rem;
    max-width: 155px;
  }

  .auth-panel h1 {
    font-size: clamp(2rem, 10vw, 2.65rem);
  }

  .admin-form input,
  .admin-form select,
  .filters-panel input,
  .filters-panel select,
  .admin-form textarea {
    font-size: 1rem;
  }

  .admin-topbar {
    gap: .75rem;
    min-height: 68px;
    padding: .65rem .85rem;
  }

  .admin-header .logo {
    flex: 0 1 135px;
    width: 135px;
  }

  .admin-user {
    gap: .45rem;
    min-width: 0;
  }

  .admin-user > span {
    max-width: 8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .icon-button {
    flex: 0 0 44px;
    height: 44px;
    width: 44px;
  }

  .admin-sidebar {
    padding: .65rem .85rem;
  }

  .admin-tab {
    min-height: 44px;
    padding: .7rem .8rem;
  }

  .admin-content,
  .client-shell {
    padding-inline: .85rem;
  }

  .client-hero {
    gap: 1.25rem;
    padding-block: 2.5rem 1.5rem;
  }

  .client-hero h1 {
    font-size: clamp(2rem, 10vw, 2.8rem);
  }

  .client-section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .client-search {
    min-width: 0;
  }

  .client-invoice-table {
    background: transparent;
    border: 0;
    overflow: visible;
  }

  .client-invoice-table table,
  .client-invoice-table tbody,
  .client-invoice-table tr,
  .client-invoice-table td {
    display: block;
    min-width: 0;
    width: 100%;
  }

  .client-invoice-table thead {
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    height: 1px;
    overflow: hidden;
    position: absolute;
    white-space: nowrap;
    width: 1px;
  }

  .client-invoice-table tbody {
    display: grid;
    gap: .8rem;
  }

  .client-invoice-table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(22, 50, 42, .05);
    padding: .35rem .9rem;
  }

  .client-invoice-table td {
    align-items: center;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    min-height: 48px;
    padding: .65rem 0;
    text-align: right;
  }

  .client-invoice-table td::before {
    color: var(--text-muted);
    content: attr(data-label);
    flex: 0 0 42%;
    font-family: var(--font-mono);
    font-size: .7rem;
    text-align: left;
  }

  .client-invoice-table td:last-child {
    border-bottom: 0;
  }

  .client-invoice-table td.empty-row {
    display: block;
    text-align: center;
  }

  .client-invoice-table td.empty-row::before {
    content: none;
  }

  .invoice-pdf-link {
    width: auto;
  }

  .toolbar .admin-button,
  .client-hero .admin-button {
    width: 100%;
  }

  .table-wrap {
    border-radius: 12px;
  }

  th,
  td {
    padding: .7rem;
  }

  .admin-modal,
  #documentModal {
    max-height: 94dvh;
    max-width: calc(100vw - 1rem);
  }

  .admin-modal .modal-content {
    max-height: 94dvh;
    padding: 1rem;
  }

  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .modal-actions .admin-button {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .admin-user > span {
    display: none;
  }

  .language-switcher button {
    min-width: 34px;
    padding-inline: .35rem;
  }

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

@media (prefers-contrast: more) {
  :root {
    --border: rgba(16, 32, 28, .3);
    --border-strong: rgba(16, 32, 28, .5);
    --text-muted: #344a44;
    --brand: #006657;
    --brand-strong: #004d42;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }

  .loading-line::before {
    animation-duration: 2s;
  }
}

/* Corporate ERP interface */
body.admin-page,
body.client-page {
  background: #f3f5f7;
  color: #17202e;
}

body.admin-page section,
body.client-page section {
  border-top: 0;
  padding-block: 0;
  scroll-margin-top: 120px;
}

.admin-page .section-label,
.client-page .section-label,
.admin-page .portal-eyebrow,
.client-page .portal-eyebrow {
  display: block;
  margin-bottom: 0;
}

body.admin-page::before,
body.client-page::before {
  display: none;
}

.admin-page,
.client-page {
  --bg: #f7faf8;
  --surface: #ffffff;
  --surface-soft: #edf4f1;
  --surface-hover: #e8f0ee;
  --border: rgba(16, 32, 28, .16);
  --border-strong: rgba(16, 32, 28, .28);
  --text: #10201c;
  --text-main: #10201c;
  --text-muted: #4c615b;
  --brand: #006f5f;
  --brand-rgb: 0, 111, 95;
  --brand-strong: #00584c;
  --erp-navy: #10201c;
  --erp-navy-soft: #edf4f1;
  --erp-blue: #006f5f;
  --erp-shadow: 0 1px 2px rgba(22, 50, 42, .05), 0 10px 26px rgba(22, 50, 42, .045);
}

.admin-page .admin-header,
.client-page .admin-header {
  backdrop-filter: blur(18px);
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 18px rgba(22, 50, 42, .05);
  color: var(--text);
}

.admin-page .admin-topbar,
.client-page .admin-topbar {
  max-width: 1600px;
  min-height: 66px;
}

.erp-brand {
  align-items: center;
  display: flex;
  gap: 1rem;
  min-width: 0;
}

.admin-header .erp-brand .logo {
  background: transparent;
  border-radius: 0;
  padding: 0;
  width: 170px;
}

.admin-header .erp-brand .logo-mark {
  height: auto;
  max-width: none;
  width: 100%;
}

.erp-product {
  border-left: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .055em;
  padding-left: 1rem;
  text-transform: uppercase;
  white-space: nowrap;
}

.admin-page .admin-user,
.client-page .admin-user {
  color: var(--text);
  gap: .65rem;
}

.erp-user-avatar {
  align-items: center;
  background: #007c6c;
  border: 1px solid rgba(var(--brand-rgb), .25);
  border-radius: 5px;
  display: inline-flex;
  flex: 0 0 36px;
  font-size: .82rem;
  font-weight: 800;
  height: 36px;
  justify-content: center;
}

.erp-user-copy {
  display: grid;
  line-height: 1.2;
  min-width: 0;
}

.erp-user-copy strong {
  font-size: .78rem;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.erp-user-copy small {
  color: var(--text-muted);
  font-size: .66rem;
  margin-top: .2rem;
}

.admin-page .icon-button,
.client-page .icon-button {
  background: var(--surface-soft);
  border-color: var(--border);
  border-radius: 5px;
  color: var(--text);
}

.admin-page .icon-button:hover,
.client-page .icon-button:hover {
  background: var(--surface-hover);
}

.admin-page .admin-sidebar {
  background: rgba(247, 250, 248, .96);
  border-bottom: 1px solid var(--border);
  gap: .15rem;
  max-width: none;
  padding: 0 max(1rem, calc((100vw - 1600px) / 2 + 1rem));
}

.admin-page .admin-tab {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--text-muted);
  font-size: .78rem;
  font-weight: 650;
  gap: .55rem;
  min-height: 49px;
  padding: .7rem 1rem;
}

.admin-page .admin-tab i {
  color: #71857f;
  font-size: .9rem;
}

.admin-page .admin-tab:hover {
  background: var(--surface-soft);
  color: var(--brand-strong);
}

.admin-page .admin-tab.active,
.admin-page .admin-tab[aria-selected="true"] {
  background: #fff;
  border-bottom-color: var(--brand);
  box-shadow: none;
  color: var(--brand-strong);
}

.admin-page .admin-tab.active i {
  color: var(--brand);
}

.admin-page .admin-content {
  margin: 0 auto;
  max-width: 1600px;
  padding: 1.65rem clamp(1rem, 2.4vw, 2rem) 3rem;
}

.panel-heading {
  align-items: end;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 2rem;
  justify-content: space-between;
  margin-bottom: 1.35rem;
  padding-bottom: 1.15rem;
}

.panel-heading h1 {
  font-size: clamp(1.65rem, 3vw, 2.15rem);
  letter-spacing: -.035em;
  margin: .3rem 0 0;
}

.panel-heading p {
  color: var(--text-muted);
  font-size: .82rem;
  margin-top: .4rem;
}

.panel-heading .section-label {
  color: var(--brand-strong);
  font-family: var(--font-sans);
  font-size: .65rem;
  font-weight: 800;
  letter-spacing: .075em;
}

.admin-page .filters-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--erp-shadow);
  gap: .6rem;
  margin-bottom: 1rem;
  padding: .8rem;
}

.admin-page .filters-panel label,
.admin-page .admin-form label {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: .7rem;
  font-weight: 750;
  letter-spacing: .015em;
}

.admin-page .filters-panel input,
.admin-page .filters-panel select,
.admin-page .admin-form input,
.admin-page .admin-form select,
.admin-page .admin-form textarea,
.client-page .admin-form input,
.client-page .admin-form select,
.client-page .admin-form textarea {
  background: #fff;
  border-color: var(--border-strong);
  border-radius: 4px;
  min-height: 42px;
  padding: .6rem .7rem;
}

.admin-page .filters-panel input:focus,
.admin-page .filters-panel select:focus,
.admin-page .admin-form input:focus,
.admin-page .admin-form select:focus,
.admin-page .admin-form textarea:focus,
.client-page .admin-form input:focus,
.client-page .admin-form select:focus,
.client-page .admin-form textarea:focus {
  border-color: #218c7d;
  box-shadow: 0 0 0 3px rgba(0, 124, 108, .12);
}

.admin-page .admin-button,
.client-page .admin-button {
  border-radius: 4px;
  box-shadow: none;
  font-size: .76rem;
  min-height: 40px;
  padding: .55rem .85rem;
}

.admin-page .admin-button:hover:not(:disabled),
.client-page .admin-button:hover:not(:disabled) {
  box-shadow: 0 4px 10px rgba(0, 99, 86, .18);
  transform: none;
}

.admin-page .admin-button.secondary,
.client-page .admin-button.secondary {
  background: #fff;
  border-color: var(--border-strong);
  color: var(--text);
}

.admin-page .metrics-grid {
  gap: .75rem;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}

.admin-page .metric-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--erp-shadow);
  min-height: 128px;
  padding: 1rem;
  position: relative;
}

.admin-page .metric-card::after {
  background: var(--brand);
  content: "";
  height: 2px;
  inset: auto 0 0;
  opacity: .65;
  position: absolute;
}

.admin-page .metric-card:hover {
  border-color: #b8c5cf;
  box-shadow: 0 5px 16px rgba(21, 31, 44, .08);
  transform: none;
}

.admin-page .metric-card span {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: .7rem;
  font-weight: 750;
  letter-spacing: .035em;
  margin-bottom: .85rem;
  text-transform: uppercase;
}

.admin-page .metric-card span i {
  align-items: center;
  background: #e8f3f1;
  border-radius: 4px;
  color: var(--brand);
  display: inline-flex;
  height: 28px;
  justify-content: center;
  width: 28px;
}

.admin-page .metric-card strong {
  color: var(--text);
  font-size: clamp(1.35rem, 2vw, 1.8rem);
  font-variant-numeric: tabular-nums;
}

.admin-page .metric-card small {
  font-size: .7rem;
}

.admin-page .dashboard-insights,
.admin-page .charts-grid {
  gap: .8rem;
  margin-top: .8rem;
}

.admin-page .insight-panel,
.admin-page .chart-card,
.admin-page .detail-panel,
.admin-page .table-wrap,
.admin-page .admin-modal .modal-content {
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--erp-shadow);
}

.admin-page .insight-panel,
.admin-page .chart-card {
  padding: 1rem;
}

.admin-page .insight-head,
.admin-page .chart-head {
  border-bottom: 1px solid #e7ebef;
  margin-bottom: .8rem;
  padding-bottom: .7rem;
}

.admin-page .insight-head h2,
.admin-page .chart-head h2,
.admin-page .toolbar h2 {
  color: var(--text);
  font-size: .85rem;
  font-weight: 800;
}

.admin-page .insight-item,
.admin-page .activity-item,
.admin-page .conversation-item {
  background: #f8fafb;
  border-color: #e0e6eb;
  border-radius: 4px;
}

.admin-page .toolbar {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  margin-bottom: 0;
  min-height: 58px;
  padding: .65rem .85rem;
}

.admin-page .toolbar + .table-wrap,
.admin-page .toolbar + .split-view,
.admin-page .toolbar + .marketing-grid {
  margin-top: .75rem;
}

.admin-page .table-wrap {
  background: #fff;
  max-height: min(68vh, 760px);
}

.admin-page table {
  border-collapse: separate;
  border-spacing: 0;
}

.admin-page th {
  background: #f1f6f4;
  border-bottom: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .045em;
  padding: .72rem .8rem;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  z-index: 2;
}

.admin-page td {
  border-bottom-color: #e5e9ed;
  font-size: .78rem;
  padding: .72rem .8rem;
}

.admin-page tbody tr:hover {
  background: #f3f8f7;
}

.admin-page .badge,
.client-page .badge {
  border-radius: 3px;
  font-family: var(--font-sans);
  font-size: .64rem;
  font-weight: 800;
  letter-spacing: .025em;
  padding: .25rem .45rem;
  text-transform: uppercase;
}

.admin-page .detail-panel {
  padding: 1rem;
}

.admin-page .admin-modal::backdrop {
  backdrop-filter: blur(2px);
  background: rgba(16, 32, 28, .62);
}

.admin-page .admin-modal .modal-content {
  border-top: 4px solid var(--brand);
  padding: 1.25rem;
}

.admin-page .modal-head {
  border-bottom: 1px solid var(--border);
  padding-bottom: .85rem;
}

.admin-page .modal-head h2 {
  color: var(--text);
  font-size: 1rem;
  font-weight: 800;
}

.admin-page .marketing-email-card {
  border-radius: 6px;
}

/* Customer-facing ERP portal */
.client-page .admin-header {
  border-bottom: 3px solid var(--brand);
}

.client-page .language-switcher {
  background: var(--surface-soft);
  border-color: var(--border);
}

.client-page .language-switcher button {
  color: var(--text-muted);
}

.client-page .language-switcher button.is-active,
.client-page .language-switcher button[aria-pressed="true"] {
  background: var(--text);
  color: #fff;
}

.client-page .client-shell {
  max-width: 1400px;
  padding-top: 1.5rem;
}

.client-page .client-hero {
  align-items: center;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: 6px;
  box-shadow: var(--erp-shadow);
  margin-bottom: 1rem;
  padding: 1.35rem 1.5rem;
}

.client-page .client-hero h1 {
  color: var(--text);
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  letter-spacing: -.035em;
  margin-bottom: .45rem;
}

.client-page .client-hero p {
  font-size: .82rem;
  line-height: 1.55;
}

.client-page .portal-eyebrow {
  color: var(--erp-blue);
  font-family: var(--font-sans);
  font-size: .64rem;
  font-weight: 800;
}

.client-page .client-summary {
  gap: .75rem;
  margin-bottom: 1rem;
}

.client-page .client-stat {
  background: #fff;
  border-radius: 6px;
  box-shadow: var(--erp-shadow);
  min-height: 110px;
  padding: 1rem;
  position: relative;
}

.client-page .client-stat::before {
  background: #d9e2e9;
  content: "";
  height: 3px;
  inset: 0 0 auto;
  position: absolute;
}

.client-page .client-stat:nth-child(2)::before {
  background: var(--erp-blue);
}

.client-page .client-stat:nth-child(3)::before {
  background: #d18b20;
}

.client-page .client-stat:nth-child(4)::before {
  background: var(--brand);
}

.client-page .client-stat span {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: .67rem;
  font-weight: 800;
}

.client-page .client-stat strong {
  color: var(--text);
  font-size: clamp(1.35rem, 2.3vw, 1.85rem);
  font-variant-numeric: tabular-nums;
}

.client-page .client-content,
.client-page .client-security {
  border-radius: 6px;
  box-shadow: var(--erp-shadow);
}

.client-page .client-content {
  padding: 1rem;
}

.client-page .client-section-head {
  border-bottom: 1px solid var(--border);
  margin-bottom: .7rem;
  padding-bottom: .85rem;
}

.client-page .client-section-head h2,
.client-page .client-security h2 {
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -.015em;
}

.client-page .client-search {
  font-size: .69rem;
  min-width: min(100%, 320px);
}

.client-page .client-search input {
  border-radius: 4px;
  min-height: 40px;
}

.client-page .client-invoice-table {
  border: 1px solid var(--border);
  border-radius: 4px;
}

.client-page .client-invoice-table th {
  background: #f1f6f4;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .045em;
  text-transform: uppercase;
}

.client-page .client-invoice-table td {
  font-size: .78rem;
}

.client-page .client-security {
  gap: 2rem;
  margin-top: 1rem;
  padding: 1.25rem;
}

.client-page .client-password-form {
  background: #f6f8fa;
  border-radius: 5px;
  padding: 1rem;
}

.client-nav {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--admin-header-height, 72px);
  z-index: 15;
}

.client-nav > div {
  display: flex;
  gap: .25rem;
  margin: 0 auto;
  max-width: 1400px;
  overflow-x: auto;
  padding: 0 1.5rem;
  scrollbar-width: thin;
}

.client-nav a {
  align-items: center;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: .78rem;
  font-weight: 750;
  gap: .5rem;
  min-height: 48px;
  padding: .7rem .85rem;
  text-decoration: none;
}

.client-nav a:hover,
.client-nav a:focus-visible,
.client-nav a[aria-selected="true"] {
  border-bottom-color: var(--brand);
  color: var(--text);
}

.client-nav a[aria-selected="true"] {
  background: var(--surface-soft);
}

.client-view-panel:not([hidden]) {
  animation: client-view-enter 260ms cubic-bezier(.16, 1, .3, 1) both;
}

.client-view-panel[hidden] {
  display: none !important;
}

@keyframes client-view-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.client-hero-actions,
.invoice-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
}

.client-alert {
  background: #fff3f3;
  border: 1px solid #e5a6a6;
  border-left: 4px solid #b3261e;
  border-radius: 5px;
  color: #761711;
  margin-bottom: 1rem;
  padding: .9rem 1rem;
}

.client-section-description {
  color: var(--text-muted);
  font-size: .8rem;
  line-height: 1.55;
  margin: .35rem 0 0;
}

.client-invoice-filters {
  align-items: end;
  background: #f6f8fa;
  border: 1px solid var(--border);
  border-radius: 5px;
  display: grid;
  gap: .75rem;
  grid-template-columns: minmax(220px, 1.5fr) repeat(3, minmax(135px, .7fr)) auto;
  margin-bottom: .75rem;
  padding: .85rem;
}

.client-invoice-filters label {
  color: var(--text-muted);
  display: grid;
  font-size: .69rem;
  font-weight: 800;
  gap: .38rem;
  min-width: 0;
}

.client-invoice-filters input,
.client-invoice-filters select {
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  font-size: .82rem;
  min-height: 42px;
  padding: .6rem .7rem;
  width: 100%;
}

.client-invoice-filters input:focus,
.client-invoice-filters select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), .14);
  outline: 0;
}

.client-clear-filters {
  min-height: 42px;
}

.client-results-status {
  color: var(--text-muted);
  font-size: .76rem;
  margin: .65rem 0;
}

.invoice-due {
  display: block;
  font-size: .68rem;
  font-weight: 800;
  margin-top: .25rem;
}

.invoice-due.is-overdue {
  color: #a22020;
}

.invoice-due.is-today {
  color: #765200;
}

.invoice-actions {
  flex-wrap: nowrap;
}

.invoice-download-link {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  flex: 0 0 40px;
  height: 40px;
  width: 40px;
}

.client-page .client-account {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--erp-shadow);
  margin-top: 1rem;
  padding: clamp(1rem, 2.5vw, 1.5rem);
}

.client-account-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, .8fr);
}

.client-profile-list {
  border: 1px solid var(--border);
  border-radius: 5px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
  overflow: hidden;
}

.client-profile-list > div {
  border-bottom: 1px solid var(--border);
  min-width: 0;
  padding: 1rem;
}

.client-profile-list > div:nth-child(odd) {
  border-right: 1px solid var(--border);
}

.client-profile-list .profile-address {
  border-bottom: 0;
  border-right: 0;
  grid-column: 1 / -1;
}

.client-profile-list dt {
  color: var(--text-muted);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .04em;
  margin-bottom: .35rem;
  text-transform: uppercase;
}

.client-profile-list dd {
  color: var(--text);
  font-size: .84rem;
  margin: 0;
  overflow-wrap: anywhere;
}

.client-preferences-form {
  background: #f6f8fa;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1rem;
}

.client-preferences-form h3 {
  font-size: .95rem;
  margin: 0;
}

.client-preferences-form > p {
  color: var(--text-muted);
  font-size: .76rem;
  line-height: 1.55;
}

.client-data-help {
  border-top: 1px solid var(--border);
  margin: .35rem 0 0;
  padding-top: .8rem;
}

.client-data-help a {
  color: var(--brand-strong);
  font-weight: 750;
}

.client-quotes-grid {
  display: grid;
  gap: .9rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.client-quote-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.client-quote-card h3 {
  font-size: 1rem;
  margin: .65rem 0 .2rem;
}

.client-quote-card p,
.quote-legal-note {
  color: var(--text-muted);
  font-size: .76rem;
  line-height: 1.55;
}

.client-quote-card dl {
  display: grid;
  gap: .6rem;
  grid-template-columns: repeat(2, 1fr);
  margin: 0;
}

.client-quote-card dt {
  color: var(--text-muted);
  font-size: .65rem;
  font-weight: 800;
  text-transform: uppercase;
}

.client-quote-card dd {
  font-weight: 750;
  margin: .2rem 0 0;
}

.client-quote-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

.quote-evidence {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: .58rem;
  overflow-wrap: anywhere;
}

.quote-sign-dialog {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  max-height: 94dvh;
  max-width: min(1180px, calc(100vw - 2rem));
  padding: 0;
  width: 100%;
}

.quote-sign-dialog::backdrop {
  background: rgba(16, 32, 28, .68);
  backdrop-filter: blur(4px);
}

.quote-sign-shell {
  display: grid;
  gap: 1rem;
  max-height: 94dvh;
  overflow: auto;
  padding: clamp(1rem, 3vw, 1.5rem);
}

.quote-sign-warning {
  background: #fff8e6;
  border-left: 4px solid #c27a0b;
  color: #654300;
  margin: 0;
  padding: .85rem 1rem;
}

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

#quotePreviewFrame {
  background: #e8eceb;
  border: 1px solid var(--border);
  min-height: 620px;
  width: 100%;
}

.quote-pages-checklist,
.signature-fieldset {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1rem;
}

.quote-pages-checklist legend,
.signature-fieldset legend {
  font-weight: 800;
  padding-inline: .35rem;
}

.quote-page-check {
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: .6rem;
  padding: .8rem 0;
}

.quote-page-check a {
  color: var(--brand-strong);
  font-weight: 750;
  text-decoration: underline;
}

.quote-page-check label,
.quote-consent {
  align-items: flex-start;
  display: flex;
  font-size: .78rem;
  gap: .6rem;
  line-height: 1.5;
}

.quote-page-check input,
.quote-consent input {
  accent-color: var(--brand);
  flex: 0 0 18px;
  height: 18px;
  margin-top: .1rem;
  width: 18px;
}

.quote-sign-fields {
  display: grid;
  gap: .8rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.quote-sign-fields label {
  color: var(--text-muted);
  display: grid;
  font-size: .72rem;
  font-weight: 750;
  gap: .4rem;
}

.quote-sign-fields input {
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  min-height: 44px;
  padding: .65rem .75rem;
}

#quoteSignatureCanvas {
  background: #fff;
  border: 1px dashed var(--border-strong);
  display: block;
  height: 180px;
  margin-bottom: .75rem;
  max-width: 100%;
  touch-action: none;
  width: 100%;
}

@media (max-width: 800px) {
  .quote-review-layout,
  .quote-sign-fields {
    grid-template-columns: 1fr;
  }

  #quotePreviewFrame {
    min-height: 480px;
  }
}

#billing,
#account,
#security {
  scroll-margin-top: 138px;
}

@media (max-width: 1050px) {
  .client-invoice-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .client-search,
  .client-clear-filters {
    min-width: 0;
  }

  .client-account-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1100px) {
  .admin-page .metrics-grid {
    grid-template-columns: repeat(2, minmax(170px, 1fr));
  }

}

@media (max-width: 700px) {
  .erp-product,
  .erp-user-copy {
    display: none;
  }

  .admin-header .erp-brand .logo {
    width: 130px;
  }

  .admin-page .admin-sidebar {
    padding-inline: .65rem;
  }

  .admin-page .admin-tab {
    min-height: 46px;
    padding-inline: .75rem;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: .8rem;
  }

  .admin-page .metrics-grid {
    grid-template-columns: 1fr;
  }

  .client-page .client-hero {
    align-items: flex-start;
    padding: 1.1rem;
  }

  .client-nav {
    top: 68px;
  }

  .client-nav > div {
    padding-inline: .65rem;
  }

  .client-hero-actions,
  .client-hero-actions .admin-button {
    width: 100%;
  }

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

  .client-profile-list {
    grid-template-columns: 1fr;
  }

  .client-page .client-account {
    padding: 1rem;
  }

  .client-profile-list > div,
  .client-profile-list > div:nth-child(odd) {
    border-bottom: 1px solid var(--border);
    border-right: 0;
  }

  .client-profile-list .profile-address {
    grid-column: auto;
  }

  .invoice-actions {
    justify-content: flex-end;
  }
}
