:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --line: #dbe3ee;
  --accent: #0f766e;
  --accent-2: #1d4ed8;
  --danger: #b91c1c;
  --warn: #b45309;
  --ok: #047857;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior-y: contain;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
  gap: 14px;
  align-content: center;
  color: var(--muted);
}

.boot img {
  width: 58px;
  height: 58px;
  border-radius: 14px;
}

.app-shell {
  min-height: 100vh;
  padding: calc(env(safe-area-inset-top) + 10px) 12px calc(74px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: -10px -12px 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: rgba(248, 250, 252, 0.94);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(219, 227, 238, 0.75);
}

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

.title {
  min-width: 0;
}

.title h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: 0;
}

.title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.account {
  max-width: 126px;
  padding: 7px 9px;
  border-radius: 8px;
  background: #e2e8f0;
  color: #334155;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 10px;
}

.log-filterbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 62px;
  gap: 6px;
  margin-top: 8px;
}

.channel-filterbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.log-statbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.log-statbar div {
  min-width: 0;
  min-height: 48px;
  padding: 6px 7px;
  border-radius: 7px;
  background: #fff;
  border: 1px solid var(--line);
}

.log-statbar span,
.log-statbar em {
  display: block;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.05;
  font-style: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-statbar b {
  display: block;
  margin-top: 3px;
  font-size: 15px;
  line-height: 1.05;
  color: #111827;
}

.log-statbar div:nth-child(2) b {
  color: #1d4ed8;
}

.log-statbar div:nth-child(3) b {
  color: var(--danger);
}

.searchbox,
.field,
.textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.searchbox,
.field {
  height: 42px;
  padding: 0 12px;
}

.field.compact,
.btn.compact {
  min-height: 0;
  height: 32px;
  padding: 0 8px;
  border-radius: 7px;
  font-size: 12px;
}

.textarea {
  min-height: 92px;
  padding: 10px 12px;
  resize: vertical;
}

.btn {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  background: #e2e8f0;
  color: #0f172a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 650;
}

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

.btn.blue {
  background: var(--accent-2);
  color: #fff;
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.btn:disabled {
  opacity: 0.55;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 0 0 auto;
  padding: 8px 11px;
  border-radius: 8px;
  background: #e2e8f0;
  color: #334155;
  font-size: 13px;
  font-weight: 650;
}

.tab.active {
  background: #111827;
  color: #fff;
}

.grid {
  display: grid;
  gap: 10px;
}

.dense-list {
  display: grid;
  gap: 7px;
}

.log-list {
  margin: 0;
}

.log-row {
  min-height: 76px;
  padding: 9px 10px;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.log-row:nth-child(even) {
  background: #fff;
}

.log-row.is-error {
  background: #fff1f2;
  border-color: #fecdd3;
}

.log-row.is-empty-completion {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.log-row.is-empty-completion .log-metrics b,
.log-row.is-empty-completion .log-model {
  color: #1d4ed8;
}

.log-row.is-retry-success {
  background: #fff7ed;
  border-color: #fdba74;
  box-shadow: 0 4px 12px rgba(180, 83, 9, 0.13);
}

.log-row.is-retry-success .log-model,
.log-row.is-retry-success .log-metrics b {
  color: #b45309;
}

.log-retry-badge {
  display: inline-flex;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #fed7aa;
  color: #9a3412;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.2;
  vertical-align: middle;
  white-space: nowrap;
}

.log-retry-path {
  margin-top: 3px;
  color: #c2410c;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-top {
  display: grid;
  grid-template-columns: minmax(64px, 0.8fr) minmax(0, 1.4fr) 58px;
  align-items: center;
  gap: 8px;
}

.log-user,
.log-model,
.log-time,
.log-metrics b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-user,
.log-model {
  font-weight: 700;
  font-size: 13px;
  line-height: 1.2;
}

.log-time {
  color: var(--muted);
  text-align: right;
  font-size: 12px;
  font-weight: 700;
}

.log-metrics {
  display: grid;
  grid-template-columns: 0.78fr 0.95fr minmax(0, 1.25fr);
  gap: 6px;
  margin-top: 8px;
}

.log-metrics div {
  min-width: 0;
  padding: 5px 6px;
  border-radius: 7px;
  background: #f8fafc;
}

.log-metrics span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
}

.log-metrics b {
  display: block;
  margin-top: 3px;
  color: #334155;
  font-size: 12px;
  line-height: 1.1;
}

.log-metrics div:first-child b {
  color: var(--ok);
}

.server-card {
  border-color: #b7e4dc;
  background: #f0fdfa;
}

.server-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.server-grid div {
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #ccfbf1;
}

.server-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.server-grid b {
  display: block;
  margin-top: 4px;
  font-size: 17px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.redemption-create-card {
  background: #fff;
}

.redemption-create-form,
.redemption-result {
  display: grid;
  grid-template-columns: 76px minmax(0, 0.9fr) minmax(0, 1fr) 54px;
  gap: 6px;
  margin-top: 10px;
}

.redemption-result {
  grid-template-columns: minmax(0, 1fr) 58px;
  margin-top: 7px;
}

.redemption-result input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}

.channel-list {
  gap: 5px;
}

.channel-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "main status"
    "metrics edit";
  gap: 6px 8px;
  align-items: center;
  min-height: 52px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.channel-main {
  grid-area: main;
  min-width: 0;
}

.channel-title {
  font-size: 13px;
  line-height: 1.15;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-row .badge {
  grid-area: status;
  max-width: 76px;
  padding: 3px 6px;
  font-size: 10px;
}

.channel-metrics {
  grid-area: metrics;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  min-width: 0;
}

.channel-metrics div {
  min-width: 0;
  padding: 4px 5px;
  border-radius: 6px;
  background: #f8fafc;
}

.channel-metrics span {
  display: block;
  color: var(--muted);
  font-size: 9px;
  line-height: 1;
}

.channel-metrics b {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  line-height: 1.05;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-row > .btn {
  grid-area: edit;
  justify-self: end;
  width: 48px;
  height: 28px;
  min-height: 0;
  padding: 0;
  font-size: 12px;
}

.bill-list {
  gap: 4px;
}

.billing-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 8px;
}

.billing-summary div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  background: #f0fdf4;
}

.billing-summary span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.billing-summary b {
  display: block;
  margin-top: 3px;
  color: #047857;
  font-size: 18px;
  line-height: 1.1;
}

.bill-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(128px, auto);
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.bill-main,
.bill-side {
  min-width: 0;
}

.bill-title {
  font-size: 13px;
  line-height: 1.18;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bill-sub,
.bill-side span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bill-side {
  max-width: 178px;
  text-align: right;
}

.bill-side b {
  display: block;
  color: #0f766e;
  font-size: 12px;
  line-height: 1.15;
}

.bill-side span {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  box-shadow: var(--shadow);
}

.stat b {
  display: block;
  font-size: 20px;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.stat span {
  font-size: 12px;
  color: var(--muted);
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.card-title {
  min-width: 0;
  font-size: 15px;
  font-weight: 750;
  line-height: 1.28;
  overflow-wrap: anywhere;
}

.card-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.badge {
  flex: 0 0 auto;
  max-width: 120px;
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--panel-2);
  color: #334155;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge.ok {
  background: #dcfce7;
  color: var(--ok);
}

.badge.warn {
  background: #fef3c7;
  color: var(--warn);
}

.badge.danger {
  background: #fee2e2;
  color: var(--danger);
}

.kv {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.kv div {
  min-width: 0;
  padding: 8px;
  border-radius: 8px;
  background: #f8fafc;
}

.kv span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.kv b {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.content {
  margin-top: 10px;
  color: #334155;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 1px;
}

.actions .btn {
  flex: 0 0 auto;
  min-height: 36px;
  font-size: 13px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.nav-btn {
  min-width: 0;
  min-height: 48px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 650;
}

.nav-btn svg {
  width: 20px;
  height: 20px;
}

.nav-btn.active {
  color: var(--accent);
  background: #ccfbf1;
}

.empty,
.error,
.loading {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

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

.pager {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}

.pager span {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
}

.modal {
  width: 100%;
  max-height: 88vh;
  overflow: auto;
  background: #fff;
  border-radius: 8px 8px 0 0;
  padding: 14px 14px calc(16px + env(safe-area-inset-bottom));
}

.modal h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.form-grid {
  display: grid;
  gap: 10px;
}

.form-row label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 8px;
}

.code-row .btn {
  min-height: 42px;
  padding: 0 10px;
  white-space: nowrap;
}

.form-hint {
  min-height: 16px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.login {
  min-height: 100vh;
  padding: calc(env(safe-area-inset-top) + 28px) 18px 32px;
  display: grid;
  align-content: center;
}

.login-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.login-card img {
  width: 54px;
  height: 54px;
  border-radius: 12px;
}

.login-card h1 {
  margin: 12px 0 4px;
  font-size: 24px;
}

.login-card p {
  margin: 0 0 18px;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 90;
  padding: 12px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.danger-zone {
  border-color: #fecaca;
  background: #fff7f7;
}

.hide {
  display: none !important;
}

@media (min-width: 720px) {
  .app-shell {
    max-width: 720px;
    margin: 0 auto;
  }

  .topbar {
    border-left: 1px solid rgba(219, 227, 238, 0.75);
    border-right: 1px solid rgba(219, 227, 238, 0.75);
  }
}
