:root {
  color-scheme: light;
  --ink: #142a44;
  --muted: #52677f;
  --line: #d4dfeb;
  --page: #f2f6fb;
  --paper: #fff;
  --brand: #0a2845;
  --primary: #1e5e9b;
  --primary-hover: #164e83;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--page);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  height: 100vh;
  height: 100dvh;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(165deg, #e6eff9 0, var(--page) 330px);
}

.app-bar {
  position: relative;
  flex: none;
  background: linear-gradient(180deg, #0c3657, var(--brand) 65%, #061b32);
  color: #fff;
  border-bottom: 1px solid #2c6a8b;
}

.app-bar-inner {
  width: min(100% - 40px, 1440px);
  min-height: 58px;
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  letter-spacing: .04em;
  white-space: nowrap;
  font-weight: 650;
}

.brand-mark {
  display: block;
  flex: none;
}

.guest-masthead { display: none; }

.app-bar:has(#account-menu[hidden]) .app-bar-inner {
  min-height: 76px;
  justify-content: center;
}

.app-bar:has(#account-menu[hidden]) .brand { display: none; }

.app-bar:has(#account-menu[hidden]) .guest-masthead {
  display: grid;
  place-items: center;
  align-self: stretch;
  position: relative;
  z-index: 0;
  width: min(570px, 95%);
  font-size: clamp(18px, 2.4vw, 24px);
  letter-spacing: .2em;
  color: #e7f5ff;
}

.guest-masthead::before {
  content: '';
  position: absolute;
  inset: 0 0 9px;
  z-index: -1;
  background: linear-gradient(180deg, #1b608464, #16466422);
  border-top: 2px solid #56cde4;
  clip-path: polygon(0 0, 100% 0, calc(100% - 36px) 100%, 36px 100%);
}

.guest-masthead::after {
  content: '';
  position: absolute;
  inset: auto 5% 8px;
  height: 1px;
  background: linear-gradient(90deg, transparent, #56cde4, transparent);
}

.account-menu {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 16px;
  font-size: 14px;
}

#account-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workbench {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.workspace-outline, .chat-surface, .chat-surface iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.workspace-outline {
  --guest-main: #eff4fa;
  --guest-side: #e7eff8;
  --guest-edge: #bed2e7;
  --guest-composer: #fff;
  --guest-ink: #19344e;
  --guest-muted: #4b6881;
  --guest-action: #176ba5;
  --guest-action-hover: #125b90;
  --guest-action-ink: #fff;
  --guest-button-disabled: #dce8f5;
  display: grid;
  grid-template-columns: clamp(210px, 20vw, 280px) minmax(0, 1fr);
  overflow: auto;
  color: var(--guest-ink);
  background-color: var(--guest-main);
}

.workspace-sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  padding: 23px 16px 16px;
  border-right: 1px solid var(--guest-edge);
  background: var(--guest-side);
}

.guest-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 2px 20px;
  border-bottom: 1px solid var(--guest-edge);
}

.guest-brand img { flex: none; }
.guest-brand strong { display: block; font-size: 21px; letter-spacing: .14em; line-height: 1.25; }
.guest-brand small { color: var(--guest-muted); font-size: 11px; letter-spacing: .12em; }

.guest-account {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--guest-edge);
}

.guest-notice {
  margin-bottom: 10px;
  color: var(--guest-muted);
  font-size: 13px;
  line-height: 1.45;
}

.guest-login-button {
  width: 100%;
  color: var(--guest-action-ink);
  background: var(--guest-action);
}

.guest-login-button:not(:disabled):hover { background: var(--guest-action-hover); }

.guest-stage {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: clamp(28px, 6vh, 52px);
  min-width: 0;
  padding: clamp(24px, 5vh, 64px) clamp(20px, 5vw, 72px);
  background-image: radial-gradient(ellipse at 55% 18%, #1b8cb912, transparent 65%),
    linear-gradient(#2786a905 1px, transparent 1px), linear-gradient(90deg, #2786a905 1px, transparent 1px);
  background-size: auto, 40px 40px, 40px 40px;
}

.guest-hero { text-align: center; }

.guest-hero img {
  display: block;
  width: clamp(58px, 14vh, 84px);
  height: auto;
  margin: 0 auto clamp(14px, 3vh, 25px);
  filter: drop-shadow(0 0 15px #4eb4d82d);
}

.guest-hero h1 {
  font-size: clamp(22px, 2.5vw, 32px);
  letter-spacing: .08em;
  font-weight: 600;
}

.guest-hero p {
  margin-top: 13px;
  color: var(--guest-muted);
  font-size: 14px;
  line-height: 1.6;
}

.workspace-composer {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(100%, 780px);
  padding: 11px 14px;
  border: 1px solid var(--guest-edge);
  border-radius: 9px;
  background: var(--guest-composer);
  box-shadow: 0 8px 28px #00132b12;
}

.workspace-composer textarea {
  flex: 1;
  min-width: 0;
  padding: 8px 0;
  border: 0;
  resize: none;
  color: var(--guest-muted);
  background: transparent;
  font: inherit;
  font-size: 14px;
  opacity: 1;
}

.workspace-composer textarea::placeholder { color: var(--guest-muted); opacity: 1; }

.guest-send {
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  flex: none;
  border: 0;
  border-radius: 50%;
  color: var(--guest-muted);
  background: var(--guest-button-disabled);
  font-size: 21px;
}

@media (prefers-color-scheme: dark) {
  .workspace-outline {
    color-scheme: dark;
    --guest-main: #06192f;
    --guest-side: #081e36;
    --guest-edge: #235272;
    --guest-composer: #0c2a47;
    --guest-ink: #e3f1ff;
    --guest-muted: #9bbbd3;
    --guest-action: #43bdd6;
    --guest-action-hover: #73d7e8;
    --guest-action-ink: #061a30;
    --guest-button-disabled: #1c425e;
  }
}

@media (max-width: 660px) {
  .app-bar:has(#account-menu[hidden]) .app-bar-inner { min-height: 60px; }
  .workspace-outline { grid-template: 'stage' minmax(0, 1fr) 'rail' auto / minmax(0, 1fr); }
  .workspace-sidebar {
    grid-area: rail;
    padding: 10px 16px max(10px, env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--guest-edge);
  }
  .guest-brand { display: none; }
  .guest-account { padding: 0; border-top: 0; }
  .guest-login-button { width: auto; min-width: 86px; }
  .guest-stage { grid-area: stage; overflow: auto; }
}

@media (max-height: 410px) {
  .guest-stage { justify-content: flex-start; gap: 18px; }
  .guest-hero img { width: 50px; }
}

.chat-surface iframe { display: block; border: 0; }
.chat-ready .workspace-outline { display: none; }

@media (min-width: 1050px) {
  .chat-ready .app-bar {
    position: absolute;
    inset: 0 16px auto auto;
    z-index: 1;
    max-width: 315px;
    border: 0;
    background: none;
  }

  .chat-ready .app-bar-inner { width: 100%; min-height: 65px; }
  .chat-ready .brand { display: none; }
}

.workbench-status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  pointer-events: none;
}

.workbench-status button { pointer-events: auto; }
.workbench-status .message { margin: 0; }
.workbench-status p {
  padding: 10px 15px;
  border-radius: 7px;
  background: var(--paper);
  box-shadow: 0 8px 22px #16365318;
}

.startup {
  color: var(--muted);
  text-align: center;
}

dialog, .settings-card {
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
}

dialog {
  max-height: calc(100% - 32px);
  overflow: auto;
  box-shadow: 0 22px 68px #1636533b;
}

dialog::backdrop { background: #142a4455; }

.login-card {
  width: min(100% - 28px, 380px);
  padding: clamp(20px, 5vw, 28px);
}

.login-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.login-heading h1 { font-size: clamp(21px, 4vw, 26px); }

.login-close {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 25px;
  cursor: pointer;
}

.login-close:not(:disabled):hover { background: var(--page); }

@media (prefers-color-scheme: dark) {
  .login-card {
    color-scheme: dark;
    --ink: #e3f1ff;
    --muted: #9bbbd3;
    --line: #235272;
    --paper: #0a2441;
    --page: #102f50;
    --primary: #43bdd6;
    --primary-hover: #73d7e8;
  }
  .login-card input:not([type=checkbox]) { border-color: #307399; }
  .login-card .button-primary { color: #061a30; }
  .login-card .error { color: #ff9ea8; }
}

h1, h2, p { margin: 0; }

h1 {
  font-size: clamp(24px, 4vw, 30px);
  letter-spacing: .015em;
  line-height: 1.4;
}

h2 {
  font-size: 19px;
  line-height: 1.45;
}

.description {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

#login-form { margin-top: 19px; }

.field {
  display: grid;
  gap: 7px;
  margin-top: 17px;
}

.field label, .checkbox-field {
  font-size: 14px;
  font-weight: 600;
}

:where(input, button) { font: inherit; }

input:not([type=checkbox]) {
  min-width: 0;
  height: 42px;
  width: 100%;
  padding: 8px 11px;
  border: 1px solid #acbed1;
  border-radius: 6px;
  color: var(--ink);
  background: var(--paper);
}

input[aria-invalid=true] { border-color: #a12232; }

:where(input, button):focus-visible {
  outline: 3px solid #82b5e7;
  outline-offset: 2px;
}

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 620;
  white-space: nowrap;
}

.button:disabled {
  opacity: .58;
  cursor: default;
}

.button-primary {
  color: #fff;
  background: var(--primary);
}

.button-primary:not(:disabled):hover { background: var(--primary-hover); }

.button-secondary {
  color: var(--brand);
  border-color: #b5c7d9;
  background: #fff;
}

.button-secondary:not(:disabled):hover { background: #f1f6fb; }

.button-light {
  min-height: 34px;
  padding: 5px 11px;
  color: #fff;
  border-color: #a3b7ce;
  background: transparent;
}

.button-light:not(:disabled):hover { background: #ffffff17; }

#login { width: 100%; margin-top: 22px; }

.settings-view {
  width: min(100% - 28px, 580px);
  padding: clamp(20px, 5vw, 28px);
}

.settings-standalone[open] {
  top: 85px;
  bottom: auto;
  max-height: calc(100% - 105px);
}

.page-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.settings-card { padding: clamp(16px, 4vw, 25px); }

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
  min-height: 30px;
}

.checkbox-field input {
  margin: 0;
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
}

.radius-field { max-width: 265px; }

.unit-input {
  position: relative;
}

.unit-input input { padding-right: 45px; }

.unit-input span {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

small { color: var(--muted); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 25px;
}

.message {
  margin-top: 13px;
  font-size: 14px;
  line-height: 1.5;
}

.error { color: #a12232; }
.success { color: #21604c; }
#reload-resources { margin-top: 14px; }

@media (max-width: 540px) {
  .app-bar-inner { width: calc(100% - 20px); min-height: 55px; gap: 8px; }
  .brand { font-size: 18px; gap: 7px; }
  .brand-mark { width: 29px; height: 29px; font-size: 16px; }
  .account-menu { gap: 8px; }
  .button-light { font-size: 12px; padding-inline: 7px; }
  .settings-standalone[open] { top: 68px; }
}
