:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8f9fa;
  --text: #17202a;
  --muted: #66717f;
  --border: #dce1e7;
  --border-strong: #c8d0d9;
  --green: #176b5b;
  --green-dark: #0f5548;
  --blue: #236fc8;
  --danger: #a33a3a;
  --shadow: 0 18px 50px rgba(27, 39, 51, 0.16);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
  overflow: hidden;
}

button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-frame {
  height: 100dvh;
  display: grid;
  grid-template-rows: 62px minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.brand-lockup, .topbar-actions, .usage-heading, .usage-meta, .view-header,
.composer-meta, .payment-heading { display: flex; align-items: center; }

.brand-lockup { gap: 10px; min-width: 0; }

.brand-mark, .message-avatar {
  display: grid;
  place-items: center;
  background: var(--green);
  color: #fff;
  font-weight: 750;
  flex: 0 0 auto;
}

.brand-mark { width: 32px; height: 32px; border-radius: 6px; font-size: 12px; }
.brand-name { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { gap: 10px; min-width: 0; }

.service-state, .model-badge {
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.service-state { display: inline-flex; align-items: center; gap: 6px; }
.state-dot { width: 7px; height: 7px; border-radius: 50%; background: #2b9a68; }
.model-badge { padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-soft); }

.app-body {
  min-height: 0;
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
}

.sidebar {
  min-height: 0;
  padding: 16px 14px;
  background: #eef1f4;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
}

.button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 650;
  color: var(--text);
  background: var(--surface);
}

.button svg, .nav-item svg, .icon-button svg, .send-button svg { width: 17px; height: 17px; stroke-width: 2; }
.button-primary { color: #fff; background: var(--green); border-color: var(--green); }
.button-primary:hover { background: var(--green-dark); }
.button-quiet { background: var(--surface); border-color: var(--border); }
.button-quiet:hover { border-color: var(--border-strong); background: var(--surface-soft); }
.button-danger { color: var(--danger); border-color: #e6caca; background: #fffafa; }
.button-wide { width: 100%; }
.new-chat { width: 100%; }

.nav-list { display: grid; gap: 4px; }
.nav-item {
  min-height: 40px;
  border: 0;
  border-radius: 5px;
  padding: 8px 10px;
  background: transparent;
  color: #4b5663;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.68); color: var(--text); }
.nav-item.active { background: var(--surface); color: var(--green); box-shadow: inset 3px 0 0 var(--green); }

.sidebar-usage {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border-strong);
}
.usage-heading, .usage-meta { justify-content: space-between; gap: 10px; }
.usage-heading span, .usage-meta { color: var(--muted); font-size: 12px; }
.usage-heading strong { color: var(--text); font-size: 14px; }
.progress-track { height: 6px; margin: 10px 0; background: #d4dae1; overflow: hidden; border-radius: 3px; }
.progress-track span { display: block; height: 100%; width: 0; background: var(--green); transition: width .25s ease; }
.text-command { border: 0; padding: 0; color: var(--blue); background: transparent; font-weight: 650; }

.workspace { min-width: 0; min-height: 0; background: var(--surface); }
.view { display: none; height: 100%; min-width: 0; }
.view.active { display: block; }
.chat-view.active { display: grid; grid-template-rows: minmax(0, 1fr) auto; }

.messages {
  overflow-y: auto;
  padding: 30px max(24px, calc((100% - 860px) / 2));
  scroll-behavior: smooth;
}

.message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 26px;
}
.message-avatar { width: 34px; height: 34px; border-radius: 6px; font-size: 11px; }
.user-message .message-avatar { background: #394553; }
.message-body { min-width: 0; padding-top: 1px; }
.message-role { margin-bottom: 6px; font-size: 12px; font-weight: 700; color: var(--muted); }
.message-content { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; font-size: 15px; }
.typing .message-content { color: var(--muted); }

.composer {
  padding: 12px max(24px, calc((100% - 860px) / 2)) 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.composer-box {
  min-height: 54px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  align-items: end;
  gap: 10px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 4px 18px rgba(30, 45, 60, .07);
}
.composer-box:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23,107,91,.10); }
textarea {
  width: 100%;
  min-height: 34px;
  max-height: 150px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 7px 0;
  color: var(--text);
  background: transparent;
  line-height: 1.45;
}
.send-button, .icon-button {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.send-button { width: 38px; height: 38px; border: 0; border-radius: 6px; color: #fff; background: var(--green); }
.send-button:disabled { cursor: not-allowed; opacity: .45; }
.composer-meta { justify-content: space-between; gap: 12px; margin-top: 7px; color: var(--muted); font-size: 11px; }

.info-view { padding: 34px max(28px, calc((100% - 900px) / 2)); overflow-y: auto; }
.info-view.active { display: block; }
.view-header { justify-content: space-between; gap: 20px; padding-bottom: 22px; border-bottom: 1px solid var(--border); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: 22px; }
h2 { margin-bottom: 8px; font-size: 20px; }
.view-header p, .modal-content > p, .payment-heading p { margin-bottom: 0; color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 1px; margin: 24px 0; background: var(--border); border: 1px solid var(--border); }
.metric { padding: 22px; background: var(--surface); }
.metric span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.metric strong { font-size: 23px; }
.detail-list { border-top: 1px solid var(--border); margin-bottom: 22px; }
.detail-list > div { min-height: 54px; display: grid; grid-template-columns: 150px minmax(0,1fr); align-items: center; gap: 14px; border-bottom: 1px solid var(--border); }
.detail-list span { color: var(--muted); }
code { font-family: "Cascadia Code", Consolas, monospace; overflow-wrap: anywhere; }
.api-details > div:first-child { grid-template-columns: 150px minmax(0,1fr) 36px; }
.icon-button { width: 34px; height: 34px; padding: 0; border-radius: 5px; }
.icon-button:hover { background: var(--surface-soft); }
.code-block { margin: 22px 0 0; padding: 18px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; background: #1e252c; color: #eef3f7; line-height: 1.6; }

.management-section { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--border); }
.section-heading { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-heading h2 { margin-bottom: 3px; font-size: 16px; }
.section-heading p { margin-bottom: 0; color: var(--muted); font-size: 12px; }
.record-list { border-top: 1px solid var(--border); }
.record-row { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border); }
.record-body { min-width: 0; display: grid; grid-template-columns: minmax(110px, .7fr) minmax(160px, 1fr) minmax(150px, 1fr); align-items: center; gap: 14px; }
.record-body strong, .record-body code, .record-body span { min-width: 0; overflow-wrap: anywhere; }
.record-body span { color: var(--muted); font-size: 12px; }
.status-approved .record-body strong { color: var(--green); }
.status-rejected .record-body strong { color: var(--danger); }

.modal {
  width: min(440px, calc(100% - 28px));
  max-height: calc(100dvh - 30px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--text);
  background: var(--surface);
}
.modal::backdrop { background: rgba(20, 28, 36, .55); }
.modal-content { position: relative; padding: 28px; }
.modal-icon { width: 42px; height: 42px; display: grid; place-items: center; margin-bottom: 18px; border-radius: 7px; color: var(--green); background: #e5f1ee; }
.modal-icon svg { width: 21px; height: 21px; }
.modal label { display: block; margin: 22px 0 7px; font-size: 12px; font-weight: 700; }
.modal input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 6px; outline: 0; }
.modal input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23,107,91,.10); }
.form-error { min-height: 22px; padding-top: 6px; color: var(--danger); font-size: 12px; }
.modal-close { position: absolute; right: 14px; top: 14px; }
.segmented { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; margin-top: 18px; padding: 3px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-soft); }
.segment { min-height: 34px; padding: 6px 8px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 650; }
.segment.active { color: var(--text); background: var(--surface); box-shadow: 0 1px 4px rgba(27,39,51,.10); }
.secret-output { display: block; min-height: 74px; margin: 20px 0 14px; padding: 14px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface-soft); overflow-wrap: anywhere; line-height: 1.55; user-select: all; }
.payment-heading { display: block; padding-right: 36px; margin-bottom: 18px; }
.payment-content { overflow-y: auto; max-height: calc(100dvh - 30px); }
.payment-qr { display: block; width: min(100%, 250px); max-height: 42dvh; object-fit: contain; margin: 0 auto 12px; border: 1px solid var(--border); border-radius: 6px; }
.recharge-form { margin-bottom: 12px; }
.recharge-form label { margin-top: 13px; }
.quota-preview { min-height: 34px; margin-top: 8px; padding: 8px 10px; border-left: 3px solid var(--green); color: var(--green-dark); background: #edf6f3; font-weight: 650; }
.recharge-result { margin: 12px 0; padding: 12px; border: 1px solid #bad8cf; border-radius: 6px; color: var(--green-dark); background: #edf6f3; line-height: 1.55; overflow-wrap: anywhere; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 20; transform: translate(-50%, 20px); padding: 10px 14px; border-radius: 5px; background: #202a33; color: #fff; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.operator-shell { min-height: 100dvh; padding: 34px max(18px, calc((100% - 1000px) / 2)); background: var(--bg); }
.operator-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.operator-header h1 { margin-bottom: 4px; }
.operator-header p { margin: 0; color: var(--muted); }
.operator-panel { margin-bottom: 22px; padding: 22px; border: 1px solid var(--border); background: var(--surface); box-shadow: 0 5px 20px rgba(27,39,51,.05); }
.operator-panel h2 { margin-bottom: 5px; font-size: 17px; }
.operator-panel p { color: var(--muted); }
.operator-panel form { max-width: 520px; }
.operator-panel form label { display: block; margin: 18px 0 7px; font-weight: 650; }
.operator-panel form input { width: 100%; height: 42px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: 5px; }
.operator-panel form .button { margin-top: 14px; }
.operator-stats { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1px; margin-bottom: 22px; background: var(--border); border: 1px solid var(--border); }
.operator-stats > div { padding: 18px; background: var(--surface); }
.operator-stats span { display: block; color: var(--muted); font-size: 12px; }
.operator-stats strong { display: block; margin-top: 6px; font-size: 24px; }
.operator-table { border-top: 1px solid var(--border); }
.operator-row { display: grid; grid-template-columns: minmax(150px, .8fr) minmax(180px, 1fr) minmax(230px, 1.4fr) auto; align-items: center; gap: 14px; min-height: 58px; padding: 8px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.operator-row > div:nth-child(3) { color: var(--muted); font-size: 12px; }
.operator-actions { display: flex; gap: 7px; }
.operator-actions .button { min-height: 32px; padding: 5px 10px; font-size: 12px; }

@media (max-width: 760px) {
  .app-frame { grid-template-rows: 56px minmax(0, 1fr); }
  .topbar { padding: 0 12px; gap: 10px; }
  .service-state, .model-badge { display: none; }
  .button-quiet span { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
  .app-body { grid-template-columns: 1fr; grid-template-rows: 58px minmax(0,1fr); }
  .sidebar { padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--border); flex-direction: row; align-items: center; overflow-x: auto; }
  .new-chat { width: 40px; min-width: 40px; padding: 0; }
  .new-chat:not(:focus) { font-size: 0; }
  .new-chat svg { width: 18px; height: 18px; }
  .nav-list { display: flex; gap: 3px; }
  .nav-item { min-height: 40px; padding: 7px 10px; }
  .nav-item.active { box-shadow: inset 0 -3px 0 var(--green); }
  .sidebar-usage { display: none; }
  .messages { padding: 20px 14px; }
  .composer { padding: 10px 12px 12px; }
  .composer-meta span:last-child { display: none; }
  .info-view { padding: 24px 16px; }
  .view-header { align-items: flex-start; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric { padding: 16px; }
  .detail-list > div { grid-template-columns: 96px minmax(0,1fr); }
  .api-details > div:first-child { grid-template-columns: 96px minmax(0,1fr) 36px; }
  .record-row { align-items: flex-start; padding: 13px 0; }
  .record-body { grid-template-columns: 1fr; gap: 4px; }
  .modal-content { padding: 22px; }
  .operator-shell { padding: 22px 14px; }
  .operator-row { grid-template-columns: 1fr; gap: 4px; padding: 13px 0; }
  .operator-actions { margin-top: 6px; }
}

@media (max-width: 410px) {
  .brand-name { max-width: 105px; }
  .topbar-actions .button { padding: 7px 9px; }
  .nav-item span { display: none; }
  .nav-item { width: 42px; justify-content: center; }
  .view-header { display: block; }
  .view-header .button { margin-top: 14px; width: 100%; }
}
