:root {
  color-scheme: light;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei UI", "Noto Sans CJK SC", system-ui, sans-serif;
  color: #10385f;
  background: #eef8ff;
  --paper: #fff;
  --ink: #10385f;
  --muted: #496682;
  --line: #dbeaf2;
  --river: #0b55aa;
  --river-dark: #124b85;
  --tide: #007f86;
  --sky: #eef8ff;
  --shallows: #f4fcfa;
  --sun: #ffb45b;
  --danger: #a81650;
  --button-gradient: linear-gradient(118deg, var(--river) 0%, #0867a4 51%, #006d75 100%);
  --shadow: 0 26px 74px rgba(16, 65, 106, .14);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; }
h1, h2, p, dl, dd { margin: 0; }
button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }
svg { display: block; width: 20px; height: 20px; flex: none; }

:focus-visible { outline: 3px solid #096ba8; outline-offset: 3px; }
.visually-hidden, .skip-link:not(:focus) {
  width: 1px; height: 1px; padding: 0; overflow: hidden; position: absolute;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip-link:focus {
  position: fixed; z-index: 10; top: .6rem; left: .6rem;
  padding: .75rem 1rem; border-radius: 10px; background: var(--paper); color: var(--river-dark);
}

.topbar { background: rgba(255, 255, 255, .87); border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 1328px; min-height: 72px; margin: 0 auto; padding: 0 32px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 13px; color: #fff; background: var(--button-gradient);
  box-shadow: 0 4px 12px rgba(11, 85, 170, .26);
}
.brand-mark svg { width: 27px; height: 27px; }
.brand-mark svg path:nth-child(2) { color: var(--sun); opacity: 1; }
.brand-name { font-size: 22px; font-weight: 800; letter-spacing: -.035em; }
.topbar-divider { width: 1px; height: 22px; background: var(--line); }
.topbar-label { font-size: 13px; font-weight: 700; color: var(--muted); }
.topbar-action { margin-left: auto; }
.account-menu { position: relative; margin-left: auto; min-width: 0; }
.account-menu > summary { display: flex; list-style: none; max-width: 230px; min-height: 38px; padding: 5px 10px; }
.account-menu > summary::-webkit-details-marker { display: none; }
.account-menu > summary::after {
  content: ""; width: 6px; height: 6px; border: solid currentColor; border-width: 0 1px 1px 0;
  transform: rotate(45deg) translateY(-1px); flex: none;
}
.account-menu[open] > summary { background: var(--sky); }
.account-initial { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: #d9eef9; color: var(--river-dark); flex: none; }
.account-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu-content {
  position: absolute; z-index: 5; top: calc(100% + 6px); right: 0; min-width: 130px;
  display: grid; padding: 4px; background: var(--paper); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: 0 12px 32px #10385f1c;
}
.account-menu-content .button { justify-content: flex-start; min-height: 38px; }

.portal-page, .admin-page {
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at 3% 6%, #deefff 0, transparent 44%),
    radial-gradient(ellipse at 94% 92%, #dcf6ed 0, transparent 42%),
    var(--sky);
}
.workspace {
  width: calc(100% - 64px); max-width: 1248px; margin: 30px auto;
  height: min(848px, calc(100dvh - 132px)); min-height: 510px;
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  overflow: hidden; border-radius: 28px; background: var(--shallows); box-shadow: var(--shadow);
  border: 1px solid #fff;
}
.workspace[data-view="entry"] { max-width: 520px; height: auto; min-height: 0; margin: clamp(24px, 9vh, 88px) auto; }
.status-dot { border-radius: 50%; width: 7px; height: 7px; display: inline-block; flex: none; background: currentColor; }
.workarea { display: flex; min-width: 0; min-height: 0; }
.entry-view {
  width: 100%; display: grid; place-items: center; overflow-y: auto; padding: clamp(24px, 5vw, 58px);
  background: radial-gradient(ellipse at 95% 0%, var(--sky), transparent 53%), var(--paper);
}
.entry-content { width: min(100%, 378px); }
.entry-illustration {
  width: 68px; height: 68px; display: grid; place-items: center; margin-bottom: 24px;
  background: linear-gradient(146deg, #e0f1ff, #e3faf1); color: var(--river);
  border: 1px solid var(--line); border-radius: 22px;
}
.entry-illustration svg { width: 41px; height: 41px; }
.entry-view h1, .admin-login h1, .admin-heading h1 { font-weight: 800; font-size: clamp(28px, 4.2vw, 39px); letter-spacing: -.05em; line-height: 1.18; }
.entry-description { margin-top: 11px; color: var(--muted); font-size: 15px; line-height: 1.75; }
.stack-form { display: grid; gap: 10px; }
.entry-view .stack-form, .admin-login .stack-form { margin-top: 29px; }
.stack-form label, .inline-form label { display: block; font-size: 13px; font-weight: 750; color: var(--ink); }
.stack-form > .button-primary { margin-top: 6px; }
.account-legacy { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 17px; align-items: center; }
.account-legacy .button { min-height: 36px; }
.password-actions { margin-top: 6px; display: flex; gap: 9px; justify-content: flex-end; }
.password-actions .button-primary { flex: 1; }

input, select {
  width: 100%; min-width: 0; min-height: 44px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid #cfdfeb; background: var(--paper); color: var(--ink); line-height: 1.4;
}
input::placeholder, textarea::placeholder { color: #527087; opacity: 1; }
input:focus, select:focus { border-color: #2e83bb; }
input[readonly] { background: var(--sky); font-family: ui-monospace, Consolas, monospace; font-size: 13px; letter-spacing: -.035em; }
.button {
  display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 40px; padding: 9px 14px;
  border: 1px solid transparent; border-radius: 10px; color: inherit; background: transparent;
  font-weight: 750; font-size: 13px; line-height: 1.3; text-decoration: none; text-align: center; cursor: pointer;
}
.button svg { width: 17px; height: 17px; }
.button:disabled { cursor: default; }
.button-primary {
  min-height: 44px; color: #fff; background: var(--button-gradient);
  box-shadow: 0 4px 12px rgba(11, 85, 170, .24);
}
.button-primary:enabled:hover { filter: brightness(1.06); }
.button-primary:disabled { color: #4a657c; background: #e4eef4; box-shadow: none; }
.button-outline { border-color: #c7deec; color: var(--river-dark); background: var(--paper); }
.button-outline:enabled:hover, .button-text:enabled:hover { background: #e7f3fc; }
.button-outline:disabled, .button-text:disabled { opacity: .72; }
.button-text { color: var(--river-dark); }
.button-danger { color: var(--danger); border-color: #f1c8d9; }
.button-danger:enabled:hover { background: #fff0f6; }
.button-icon { padding: 0; min-height: 36px; width: 36px; color: var(--muted); }
.button-icon:hover { background: var(--sky); }
.form-error { color: var(--danger); font-size: 13px; line-height: 1.55; }

.chat-view { width: 100%; display: flex; flex-direction: column; height: 100%; min-width: 0; min-height: 0; }
.chat-header {
  display: flex; align-items: center; gap: 12px; min-height: 79px; padding: 14px clamp(15px, 3vw, 30px);
  background: #fff; border-bottom: 1px solid var(--line);
}
.channel-icon {
  width: 45px; height: 45px; display: grid; place-items: center; flex: none;
  color: var(--river); background: linear-gradient(130deg, #e0efff, #e1f8f1); border-radius: 14px;
}
.channel-icon svg { width: 23px; height: 23px; }
.channel-title { min-width: 0; }
.channel-title h1 { font-size: clamp(18px, 2.4vw, 23px); font-weight: 800; letter-spacing: -.038em; line-height: 1.25; overflow-wrap: anywhere; }
.channel-title p { color: var(--muted); font-size: 12px; margin-top: 3px; }
.lease-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; line-height: 1.5; }
.lease-remaining, .expires-at { white-space: nowrap; }
.countdown { color: var(--ink); font-weight: 750; font-variant-numeric: tabular-nums; }
.countdown[data-soon="true"] { color: #824400; background: #fff0d9; border-radius: 6px; padding: 1px 5px; }
.renew-toggle { flex: none; min-height: 36px; padding: 7px 12px; }
.status-chip {
  --status-color: #2e5879; --status-bg: #eaf2f7; margin-left: auto;
  display: inline-flex; flex: none; align-items: center; gap: 7px;
  border-radius: 999px; padding: 6px 10px; color: var(--status-color); background: var(--status-bg);
  font-size: 12px; font-weight: 750; white-space: nowrap;
}
.status-chip[data-state="waiting"], .status-chip[data-state="available"] { --status-color: #086447; --status-bg: #ddf8ea; }
.status-chip[data-state="running"], .status-chip[data-state="leased"] { --status-color: #164e9d; --status-bg: #e6f1ff; }
.status-chip[data-state="offline"] { --status-color: #495f73; --status-bg: #e9eff3; }
.status-chip[data-state="draining"], .status-chip[data-state="retrying"] { --status-color: #824400; --status-bg: #fff0d9; }
.status-chip[data-state="preparing"] { --status-color: #0b6471; --status-bg: #dff6f6; }
.status-chip[data-state="failed"] { --status-color: #9c2145; --status-bg: #fce8ef; }
.renew-box { padding: 12px clamp(15px, 3vw, 30px); border-bottom: 1px solid var(--line); background: var(--sky); }
.inline-form { display: flex; align-items: end; gap: 10px; }
.inline-form .field-grow { min-width: 0; flex: 1; }
.inline-form input { margin-top: 6px; }
.inline-note { margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.inline-note[data-tone="error"] { color: var(--danger); }
.inline-note[data-tone="success"] { color: #09614c; }
.conversation {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-color: #a3c4d7 transparent;
  padding: 21px clamp(15px, 3vw, 30px);
  background: radial-gradient(ellipse at 96% -9%, #e7f5ff 0, transparent 66%), var(--shallows);
}
.conversation:focus-visible { outline-offset: -4px; }
.history-controls { text-align: center; margin-bottom: 12px; }
.message-list { display: grid; gap: 18px; width: min(100%, 800px); margin: 0 auto; }
.message-row { display: flex; align-items: flex-start; gap: 9px; }
.message-avatar {
  display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 10px;
  background: #dff1fd; color: var(--river);
}
.message-avatar svg { width: 20px; height: 20px; }
.message-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 5px; line-height: 1.5; font-size: 12px; color: var(--muted); }
.message-author { color: #285678; font-weight: 750; }
.message-content { max-width: min(86%, 650px); min-width: 0; }
.message-bubble {
  white-space: pre-wrap; overflow-wrap: anywhere; border-radius: 4px 15px 15px;
  border: 1px solid var(--line); background: var(--paper); padding: 11px 14px;
  font-size: 14px; line-height: 1.7; box-shadow: 0 3px 7px rgba(16, 65, 106, .05);
}
.message-row[data-role="user"] { justify-content: flex-end; }
.message-row[data-role="user"] .message-avatar { display: none; }
.message-row[data-role="user"] .message-meta { justify-content: flex-end; }
.message-row[data-role="user"] .message-bubble { color: white; background: var(--button-gradient); border-color: transparent; border-radius: 15px 4px 15px 15px; }
.chat-empty { min-height: 100%; display: flex; flex-direction: column; gap: 8px; justify-content: center; align-items: center; padding: 14px 12px; text-align: center; }
.empty-symbol { display: grid; place-items: center; width: 57px; height: 57px; border-radius: 19px; margin-bottom: 6px; color: var(--river); background: #ddf0fc; }
.empty-symbol svg { width: 30px; height: 30px; }
.chat-empty h2 { font-weight: 800; font-size: 18px; letter-spacing: -.02em; }
.chat-empty p { color: var(--muted); font-size: 13px; line-height: 1.55; }
.compose-area { background: #fff; padding: 12px clamp(15px, 3vw, 30px) 16px; border-top: 1px solid var(--line); }
.compose-form {
  max-width: 800px; margin: 0 auto; border: 1px solid #cfe3ef; background: var(--paper); border-radius: 15px;
  box-shadow: 0 4px 14px #10416a0d; overflow: hidden;
}
.compose-form:focus-within { border-color: #2e83bb; }
.compose-form textarea {
  display: block; width: 100%; min-height: 54px; max-height: 155px; resize: vertical; border: 0; padding: 11px 13px;
  background: transparent; color: var(--ink); line-height: 1.45; font-size: 14px; outline-offset: -3px;
}
.compose-form textarea:disabled { background: #f3f8fb; }
.compose-tools { padding: 0 9px 8px 12px; display: flex; gap: 8px; align-items: center; }
.keyboard-hint, .compose-count { color: var(--muted); font-size: 11px; white-space: nowrap; }
.keyboard-hint kbd { font: inherit; font-weight: 700; }
.compose-count { margin-left: auto; font-variant-numeric: tabular-nums; }
.compose-count[data-tone="error"] { color: var(--danger); }
.send-button { min-height: 38px; margin-left: auto; }
.compose-count:not([hidden]) + .send-button { margin-left: 0; }
.compose-notice { max-width: 800px; margin: 0 auto 8px; font-size: 12px; color: #335874; line-height: 1.45; }
.compose-notice[data-tone="error"] { color: var(--danger); }

.admin-main {
  max-width: 1328px; width: 100%; padding: 38px 32px 55px; margin: 0 auto;
}
.surface { background: var(--paper); border: 1px solid var(--line); border-radius: 21px; box-shadow: 0 15px 42px #10416a0c; }
.admin-login { width: min(100%, 480px); margin: clamp(20px, 11vh, 100px) auto 0; padding: clamp(23px, 5vw, 43px); }
.admin-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.admin-heading p { color: var(--muted); font-size: 14px; line-height: 1.6; margin-top: 7px; }
.admin-heading-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.metrics { display: grid; grid-template-columns: repeat(var(--metric-columns, 5), minmax(0, 1fr)); gap: 12px; margin: 0 0 19px; }
.metrics[data-rotation="enabled"] { --metric-columns: 6; }
.metric { border-radius: 15px; min-width: 0; min-height: 92px; padding: 15px; background: #dff3fb; color: #144c6b; }
.metric-mint { background: #ddf8eb; color: #0d6348; }
.metric-blue { background: #e0eeff; color: #164e92; }
.metric-orange { background: #fff0d8; color: #7d450b; }
.metric-teal { background: #def6f6; color: #0b6170; }
.metric-muted { background: #eaf0f4; color: #465f73; }
.metric dt { font-size: 13px; line-height: 1.3; font-weight: 700; }
.metric dd { font-size: 30px; font-variant-numeric: tabular-nums; margin-top: 6px; line-height: 1; font-weight: 800; }
.session-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; padding: 18px 18px 14px; }
.session-toolbar h2, .dialog-heading h2 { font-weight: 800; font-size: 19px; letter-spacing: -.035em; }
.session-toolbar p { font-size: 12px; margin-top: 4px; }
.muted { color: var(--muted); line-height: 1.55; font-size: 13px; }
.session-filters { display: flex; gap: 8px; }
.session-filters input { width: 200px; }
.session-filters select { width: auto; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 12px 13px; border-top: 1px solid var(--line); }
th:first-child, td:first-child { padding-left: 18px; }
th:last-child, td:last-child { padding-right: 18px; }
th { color: var(--muted); background: #f4f9fd; font-weight: 750; font-size: 12px; }
td { color: var(--ink); font-size: 13px; }
td:first-child { width: 27%; }
.session-name { font-size: 14px; font-weight: 800; overflow-wrap: anywhere; }
.session-id, .session-meta { font-size: 12px; color: var(--muted); display: inline-block; margin-top: 4px; overflow-wrap: anywhere; }
.session-id { font-family: ui-monospace, Consolas, monospace; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.row-actions .button { min-height: 35px; padding: 6px 9px; }
.admin-empty, .admin-notice { margin: 0 18px; padding: 16px 0; line-height: 1.5; font-size: 13px; color: var(--muted); }
.admin-notice[data-tone="error"] { color: var(--danger); }
.admin-notice[data-tone="success"] { color: #09614c; }
.account-surface { margin-top: 19px; scroll-margin-top: 18px; }
.accounts-table td:nth-child(2) { width: 27%; }
.action-dialog { width: min(100% - 28px, 465px); max-height: calc(100dvh - 32px); padding: 21px; border: 1px solid var(--line); color: var(--ink); border-radius: 18px; box-shadow: var(--shadow); }
.action-dialog::backdrop { background: #11365475; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.code-fields, .code-result, .copy-area { display: grid; gap: 8px; }
.code-fields, .code-result { margin: 8px 0; }
.dialog-actions, .copy-field { display: flex; align-items: center; gap: 8px; }
.dialog-actions { justify-content: flex-end; }
.copy-field input { flex: 1; }
.provision-prompt {
  width: 100%; min-width: 0; padding: 10px 12px; resize: vertical;
  border: 1px solid #cfdfeb; border-radius: 10px;
  background: var(--sky); color: var(--ink); font-size: 13px; line-height: 1.5;
}
.provision-prompt-copy { justify-self: start; }

@media (max-width: 860px) {
  .workspace { width: calc(100% - 36px); margin: 18px auto; height: calc(100dvh - 108px); border-radius: 21px; }
  .topbar-inner, .admin-main { padding-left: 18px; padding-right: 18px; }
  .metrics[data-rotation="enabled"] { --metric-columns: 3; }
}
@media (max-width: 640px) {
  .topbar-inner { min-height: 56px; gap: 11px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
  .brand-mark svg { width: 23px; height: 23px; }
  .brand-name { font-size: 19px; }
  .account-menu > summary { max-width: min(38vw, 180px); min-height: 34px; gap: 6px; }
  .topbar-label { white-space: nowrap; }
  .workspace { width: calc(100% - 18px); height: calc(100dvh - 74px); min-height: 470px; margin: 8px auto; border-radius: 17px; }
  .workspace[data-view="entry"] { max-width: none; height: auto; min-height: calc(100dvh - 74px); margin: 8px auto; }
  .entry-view { padding: 25px 20px; }
  .chat-header { min-height: 63px; padding: 9px 12px; gap: 8px; }
  .channel-icon { width: 37px; height: 37px; border-radius: 11px; }
  .channel-icon svg { width: 20px; height: 20px; }
  .channel-title p { font-size: 11px; }
  .lease-summary { display: grid; gap: 0; }
  .lease-separator { display: none; }
  .status-chip { font-size: 11px; gap: 5px; padding: 5px 7px; }
  .renew-toggle { width: 36px; padding: 0; }
  .renew-toggle-label {
    width: 1px; height: 1px; overflow: hidden; position: absolute;
    clip-path: inset(50%); white-space: nowrap;
  }
  .conversation { padding: 14px 10px; }
  .compose-area { padding: 8px 8px 10px; }
  .compose-form textarea { font-size: 16px; }
  .keyboard-hint { display: none; }
  .message-content { max-width: 84%; }
  .admin-main { padding: 22px 10px 35px; }
  .admin-heading { align-items: start; flex-direction: column; }
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .metric { padding: 11px 10px; min-height: 68px; }
  .metric dd { font-size: 25px; }
  .session-filters { width: 100%; }
  .session-filters input { flex: 1; width: auto; }
  .session-filters input, .session-filters select { font-size: 13px; min-height: 38px; }
  th, td { padding: 9px; }
  th { white-space: nowrap; }
  td:first-child { min-width: 118px; }
}
@media (prefers-reduced-motion: no-preference) {
  .button { transition: background .15s ease, filter .15s ease, border-color .15s ease; }
}
