:root {
  color-scheme: light;
  --ink: #1b1d1b;
  --muted: #68716c;
  --line: #dce3df;
  --paper: #f6f8f6;
  --panel: #ffffff;
  --accent: #116a5b;
  --accent-dark: #0a4d42;
  --soft: #e9f4ef;
  --amber: #b57514;
  --danger: #a33a2b;
  --shadow: 0 18px 45px rgba(22, 39, 34, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #ffffff 0%, var(--paper) 58%, #eef3ef 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.18;
  font-weight: 780;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
  font-weight: 760;
}

p,
label,
.label,
.refs,
.todo {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.shell {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(420px, 1fr);
  gap: 24px;
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 26px 0;
}

.phone {
  min-height: calc(100vh - 52px);
  border: 1px solid #d9e2dc;
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.app-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 22px 18px;
  border-bottom: 1px solid var(--line);
}

.auth-panel,
.app-view {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  min-height: 0;
}

.auth-copy {
  display: grid;
  gap: 6px;
  padding: 16px;
  border-radius: 8px;
  background: var(--soft);
}

label {
  display: grid;
  gap: 7px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.62;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17, 106, 91, 0.13);
}

.auth-actions,
.composer-actions,
.panel-head,
.balance-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.primary,
.secondary,
.ghost,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  white-space: nowrap;
}

.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 720;
}

.primary:hover {
  background: var(--accent-dark);
}

.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost,
.icon-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.balance-band {
  padding: 15px;
  border-radius: 8px;
  background: #18231f;
  color: #fff;
}

.balance-band .label {
  display: block;
  color: rgba(255, 255, 255, 0.66);
}

#tokenBalance {
  display: block;
  margin-top: 4px;
  font-size: 34px;
  line-height: 1;
  color: #f4c978;
}

.store {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.package {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
  text-align: left;
  cursor: pointer;
}

.package.hot {
  border-color: rgba(181, 117, 20, 0.55);
  background: #fff9ed;
}

.package strong {
  color: var(--accent-dark);
}

.package em {
  color: var(--amber);
  font-style: normal;
  font-weight: 720;
}

.chat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex: 1;
  flex-direction: column;
}

.messages {
  min-height: 320px;
  max-height: calc(100vh - 410px);
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fbfcfb;
}

.bubble {
  max-width: 88%;
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
}

.bubble.user small {
  color: rgba(255, 255, 255, 0.72);
}

.bubble.assistant {
  align-self: flex-start;
  border: 1px solid var(--line);
  background: #fff;
}

.composer {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.segmented {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  height: 38px;
  border-right: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 0 12px;
  cursor: pointer;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented .active {
  background: var(--soft);
  color: var(--accent-dark);
  font-weight: 720;
}

.admin {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  padding: 16px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.settings-grid label:nth-child(3),
.settings-grid label:nth-child(4) {
  grid-column: 1 / -1;
}

.refs {
  margin-top: 12px;
}

.ref-item {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.ref-item:first-child {
  border-top: 0;
}

.ref-title {
  color: var(--ink);
  font-weight: 720;
  font-size: 13px;
  margin-bottom: 4px;
}

.ref-path {
  color: var(--amber);
  font-size: 12px;
  margin-bottom: 5px;
}

.todo {
  margin: 10px 0 0;
  padding-left: 18px;
}

.hidden {
  display: none !important;
}

@media (max-width: 920px) {
  .shell {
    grid-template-columns: 1fr;
    width: min(100vw - 18px, 560px);
    padding: 10px 0 18px;
  }

  .phone {
    min-height: auto;
    border-radius: 18px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .auth-actions,
  .composer-actions,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .auth-actions > *,
  .composer-actions > *,
  .panel-head > button,
  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
    padding: 0 8px;
  }

  .messages {
    max-height: 52vh;
  }
}
