:root {
  color-scheme: light;
  --paper: #f7fafc;
  --paper-deep: #eaf1f6;
  --ink: #072e62;
  --ink-2: #143e6f;
  --ink-soft: #4d6075;
  --muted: #71808e;
  --green: #19b8b1;
  --green-dark: #078d91;
  --mint: #dff7f5;
  --blue: #d9ebf7;
  --lavender: #eee9ff;
  --border: #d9e1e5;
  --border-strong: #c7d3dc;
  --white: #ffffff;
  --danger: #b33b4a;
  --danger-bg: #fff1f2;
  --warning: #946200;
  --warning-bg: #fff8df;
  --success: #087b69;
  --success-bg: #e8f8f3;
  --shadow-sm: 0 10px 28px rgba(24, 49, 72, 0.07);
  --shadow-md: 0 22px 55px rgba(24, 49, 72, 0.11);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --focus: rgba(25, 184, 177, 0.28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  overflow-x: hidden;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Geist", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
a { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 10px;
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* Public and authentication pages */
.public-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(430px, 0.92fr);
}
.public-story {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 100vh;
  padding: 42px clamp(34px, 5vw, 78px);
  color: #f7fbfc;
  background:
    radial-gradient(circle at 10% 12%, rgba(25, 184, 177, 0.28), transparent 34%),
    radial-gradient(circle at 92% 72%, rgba(125, 175, 245, 0.18), transparent 36%),
    var(--ink);
}
.public-story::after {
  content: "";
  position: absolute;
  width: 540px;
  height: 540px;
  right: -260px;
  top: 70px;
  border: 1px solid rgba(108, 224, 198, 0.18);
  border-radius: 50%;
  box-shadow: 0 0 0 78px rgba(108, 224, 198, 0.045), 0 0 0 156px rgba(108, 224, 198, 0.025);
}
.public-brand,
.portal-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
  text-decoration: none;
}
.public-brand img { width: 176px; filter: brightness(0) invert(1); }
.public-story-copy { position: relative; z-index: 1; max-width: 660px; }
.public-story-copy h1 {
  margin: 0;
  max-width: 650px;
  font-family: Iowan Old Style, Baskerville, Georgia, "Times New Roman", serif;
  font-size: clamp(46px, 5.2vw, 74px);
  font-weight: 500;
  line-height: 0.98;
  letter-spacing: -0.055em;
}
.public-story-copy > p:not(.eyebrow) {
  max-width: 610px;
  margin: 28px 0 0;
  color: #c7d2dc;
  font-size: 17px;
  line-height: 1.7;
}
.public-proof {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 42px;
}
.public-proof article {
  min-height: 118px;
  padding: 18px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  background: rgba(255,255,255,0.055);
}
.public-proof span {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-bottom: 15px;
  border-radius: 10px;
  color: #91ead6;
  background: rgba(108, 224, 198, 0.12);
}
.public-proof strong { display: block; font-size: 13px; }
.public-proof small { display: block; margin-top: 5px; color: #9eb0bf; line-height: 1.45; }
.public-story-footer { position: relative; z-index: 1; color: #8fa3b4; font-size: 12px; }

.public-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 34px clamp(24px, 5vw, 72px);
  background: var(--paper);
}
.auth-card { width: min(100%, 520px); }
.auth-card h2,
.public-simple h1 {
  margin: 0;
  font-family: Iowan Old Style, Baskerville, Georgia, "Times New Roman", serif;
  font-size: clamp(36px, 4vw, 52px);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -0.045em;
}
.auth-card > .muted { margin: 16px 0 30px; line-height: 1.65; }
.auth-form { display: grid; gap: 18px; }
.field { display: grid; gap: 7px; }
.field-label,
.auth-form label,
.form-grid label,
.filter-grid label {
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 680;
}
.field-help { color: var(--muted); font-size: 11px; font-weight: 450; line-height: 1.45; }
input, select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 0 13px;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border .18s, box-shadow .18s, background .18s;
}
textarea { min-height: 100px; padding-top: 12px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #95a3af; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 4px var(--focus); }
.password-field { position: relative; }
.password-field input { padding-right: 74px; }
.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  padding: 7px 9px;
  border: 0;
  color: var(--green-dark);
  background: transparent;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius-sm);
  font-weight: 720;
  text-decoration: none;
  cursor: pointer;
  transition: transform .18s, box-shadow .18s, background .18s, border .18s;
}
.button:hover { transform: translateY(-1px); }
.button-primary {
  color: #042f4f;
  background: linear-gradient(135deg, #22c6bc, #0f9fa4);
  box-shadow: 0 12px 28px rgba(32, 185, 152, 0.22);
}
.button-primary:hover { box-shadow: 0 16px 34px rgba(32, 185, 152, 0.3); }
.button-secondary { color: var(--ink); background: var(--white); border: 1px solid var(--border); }
.button-ghost { color: var(--green-dark); background: transparent; border: 1px solid var(--green); }
.button-danger { color: var(--danger); background: var(--danger-bg); border: 1px solid #f2c5ca; }
.button-small { min-height: 36px; padding: 0 12px; font-size: 12px; }
button[disabled] { opacity: .58; cursor: wait; transform: none; }
.auth-row { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.auth-row a, .text-link { color: var(--green-dark); font-size: 12px; font-weight: 680; text-decoration: none; }
.auth-message {
  display: none;
  margin: 18px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.5;
}
.auth-message.visible { display: block; }
.auth-message.error { color: var(--danger); background: var(--danger-bg); border: 1px solid #f2c5ca; }
.auth-message.success { color: var(--success); background: var(--success-bg); border: 1px solid #bfe8dd; }
.advanced-auth { margin-top: -4px; }
.advanced-auth summary { color: var(--muted); font-size: 11px; cursor: pointer; }
.advanced-auth .field { margin-top: 12px; }
.auth-security {
  display: flex;
  gap: 10px;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}
.auth-security svg { flex: 0 0 auto; color: var(--green-dark); }
.public-simple {
  width: min(100%, 650px);
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--white);
  box-shadow: var(--shadow-sm);
}
.public-simple .muted { line-height: 1.65; }
.public-simple form { margin-top: 24px; }
.public-simple pre { display: none; }

/* Authenticated portal */
.portal-shell { min-height: 100vh; }
.portal-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: 268px;
  display: flex;
  flex-direction: column;
  color: #f6f9fb;
  background:
    radial-gradient(circle at 0 0, rgba(25,184,177,.20), transparent 28%),
    var(--ink);
  border-right: 1px solid rgba(255,255,255,.07);
}
.portal-brand {
  min-height: 82px;
  padding: 0 24px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.portal-brand img { width: 152px; filter: brightness(0) invert(1); }
.portal-client {
  margin: 20px 18px 8px;
  padding: 16px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 13px;
  background: rgba(255,255,255,.055);
}
.portal-client small { color: #92a6b7; font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
.portal-client strong { display: block; margin-top: 6px; font-size: 13px; line-height: 1.4; }
.portal-nav { flex: 1; overflow-y: auto; padding: 10px 14px 20px; }
.nav-group { margin-top: 20px; }
.nav-group:first-child { margin-top: 0; }
.nav-group-title {
  display: block;
  padding: 0 10px 8px;
  color: #8399aa;
  font-size: 9px;
  font-weight: 760;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.portal-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 42px;
  margin: 3px 0;
  padding: 0 11px;
  color: #c9d4dc;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 580;
  text-decoration: none;
  transition: background .16s, color .16s, border .16s;
}
.portal-nav a:hover { color: #fff; background: rgba(255,255,255,.06); }
.portal-nav a[aria-current="page"] {
  color: #eafffa;
  background: rgba(25,184,177,.14);
  border-color: rgba(108,224,198,.22);
}
.nav-icon {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  flex: 0 0 auto;
  border-radius: 8px;
  color: #8edfd2;
  background: rgba(108,224,198,.08);
  font-size: 12px;
}
.portal-sidebar-footer {
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.portal-sidebar-footer a {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #9fb0bd;
  font-size: 11px;
  text-decoration: none;
}
.portal-workspace { min-height: 100vh; margin-left: 268px; }
.portal-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 clamp(22px, 4vw, 52px);
  border-bottom: 1px solid rgba(16,37,63,.10);
  background: rgba(247,250,252,.92);
  backdrop-filter: blur(18px);
}
.topbar-title small { display: block; color: var(--muted); font-size: 11px; }
.topbar-title strong { display: block; margin-top: 3px; font-size: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--white);
}
.user-meta { text-align: right; }
.user-meta strong { display: block; max-width: 210px; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
.user-meta small { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; }
.user-avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: var(--ink); background: var(--mint); font-size: 11px; font-weight: 800; }
.menu-toggle { display: none; }
.portal-main { padding: 36px clamp(22px, 4vw, 52px) 64px; }
.panel { display: none; max-width: 1420px; }
.panel.active { display: block; animation: panel-in .25s ease both; }
@keyframes panel-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 26px;
}
.page-heading h1,
.page-heading h2 {
  margin: 0;
  font-family: Iowan Old Style, Baskerville, Georgia, "Times New Roman", serif;
  font-size: clamp(34px, 4vw, 48px);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -0.045em;
}
.page-heading p { max-width: 720px; margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.status {
  min-height: 18px;
  margin: 12px 0;
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 680;
}
.status.error { color: var(--danger); }

.contract-overview {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, .65fr);
  gap: 28px;
  padding: 28px;
  color: #fff;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 92% -10%, rgba(25,184,177,.36), transparent 36%),
    linear-gradient(135deg, #072e62, #0b3e71);
  box-shadow: var(--shadow-md);
}
.contract-overview::after {
  content: "";
  position: absolute;
  width: 300px;
  height: 300px;
  right: -190px;
  bottom: -220px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 50%;
}
.contract-copy { position: relative; z-index: 1; }
.contract-copy .eyebrow { color: #91ead6; }
.contract-copy h3 { margin: 0; font-size: 24px; letter-spacing: -.03em; }
.contract-copy p { max-width: 660px; margin: 12px 0 0; color: #b9c7d2; font-size: 12px; line-height: 1.65; }
.contract-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
}
.badge-success { color: #075f53; background: #dff7f5; }
.badge-neutral { color: #4d6075; background: #eef3f6; }
.badge-warning { color: var(--warning); background: var(--warning-bg); }
.badge-danger { color: var(--danger); background: var(--danger-bg); }
.contract-usage { position: relative; z-index: 1; align-self: center; }
.contract-usage-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.contract-usage-head strong { font-size: 28px; letter-spacing: -.04em; }
.contract-usage-head small { color: #a9bac7; font-size: 10px; }
.progress {
  height: 9px;
  margin-top: 13px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
}
.progress > span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #6ce0c6, #22c6bc); transition: width .4s ease; }
.contract-usage p { display: flex; justify-content: space-between; margin: 10px 0 0; color: #a9bac7; font-size: 10px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}
.metric-card {
  min-height: 146px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255,255,255,.86);
  box-shadow: var(--shadow-sm);
}
.metric-card-top { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.metric-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; color: var(--green-dark); background: var(--mint); font-size: 15px; }
.metric-card small { color: var(--muted); font-size: 10px; }
.metric-value { display: block; margin-top: 18px; font-size: 30px; font-weight: 720; letter-spacing: -.045em; }
.metric-label { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 11px; }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, .75fr);
  gap: 18px;
  margin-top: 18px;
}
.surface {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--white);
  box-shadow: var(--shadow-sm);
}
.surface-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.surface-heading h3 { margin: 0; font-size: 15px; letter-spacing: -.02em; }
.surface-heading p { margin: 5px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.chart-empty, .empty-state {
  min-height: 170px;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  text-align: center;
  font-size: 11px;
}
.bar-chart { display: grid; gap: 13px; }
.bar-row { display: grid; grid-template-columns: 82px minmax(0, 1fr) 46px; gap: 10px; align-items: center; font-size: 10px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); }
.bar-track { height: 9px; overflow: hidden; border-radius: 999px; background: var(--paper-deep); }
.bar-fill { display: block; height: 100%; min-width: 3px; border-radius: inherit; background: linear-gradient(90deg, var(--green), var(--green-dark)); }
.bar-value { text-align: right; font-weight: 700; }
.summary-list { display: grid; gap: 12px; }
.summary-item { display: flex; justify-content: space-between; gap: 14px; align-items: center; padding: 13px 0; border-bottom: 1px solid var(--border); }
.summary-item:last-child { border-bottom: 0; }
.summary-item span { display: block; color: var(--ink-soft); font-size: 11px; }
.summary-item strong { font-size: 13px; }
.summary-item small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }

.panel-card {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--white);
  box-shadow: var(--shadow-sm);
}
.report-layout { display: grid; gap: 16px; }
.filters {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--paper);
}
.filters summary {
  padding: 14px 16px;
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 720;
  cursor: pointer;
}
.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 13px;
  padding: 0 16px 16px;
}
.filter-grid label { display: grid; gap: 6px; }
.filter-grid input, .filter-grid select { min-height: 40px; font-size: 11px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toolbar .download { margin-left: auto; }
.toolbar .download a { color: var(--green-dark); font-size: 11px; font-weight: 700; text-decoration: none; }
.rows { margin-top: 14px; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; min-width: 840px; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; z-index: 1; color: var(--ink-soft); background: #f2f6f8; font-size: 9px; font-weight: 760; letter-spacing: .07em; text-transform: uppercase; }
td { color: #354c63; font-size: 10px; line-height: 1.5; }
tbody tr:hover { background: #f9fbfc; }
tbody tr:last-child td { border-bottom: 0; }
.table-empty { padding: 36px; color: var(--muted); text-align: center; font-size: 11px; }

.split-grid { display: grid; grid-template-columns: minmax(300px, .6fr) minmax(0, 1.4fr); gap: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid label { display: grid; gap: 7px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.form-note { margin: 8px 0 0; color: var(--muted); font-size: 10px; line-height: 1.55; }
.result-note { display: none; margin-top: 12px; padding: 11px 12px; border-radius: 8px; font-size: 11px; }
.result-note.visible { display: block; }
.result-note.success { color: var(--success); background: var(--success-bg); }
.result-note.error { color: var(--danger); background: var(--danger-bg); }

.mobile-overlay { display: none; }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 920px) {
  .public-shell { grid-template-columns: 1fr; }
  .public-story { display: none; }
  .portal-sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  body.sidebar-open .portal-sidebar { transform: translateX(0); }
  .portal-workspace { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .mobile-overlay { position: fixed; inset: 0; z-index: 35; background: rgba(3, 22, 42, .48); }
  body.sidebar-open .mobile-overlay { display: block; }
  .contract-overview { grid-template-columns: 1fr; }
  .split-grid { grid-template-columns: 1fr; }
}

@media (max-width: 650px) {
  .public-panel { padding: 24px 18px; }
  .portal-topbar { min-height: 72px; padding: 0 16px; }
  .portal-main { padding: 26px 16px 48px; }
  .user-meta { display: none; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .metric-grid, .filter-grid, .form-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 128px; }
  .contract-overview, .surface, .panel-card { padding: 18px; }
  .toolbar { align-items: stretch; }
  .toolbar .button { width: 100%; }
  .toolbar .download { margin-left: 0; }
}

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