:root {
  --ecosystem-navy: #07182d;
  --ecosystem-navy-soft: #0d2440;
  --ecosystem-blue: #2f80ed;
  --ecosystem-blue-strong: #1d4ed8;
  --ecosystem-indigo: #4338ca;
  --ecosystem-green: #20c997;
  --ecosystem-ink: #10233f;
  --ecosystem-muted: #58708c;
  --ecosystem-page: #eef5ff;
  --ecosystem-border: #dbe8f6;
  --ecosystem-shadow: 0 18px 44px rgba(34, 79, 122, 0.11);
}

html {
  background: var(--ecosystem-page);
}

body.app-shell {
  min-height: 100vh;
  color: var(--ecosystem-ink);
  background:
    radial-gradient(circle at 92% 4%, rgba(47, 128, 237, 0.12), transparent 30%),
    radial-gradient(circle at 10% 90%, rgba(32, 201, 151, 0.08), transparent 28%),
    linear-gradient(135deg, #f7fbff 0%, #eef6ff 52%, #e8f3ef 100%);
}

body.app-shell .app-bg {
  display: none;
}

/* Authenticated product shell: shared M.A.D.S / M.A.S.S language */
.product-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
}

.product-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 28px 22px 22px;
  color: #dbeafe;
  background: linear-gradient(180deg, var(--ecosystem-navy) 0%, var(--ecosystem-navy-soft) 100%);
  box-shadow: 14px 0 38px rgba(15, 35, 65, 0.16);
  z-index: 30;
}

.product-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
}

.product-brand-mark,
.public-brand-mark,
.auth-brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  color: #fff;
  font-weight: 850;
  background: linear-gradient(135deg, var(--ecosystem-blue), var(--ecosystem-green));
  box-shadow: 0 12px 26px rgba(32, 201, 151, 0.2);
}

.product-brand-copy {
  min-width: 0;
  display: grid;
  line-height: 1.18;
}

.product-brand-copy strong {
  color: #fff;
  font-size: 1.02rem;
  letter-spacing: 0.04em;
}

.product-brand-copy small {
  max-width: 165px;
  margin-top: 4px;
  overflow: hidden;
  color: #a9c1da;
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-nav {
  display: grid;
  gap: 8px;
}

.product-nav-label {
  margin: 0 0 4px 12px;
  color: #7794b4;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.product-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px;
  border-radius: 14px;
  color: #b8c9dc;
  font-weight: 700;
  text-decoration: none;
  transition: 0.2s ease;
}

.product-nav a:hover,
.product-nav a:focus-visible,
.product-nav a.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  outline: none;
}

.product-nav-icon {
  width: 24px;
  color: #80b7ff;
  font-size: 0.92rem;
  text-align: center;
}

.product-sidebar-account {
  margin-top: auto;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
}

.product-sidebar-account strong,
.product-sidebar-account small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-sidebar-account strong {
  color: #fff;
  font-size: 0.86rem;
}

.product-sidebar-account small {
  margin-top: 3px;
  color: #a9c1da;
  font-size: 0.72rem;
}

.product-logout {
  width: 100%;
  margin-top: 12px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 10px;
  color: #dbeafe;
  background: rgba(255, 255, 255, 0.08);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 750;
  cursor: pointer;
}

.product-main-shell {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.product-topbar {
  position: sticky;
  top: 0;
  z-index: 25;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--ecosystem-border);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
}

.product-topbar-copy strong,
.product-topbar-copy small {
  display: block;
}

.product-topbar-copy strong {
  color: var(--ecosystem-ink);
  font-size: 0.94rem;
}

.product-topbar-copy small {
  margin-top: 2px;
  color: var(--ecosystem-muted);
  font-size: 0.76rem;
}

.product-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border: 1px solid #cce9df;
  border-radius: 999px;
  color: #0f8f68;
  background: #e9fbf4;
  font-size: 0.74rem;
  font-weight: 800;
}

.product-status::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ecosystem-green);
  content: '';
}

.product-content {
  width: min(100% - 48px, 1480px);
  margin-inline: auto;
  padding: 28px 0 44px;
}

.product-footer {
  margin-top: auto;
  padding: 20px 28px 26px;
  color: #70809b;
  font-size: 0.78rem;
  text-align: center;
}

/* Shared surfaces and controls */
body.app-shell .section-shell,
body.app-shell .card-surface,
body.app-shell .table-card,
body.app-shell .metric-card {
  border-color: var(--ecosystem-border);
  box-shadow: var(--ecosystem-shadow);
}

body.app-shell .section-shell {
  background: rgba(255, 255, 255, 0.96);
}

body.app-shell .btn-primary,
.public-page .btn-primary,
.auth-page .btn-primary {
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, var(--ecosystem-blue) 0%, var(--ecosystem-indigo) 58%, var(--ecosystem-green) 145%);
  box-shadow: 0 12px 24px rgba(47, 128, 237, 0.22);
}

body.app-shell .btn-primary:hover,
.public-page .btn-primary:hover,
.auth-page .btn-primary:hover {
  background: linear-gradient(135deg, #256fda 0%, #392fae 60%, #19af83 145%);
}

body.app-shell .btn-secondary,
.public-page .btn-secondary {
  border-color: #d7e4f5;
  color: #29476c;
  background: #fff;
}

body.app-shell input,
body.app-shell textarea,
body.app-shell select,
.public-page input,
.public-page textarea,
.public-page select {
  border-color: #d8e5f3;
  background: #fbfdff;
}

body.app-shell input:focus-visible,
body.app-shell textarea:focus-visible,
body.app-shell select:focus-visible,
.public-page input:focus-visible,
.public-page textarea:focus-visible,
.public-page select:focus-visible {
  border-color: #7eb6f3;
  outline-color: rgba(47, 128, 237, 0.15);
}

body.app-shell .badge-primary {
  border-color: #c9dcfb;
  color: #226ebd;
  background: #edf6ff;
}

body.app-shell .badge-success {
  border-color: #cce9df;
  color: #0f8f68;
  background: #e9fbf4;
}

body.app-shell .eyebrow,
.public-page .eyebrow,
.auth-page .eyebrow {
  color: #2f6fb8;
}

body.app-shell .data-table th {
  color: #58708c;
  background: #f4f8fd;
}

/* Invoice editor ecosystem overrides */
.invoice-editor-header,
.invoice-document-toolbar {
  background:
    radial-gradient(circle at 90% 0%, rgba(32, 201, 151, 0.12), transparent 34%),
    linear-gradient(135deg, #f9fcff 0%, #eef6ff 100%);
}

.invoice-editor-grid {
  background: linear-gradient(135deg, #f7fbff 0%, #eef6ff 100%);
}

.invoice-panel-icon {
  color: #fff;
  background: linear-gradient(135deg, var(--ecosystem-blue), var(--ecosystem-green));
  box-shadow: 0 9px 18px rgba(47, 128, 237, 0.18);
}

.invoice-summary-total strong {
  color: var(--ecosystem-blue-strong);
}

/* Public marketing: Magos trust layer + product accents */
.public-page {
  min-height: 100vh;
  margin: 0;
  color: var(--ecosystem-ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(47, 128, 237, 0.12), transparent 32%),
    radial-gradient(circle at 92% 14%, rgba(32, 201, 151, 0.08), transparent 28%),
    linear-gradient(180deg, #fbfdff 0%, #f4f8fd 100%);
}

.public-header {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid rgba(219, 232, 246, 0.96);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
}

.public-header-inner {
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 30px;
}

.public-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ecosystem-ink);
  font-size: 1.22rem;
  font-weight: 850;
  text-decoration: none;
}

.public-brand-copy {
  display: grid;
  line-height: 1.12;
}

.public-brand-copy small {
  margin-top: 3px;
  color: #6d8198;
  font-size: 0.64rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.public-nav {
  display: flex;
  align-items: center;
  gap: 26px;
  margin-left: auto;
}

.public-nav a {
  color: #45617f;
  font-weight: 700;
  text-decoration: none;
}

.public-nav a:hover {
  color: var(--ecosystem-blue-strong);
}

.public-actions {
  display: flex;
  gap: 10px;
}

.public-main {
  padding-top: 38px;
  padding-bottom: 72px;
}

.public-footer {
  padding: 30px 0;
  border-top: 1px solid var(--ecosystem-border);
  color: #667b93;
  background: #fff;
}

.public-footer-inner {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

/* Authentication */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(420px, 0.95fr);
  color: var(--ecosystem-ink);
  background: #f5f8ff;
}

.auth-showcase {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 64px clamp(32px, 6vw, 96px);
  color: #dbeafe;
  background: linear-gradient(160deg, var(--ecosystem-navy) 0%, var(--ecosystem-navy-soft) 72%, #123c4c 130%);
}

.auth-showcase::after {
  position: absolute;
  width: 520px;
  height: 520px;
  right: -180px;
  bottom: -220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(32, 201, 151, 0.24), transparent 68%);
  content: '';
}

.auth-showcase > * {
  position: relative;
  z-index: 1;
}

.auth-showcase h1 {
  max-width: 760px;
  margin: 22px 0;
  color: #fff;
  font-size: clamp(42px, 5vw, 72px);
  line-height: 1.02;
  letter-spacing: -0.055em;
}

.auth-showcase h1 span {
  color: #80b7ff;
}

.auth-showcase p {
  max-width: 680px;
  color: #b8c9dc;
  font-size: 19px;
  line-height: 1.7;
}

.auth-benefits {
  display: grid;
  gap: 14px;
  margin-top: 28px;
}

.auth-benefit {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #dbeafe;
  font-weight: 700;
}

.auth-check {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, var(--ecosystem-blue), var(--ecosystem-green));
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: #fff;
}

.auth-card {
  width: min(100%, 520px);
  padding: 42px;
  border: 1px solid var(--ecosystem-border);
  border-radius: 28px;
  box-shadow: 0 24px 70px rgba(16, 35, 63, 0.13);
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ecosystem-ink);
  font-size: 23px;
  font-weight: 800;
  text-decoration: none;
}

.auth-card h2 {
  margin: 30px 0 8px;
  font-size: 34px;
  letter-spacing: -0.035em;
}

.auth-card > .lead {
  margin: 0 0 28px;
  color: #667b93;
}

.auth-form {
  display: grid;
  gap: 18px;
}

.auth-form label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.auth-form input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid #d8e5f3;
  border-radius: 12px;
  color: var(--ecosystem-ink);
  background: #fbfdff;
  font: inherit;
  box-sizing: border-box;
}

.auth-form input:focus {
  border-color: #7eb6f3;
  outline: 3px solid rgba(47, 128, 237, 0.15);
}

.auth-submit {
  width: 100%;
  justify-content: center;
  padding: 15px 18px;
  border: 0;
  cursor: pointer;
  font-size: 16px;
}

.auth-alert {
  margin-bottom: 18px;
  padding: 13px 15px;
  border: 1px solid #fecdca;
  border-radius: 12px;
  color: #b42318;
  background: #fff1f0;
}

.auth-switch {
  margin: 22px 0 0;
  color: #667b93;
  text-align: center;
}

.auth-switch a {
  color: var(--ecosystem-blue-strong);
  font-weight: 800;
  text-decoration: none;
}

@media (max-width: 980px) {
  .product-shell {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .product-sidebar {
    padding-inline: 16px;
  }

  .product-brand-copy,
  .product-nav a span:not(.product-nav-icon),
  .product-nav-label,
  .product-sidebar-account strong,
  .product-sidebar-account small {
    display: none;
  }

  .product-brand,
  .product-nav a {
    justify-content: center;
  }

  .product-sidebar-account {
    padding: 10px;
  }

  .product-logout {
    padding-inline: 5px;
    font-size: 0.68rem;
  }
}

@media (max-width: 820px) {
  .public-nav {
    display: none;
  }

  .public-actions {
    margin-left: auto;
  }

  .public-actions .btn-secondary {
    display: none;
  }

  .public-header-inner {
    min-height: 68px;
  }
}

@media (max-width: 720px) {
  .product-shell {
    display: block;
  }

  .product-sidebar {
    position: static;
    width: 100%;
    height: auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 16px;
  }

  .product-brand {
    justify-content: flex-start;
  }

  .product-brand-copy,
  .product-nav-label,
  .product-sidebar-account strong,
  .product-sidebar-account small {
    display: grid;
  }

  .product-nav {
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .product-nav a {
    justify-content: flex-start;
    white-space: nowrap;
  }

  .product-nav a span:not(.product-nav-icon) {
    display: inline;
  }

  .product-sidebar-account {
    display: none;
  }

  .product-topbar {
    position: static;
    padding-inline: 18px;
  }

  .product-content {
    width: min(100% - 24px, 1480px);
    padding-top: 18px;
  }

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

  .auth-showcase {
    display: none;
  }

  .auth-panel {
    min-height: 100vh;
    padding: 20px;
  }

  .auth-card {
    padding: 30px 24px;
  }
}
