:root {
  --bg: #eef4ff;
  --surface: rgba(255, 255, 255, 0.76);
  --surface-strong: rgba(255, 255, 255, 0.94);
  --surface-alt: rgba(242, 248, 255, 0.82);
  --ink: #12233d;
  --muted: #66788f;
  --line: rgba(101, 132, 179, 0.18);
  --line-strong: rgba(46, 115, 224, 0.3);
  --brand: #1150d5;
  --brand-strong: #0b3b97;
  --brand-soft: #eaf2ff;
  --accent: #05b8da;
  --accent-soft: rgba(5, 184, 218, 0.14);
  --success: #10956f;
  --success-soft: rgba(16, 149, 111, 0.14);
  --danger: #d85170;
  --danger-soft: rgba(216, 81, 112, 0.14);
  --terminal: #091624;
  --terminal-line: rgba(255, 255, 255, 0.06);
  --shadow: 0 30px 90px rgba(84, 119, 172, 0.16);
  --shadow-soft: 0 18px 42px rgba(101, 132, 179, 0.12);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --sans: "Manrope", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --display: "Space Grotesk", "Noto Sans SC", "PingFang SC", sans-serif;
  --mono: "Fira Code", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 10% 12%, rgba(17, 80, 213, 0.18), transparent 0 22%),
    radial-gradient(circle at 88% 10%, rgba(5, 184, 218, 0.16), transparent 0 20%),
    linear-gradient(180deg, #f8fbff 0%, #edf4ff 54%, #e8f0ff 100%);
  color: var(--ink);
  font-family: var(--sans);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(67, 110, 176, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(67, 110, 176, 0.045) 1px, transparent 1px);
  background-size: 54px 54px;
  mask-image: radial-gradient(circle at center, black 56%, transparent 100%);
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app-shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 20px 0 28px;
}

.workspace-shell[hidden],
.login-shell[hidden] {
  display: none;
}

.login-shell {
  min-height: calc(100vh - 28px);
  display: grid;
  place-items: center;
}

.login-card,
.topbar,
.panel {
  position: relative;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.login-card::after,
.topbar::after,
.panel::after,
.message-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.86), transparent 30%, transparent 72%, rgba(17, 80, 213, 0.14));
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.login-card {
  width: min(100%, 560px);
  padding: 38px;
  border-radius: 32px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(243, 248, 255, 0.82));
}

.login-form {
  display: grid;
  gap: 18px;
  margin-top: 28px;
}

.login-field {
  display: grid;
  gap: 10px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.login-field input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.88);
}

.login-field input {
  min-height: 54px;
  padding: 0 16px;
}

.login-field input:focus,
textarea:focus {
  outline: none;
  border-color: var(--line-strong);
  box-shadow: 0 0 0 4px rgba(17, 80, 213, 0.12);
}

.login-actions {
  display: grid;
  gap: 10px;
}

.login-error {
  color: var(--danger);
  font-size: 14px;
  line-height: 1.6;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding: 22px 24px;
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(242, 248, 255, 0.82));
}

.eyebrow,
.panel-kicker,
.hint {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 12px;
  font-weight: 700;
}

.topbar h1,
.panel-header h2,
.login-card h1 {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: -0.05em;
}

h1 {
  margin-top: 10px;
  font-size: clamp(32px, 3vw, 46px);
  line-height: 0.98;
  background: linear-gradient(135deg, #0c1f3c 0%, var(--brand) 60%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.topbar-copy {
  max-width: 44ch;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.75;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.pill-badge,
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 800;
}

.pill-badge {
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(17, 80, 213, 0.12);
  color: var(--brand-strong);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 18px;
  height: calc(100vh - 178px);
  min-height: 680px;
}

.side-column {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(240px, 320px);
  gap: 18px;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(242, 248, 255, 0.8));
}

.panel-header,
.chat-form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header {
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--line);
}

.chat-panel,
.terminal-panel {
  min-height: 0;
}

.chat-form {
  display: grid;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.74), rgba(241, 247, 255, 0.82));
}

.chat-form.is-busy {
  background: linear-gradient(180deg, rgba(239, 247, 255, 0.9), rgba(232, 243, 255, 0.86));
}

#messageInput {
  min-height: 118px;
  max-height: 132px;
}

textarea {
  resize: vertical;
  padding: 16px 18px;
  line-height: 1.75;
}

.composer-meta {
  display: grid;
  gap: 6px;
}

.composer-state {
  font-size: 13px;
  line-height: 1.6;
}

.composer-state.idle {
  color: var(--brand);
}

.composer-state.busy {
  color: var(--accent);
}

.composer-state.done {
  color: var(--success);
}

.composer-state.error {
  color: var(--danger);
}

.primary-button,
.ghost-button {
  min-height: 46px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease,
    background-color 180ms ease;
  font-weight: 700;
}

.primary-button {
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #ffffff;
  box-shadow: 0 18px 34px rgba(17, 80, 213, 0.22);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  border-color: var(--line);
}

.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.ghost-button:disabled {
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  opacity: 0.56;
}

.chat-messages,
.terminal-log {
  overflow: auto;
}

.chat-messages {
  min-height: 0;
  flex: 1;
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 20px;
}

.message-card {
  position: relative;
  max-width: 92%;
  padding: 16px 18px;
  border-radius: 22px;
  border: 1px solid var(--line);
  line-height: 1.7;
  white-space: pre-wrap;
  box-shadow: var(--shadow-soft);
}

.message-card.user {
  justify-self: end;
  background: linear-gradient(180deg, rgba(231, 241, 255, 0.96), rgba(220, 234, 255, 0.88));
}

.message-card.assistant {
  max-width: min(74%, 680px);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(243, 248, 255, 0.92));
}

.message-role,
.message-time,
.empty-chat,
.empty-state {
  color: var(--muted);
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.message-role {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.message-time {
  font-size: 12px;
  white-space: nowrap;
}

.message-content {
  color: var(--ink);
  max-height: 240px;
  overflow: auto;
  padding-right: 4px;
}

.quota-body {
  display: grid;
  gap: 16px;
  padding: 18px 20px 20px;
}

.quota-state {
  font-size: 13px;
  line-height: 1.7;
}

.quota-state.idle,
.quota-state.loading {
  color: var(--brand);
}

.quota-state.success {
  color: var(--success);
}

.quota-state.warning {
  color: #9a6700;
}

.quota-state.error {
  color: var(--danger);
}

.quota-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.metric-chip,
.quota-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(239, 246, 255, 0.88));
  box-shadow: var(--shadow-soft);
}

.metric-chip {
  padding: 16px;
}

.metric-chip p,
.metric-chip span,
.quota-card-head {
  color: var(--muted);
}

.metric-chip p,
.metric-chip span {
  font-size: 12px;
  line-height: 1.6;
}

.metric-chip strong {
  display: block;
  margin: 6px 0 4px;
  font-family: var(--display);
  font-size: 24px;
  letter-spacing: -0.04em;
  color: var(--ink);
}

.quota-sections {
  display: grid;
  gap: 12px;
}

.quota-card {
  padding: 16px;
}

.quota-card-head {
  margin-bottom: 12px;
}

.quota-card h3 {
  font-family: var(--display);
  font-size: 18px;
  letter-spacing: -0.03em;
}

.quota-card-head p,
.redeem-state {
  font-size: 13px;
  line-height: 1.7;
}

.quota-card-head p {
  margin-top: 6px;
}

.redeem-card {
  gap: 14px;
}

.redeem-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.redeem-form input {
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.88);
}

.redeem-form input:focus {
  outline: none;
  border-color: var(--line-strong);
  box-shadow: 0 0 0 4px rgba(17, 80, 213, 0.12);
}

.redeem-state.idle,
.redeem-state.loading {
  color: var(--brand);
}

.redeem-state.success {
  color: var(--success);
}

.redeem-state.error {
  color: var(--danger);
}

.terminal-log {
  flex: 1;
  max-height: 360px;
  padding: 18px 20px 22px;
  background:
    linear-gradient(180deg, rgba(10, 24, 40, 0.98), rgba(9, 22, 36, 1)),
    var(--terminal);
  color: #dbe7f5;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
}

.terminal-line {
  padding: 8px 10px;
  border-radius: 10px;
  white-space: pre-wrap;
}

.terminal-line + .terminal-line {
  margin-top: 6px;
}

.terminal-line.command {
  color: #ffcf7a;
  background: var(--terminal-line);
}

.terminal-line.output {
  color: #dbe5f2;
}

.terminal-line.system {
  color: #86d9ff;
}

.terminal-line.success {
  color: #62e6ad;
}

.terminal-line.error {
  color: #ff8aa7;
}

.status-badge {
  min-width: 104px;
}

.status-badge.idle {
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(17, 80, 213, 0.12);
  color: var(--brand-strong);
}

.status-badge.busy {
  background: var(--accent-soft);
  border-color: rgba(5, 184, 218, 0.18);
  color: var(--accent);
}

.status-badge.done {
  background: var(--success-soft);
  border-color: rgba(16, 149, 111, 0.2);
  color: var(--success);
}

.status-badge.error {
  background: var(--danger-soft);
  border-color: rgba(216, 81, 112, 0.2);
  color: var(--danger);
}

.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;
}

@media (max-width: 1024px) {
  .layout {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .side-column {
    grid-template-rows: auto minmax(240px, 320px);
  }

  .chat-panel {
    min-height: 560px;
  }

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

  .terminal-panel {
    min-height: 320px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 20px, 100%);
    padding: 14px 0 20px;
  }

  .login-card,
  .topbar,
  .panel {
    border-radius: 24px;
  }

  .login-card,
  .topbar,
  .panel-header,
  .chat-form,
  .terminal-log {
    padding-left: 18px;
    padding-right: 18px;
  }

  .topbar,
  .topbar-actions,
  .chat-form-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .redeem-form {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
