:root {
  color-scheme: light;
  --ink: #18243a;
  --muted: #596981;
  --surface: #ffffff;
  --backdrop: #f4f6fa;
  --line: #dce3ef;
  --primary: #4e43c5;
  --primary-dark: #3b31a7;
  --soft: #eeebff;
  --nav: #131c32;
  --green: #087353;
  --green-back: #e3f4ec;
  --red: #a33342;
  --red-back: #fae9ec;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--backdrop);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; }
button, .button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
a, button, input, select { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #8a7df8; outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(2rem, 3vw, 2.7rem); line-height: 1.14; letter-spacing: -.04em; }
h2 { font-size: 1.26rem; letter-spacing: -.018em; line-height: 1.3; }
h3 { font-size: 1.04rem; }
p { color: var(--muted); }
a { color: var(--primary-dark); }
.skip-link { position: fixed; z-index: 100; top: .5rem; left: .5rem; padding: .6rem 1rem; background: #fff; transform: translateY(-150%); }
.skip-link:focus { transform: none; }

.primary, .outline, .subtle, .link-button, .text-button {
  border-radius: .55rem;
  border: 1px solid transparent;
  padding: .65rem .95rem;
  font-weight: 650;
  font-size: .88rem;
  min-height: 42px;
}
.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.primary:hover:not(:disabled) { background: var(--primary-dark); }
.outline { color: var(--ink); border-color: var(--line); background: #fff; }
.outline:hover:not(:disabled), .subtle:hover:not(:disabled) { background: var(--backdrop); }
.subtle, .text-button, .link-button { color: var(--primary-dark); background: transparent; }
.text-button { padding-inline: .45rem; }
.small { min-height: 36px; padding: .35rem .62rem; }
.button { display: inline-flex; align-items: center; text-decoration: none; }
.full { width: 100%; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.muted { color: var(--muted); }
.block { display: block; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88rem; }

label { display: grid; gap: .38rem; font-size: .9rem; font-weight: 650; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: .58rem .72rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cbd5e5;
  border-radius: .5rem;
}
input[readonly] { background: var(--backdrop); }

.brand { display: flex; align-items: center; gap: .72rem; font-size: 1.04rem; color: #f6f7ff; font-weight: 730; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 2.3rem; height: 2.3rem; border-radius: .62rem; background: #7063eb; color: #fff; font-weight: 800; font-size: 1.2rem; }
.auth-shell { display: grid; grid-template-columns: minmax(0, 47fr) minmax(0, 53fr); min-height: 100vh; }
.auth-side {
  display: flex; flex-direction: column; justify-content: space-between;
  padding: clamp(1.8rem, 4.8vw, 5rem);
  background: radial-gradient(ellipse at 10% 90%, #2e2c68, transparent 67%), #131c32;
  color: #fff;
}
.auth-message h1 { margin: .95rem 0; font-size: clamp(3rem, 6.1vw, 6.3rem); letter-spacing: -.065em; }
.auth-message p { color: #d4dced; max-width: 29rem; font-size: 1.08rem; }
.auth-bottom { color: #c5cde4; font-size: .9rem; }
.auth-stats { display: grid; grid-template-columns: repeat(3, 1fr); max-width: 31rem; gap: .5rem; border-top: 1px solid #ffffff3a; padding-top: 1rem; margin-top: 2.2rem; }
.auth-stats span { display: block; color: #c9d0e7; font-size: .86rem; }
.auth-stats strong { font-size: .94rem; }
.auth-main { background: #fff; display: grid; place-items: center; padding: 2rem; }
.auth-form { width: min(100%, 25rem); }
.auth-form h2 { font-size: 2rem; margin-bottom: .5rem; }
.auth-form form { display: grid; gap: 1rem; margin-top: 1.5rem; }
.auth-form .link-button { margin: .7rem 0 0 -.9rem; }
.mobile-brand { display: none; }
.loading { min-height: 65vh; display: grid; place-items: center; color: var(--muted); }

.shell { min-height: 100vh; display: grid; grid-template-columns: 15rem minmax(0, 1fr); }
.sidebar { background: var(--nav); color: #d4dced; padding: 1.45rem 1.15rem; display: flex; flex-direction: column; gap: 2.5rem; }
.sidebar nav { display: grid; gap: .45rem; }
.nav-item { text-align: left; display: flex; align-items: center; gap: .7rem; background: none; color: #d4dced; border: 1px solid transparent; border-radius: .58rem; padding: .68rem .72rem; font-weight: 620; }
.nav-item.current { background: #30295f; color: #fff; border-color: #474176; }
.nav-item > span { display: grid; place-items: center; width: 1.1rem; color: #b3a9ff; }
.nav-item:hover { background: #252e48; }
.sidebar-foot { margin-top: auto; border-top: 1px solid #ffffff22; padding: .9rem .25rem 0; font-size: .85rem; }
.sidebar-foot strong { display: block; color: #c2b9ff; }
.main-column { min-width: 0; }
.top { min-height: 65px; background: #fff; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: .85rem; padding: .7rem clamp(1rem, 3vw, 2.8rem); }
.top-name { font-size: .91rem; font-weight: 650; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: .68rem; }
.avatar { display: grid; place-items: center; background: var(--soft); color: var(--primary-dark); font-size: .77rem; font-weight: 730; width: 2rem; height: 2rem; border-radius: 50%; }
.user-name { font-size: .9rem; font-weight: 660; max-width: 10rem; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
main:not(.auth-main):not(.loading) { max-width: 1500px; padding: clamp(1rem, 3vw, 2.8rem); margin-inline: auto; }
.page-title { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.35rem; }
.page-title p { margin-top: .42rem; }
.broker, .button-row, .dialog-actions, .basket-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.tag { border-radius: 999px; display: inline-flex; padding: .24rem .6rem; font-size: .76rem; font-weight: 730; white-space: nowrap; background: var(--backdrop); color: #455575; }
.tag.good { background: var(--green-back); color: var(--green); }
.tag.bad { background: var(--red-back); color: var(--red); }
.tag.neutral { background: var(--soft); color: #4535a5; }
.tag.pilot-tag { background: #ffffff22; color: #eeeaff; }

.quotes, .admin-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .85rem; margin-bottom: 1rem; }
.quote-card { display: grid; justify-items: start; gap: .11rem; padding: .88rem 1rem; background: #fff; border: 1px solid var(--line); border-radius: .72rem; color: var(--ink); }
.quote-card.selected { border-color: #8575ee; box-shadow: inset 0 0 0 1px #8575ee; }
.quote-card span { font-size: .8rem; font-weight: 675; }
.quote-card span:first-child { color: var(--muted); }
.quote-card strong { font-size: 1.48rem; font-variant-numeric: tabular-nums; }

.panel { min-width: 0; padding: 1.18rem; background: #fff; border: 1px solid var(--line); border-radius: .74rem; }
.panel-head { display: flex; flex-wrap: wrap; align-items: start; justify-content: space-between; gap: .5rem; margin-bottom: .95rem; }
.panel-head p { margin-top: .24rem; font-size: .88rem; }
.workspace-grid { display: grid; grid-template-columns: minmax(0, 1.18fr) minmax(0, 1fr); align-items: start; gap: .9rem; }
.template-form, .scenario-form { display: flex; align-items: end; flex-wrap: wrap; gap: .52rem; margin: .3rem 0 .85rem; }
.template-form > label:first-child { flex: 1 1 12rem; }
.scenario-form > label { flex: 1 1 8rem; max-width: 14rem; }
.leg-form { display: grid; grid-template-columns: minmax(8rem, 1fr) minmax(4rem, 5rem) 4rem auto; align-items: end; gap: .52rem; margin: .3rem 0 .85rem; }
.table-wrap { min-width: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: .87rem; border-top: 1px solid var(--line); }
th, td { padding: .62rem .46rem; vertical-align: middle; }
th { font-size: .8rem; font-weight: 660; color: var(--muted); background: #f7f8fc; }
tr + tr, tbody { border-top: 1px solid var(--line); }
.empty { text-align: center; padding: 1.3rem .55rem; border-top: 1px solid var(--line); font-size: .91rem; }
.basket-actions, .dialog-actions { justify-content: flex-end; margin-top: .85rem; }
.chart-empty { display: grid; place-items: center; min-height: 185px; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .35rem; border-bottom: 1px solid var(--line); padding-bottom: .65rem; }
.metrics span, .admin-stats span { font-size: .82rem; color: var(--muted); }
.metrics strong, .admin-stats strong { display: block; margin-top: .14rem; }
canvas { width: 100%; height: auto; margin-top: .4rem; }
.chart-label { font-size: .83rem; }
.chart-label strong { color: var(--ink); margin-left: .2rem; }
.chart-toggle { display: flex; align-items: center; gap: .45rem; margin-top: .7rem; }
.chart-toggle input { width: auto; min-height: 0; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .85rem; margin-bottom: .5rem; color: var(--muted); font-size: .82rem; }
.chart-legend span::before { display: inline-block; content: ''; width: 1.25rem; border-top: 2px solid #5547d6; margin: 0 .35rem .2rem 0; }
.chart-legend .modeled::before { border-top: 2px dashed #0e799a; }
.saved { margin-top: .9rem; }
.locked { max-width: 42rem; }
.locked p { margin: .55rem 0 .85rem; }

.subscription-grid, .admin-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .9rem; align-items: start; }
.admin-grid { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
.admin-stats strong { font-size: 1.5rem; }
.plan-price { display: flex; align-items: baseline; gap: .5rem; margin: .55rem 0; }
.plan-price strong { font-size: 2.45rem; letter-spacing: -.045em; }
.plan-price span { color: var(--muted); }
dl { display: grid; gap: .35rem; padding: .8rem 0; margin: .85rem 0; border-bottom: 1px solid var(--line); border-top: 1px solid var(--line); }
dl > div { display: flex; justify-content: space-between; gap: 1rem; }
dt { color: var(--muted); }
dd { text-align: right; margin: 0; font-weight: 635; }
.checkout-status { margin: .65rem 0; padding: .75rem; background: var(--backdrop); border-radius: .55rem; }
.checkout-status p { margin: .35rem 0 .7rem; font-size: .9rem; }
.invite { display: grid; gap: .65rem; margin-bottom: .9rem; }
.invite button { justify-self: start; }
.broker-settings { display: grid; gap: 1rem; max-width: 42rem; }
.broker-settings .panel-head { margin-bottom: 0; }
.broker-settings fieldset { display: grid; gap: .85rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.broker-settings fieldset button { justify-self: start; }
.broker-picker { display: flex; flex-wrap: wrap; gap: .7rem; align-items: end; }
.broker-picker label { flex: 1 1 14rem; }
.broker-detail { display: grid; gap: .8rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.order-leg { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.order-leg + .order-leg { margin-top: .32rem; }

dialog { width: min(93vw, 29rem); border: 1px solid var(--line); border-radius: .78rem; box-shadow: 0 24px 65px #0d152950; padding: 1.4rem; }
dialog::backdrop { background: #1118276b; }
dialog h2 { margin: 0 0 .45rem; }
dialog p { margin: .4rem 0 .6rem; }
.review-legs { margin: .5rem 0 1rem; padding-left: 1.3rem; font-size: .93rem; }
.notice { position: fixed; bottom: 1rem; right: 1rem; max-width: min(28rem, 94vw); z-index: 100; color: #fff; background: var(--nav); padding: .7rem .95rem; border-radius: .55rem; box-shadow: 0 8px 25px #17234636; }
.notice.danger { background: #8a293b; }

@media (max-width: 1100px) {
  .workspace-grid, .admin-grid { grid-template-columns: 1fr; }
  .payoff { max-width: 100%; }
  .shell { grid-template-columns: 13.3rem minmax(0, 1fr); }
  .brand { font-size: .92rem; }
}
@media (max-width: 720px) {
  .shell { display: block; }
  .sidebar { padding: .75rem .9rem; display: block; }
  .sidebar nav { display: flex; gap: .25rem; margin-top: .55rem; overflow: auto; }
  .nav-item { white-space: nowrap; padding: .5rem .45rem; font-size: .83rem; }
  .sidebar-foot, .user-name { display: none; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .auth-main { min-height: 100svh; padding: 1.3rem; }
  .mobile-brand { display: flex; color: var(--ink); margin-bottom: 1.2rem; }
  .subscription-grid { grid-template-columns: 1fr; }
  .quote-card { padding: .61rem .55rem; }
  .quotes, .admin-stats { gap: .5rem; }
  .quote-card strong { font-size: 1.15rem; }
  .panel { padding: .85rem; }
}
@media (max-width: 450px) {
  .leg-form { grid-template-columns: 1fr 1fr; }
  .quote-card strong { font-size: .94rem; }
  .top { padding: .5rem .75rem; }
  .top-actions { gap: .27rem; }
  h1 { font-size: 1.85rem; }
  th, td { padding: .48rem .35rem; }
  .admin-stats { grid-template-columns: 1fr; }
}
