*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  --bg: #f3eadb;
  --surface: #fffaf3;
  --sidebar: #1f1712;
  --sidebar-text: #e4d5c1;
  --sidebar-active: #c23b3b;
  --line: #e4d5c1;
  --text: #1f1712;
  --muted: #6b5748;
  --ok: #3d6b3a;
  --bad: #c23b3b;
  --rose: #c23b3b;
  --radius: 16px;
  --shadow: 0 10px 28px rgba(88, 52, 28, 0.08);
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 420px at 10% -10%, #fbe7c6 0%, transparent 55%),
    var(--bg);
}

.view {
  min-height: 100%;
}

#login-view {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.login-card {
  width: min(400px, calc(100% - 32px));
  margin: 14vh auto;
  padding: 32px 28px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.brand-mark {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--rose);
  font-weight: 700;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 32px;
  letter-spacing: -0.04em;
}

.login-back {
  margin: 18px 0 0;
  text-align: center;
}

.login-back a {
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
}

.app-shell {
  display: flex;
  min-height: 100%;
}

.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-brand {
  padding: 20px 18px 12px;
  border-bottom: 1px solid rgba(255, 250, 243, 0.08);
}

.sidebar-brand strong {
  display: block;
  color: #fffaf3;
  font-size: 16px;
}

.sidebar-brand span {
  font-size: 12px;
  color: #b89f88;
}

.sidebar-nav {
  padding: 12px 10px 24px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: auto;
}

.nav-group {
  margin: 14px 8px 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #b89f88;
}

.nav-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--sidebar-text);
  padding: 8px 12px;
  border-radius: 10px;
}

.nav-item:hover {
  background: rgba(255, 250, 243, 0.08);
  color: #fffaf3;
}

#bot-nav,
#account-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#bot-nav .nav-item,
#account-nav .nav-item {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.nav-item-meta {
  font-size: 11px;
  color: #b89f88;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.nav-empty {
  margin: 4px 12px 10px;
  font-size: 12px;
  color: #b89f88;
}

.nav-add {
  color: #f1c4b4;
}

.nav-item.is-offline .nav-item-meta {
  color: #e8a0a0;
}

.nav-item.is-online .nav-item-meta {
  color: #b7d6a8;
}

.user-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 20px;
  background: #f7efe3;
  border-bottom: 1px solid var(--line);
}

.user-meta[hidden] {
  display: none;
}

.user-meta .hint {
  margin: 0;
  flex: 1;
  min-width: 180px;
}

.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1,
.topbar .hint {
  margin: 0;
}

.cmd-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.cmd-table th,
.cmd-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.cmd-table th {
  color: var(--muted);
  font-weight: 600;
}

.feature-list {
  margin: 0;
  padding-left: 18px;
}

.feature-list li {
  margin: 6px 0;
}

.feature-toggles {
  margin-bottom: 8px;
}

.fixed-row {
  align-items: center;
}

.workspace-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.config-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 53px;
  z-index: 4;
}

.config-subnav[hidden] {
  display: none;
}

.subnav-item {
  border: 1px solid transparent;
  background: #f7efe3;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px;
}

.subnav-item:hover {
  background: #efe4d3;
}

.subnav-item.active {
  background: #1f1712;
  color: #fffaf3;
  border-color: #1f1712;
}

.qq-login-box {
  margin-top: 8px;
}

.qq-login-form {
  margin-top: 4px;
}

.qq-login-form .btn-row {
  margin-top: 10px;
}

.qr-wrap {
  margin: 12px 0 0;
}

.qr-wrap img {
  display: block;
  width: 180px;
  height: 180px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.account-card {
  cursor: pointer;
}

.account-card.revoked {
  cursor: default;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.quota-bar {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
}

.content {
  padding: 20px 24px 40px;
  max-width: 1080px;
}

.panel {
  display: none;
}

.panel.is-active {
  display: block;
}

.content.bot-page {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.content.bot-page .panel:not([data-panel="accounts"]) {
  display: block;
}

.content.bot-page .panel[data-panel="status"] { order: 1; }
.content.bot-page .panel[data-panel="persona"] { order: 2; }
.content.bot-page .panel[data-panel="groups"] { order: 3; }
.content.bot-page .panel[data-panel="owners"] { order: 4; }
.content.bot-page .panel[data-panel="welcome"] { order: 5; }
.content.bot-page .panel[data-panel="llm"] { order: 6; }
.content.bot-page .panel[data-panel="avatar"] { order: 7; }
.content.bot-page .panel[data-panel="novel"] { order: 8; }
.content.bot-page .panel[data-panel="library"] { order: 9; }
.content.bot-page .panel[data-panel="features"] { order: 10; }
.content.bot-page .panel[data-panel="moderation"] { order: 11; }
.content.bot-page .panel[data-panel="notice"] { order: 12; }
.content.bot-page .panel[data-panel="tokens"] { order: 13; }
.content.bot-page .panel[data-panel="logs"] { order: 14; }

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head h2 {
  margin: 0;
  font-size: 22px;
}

.panel-head .hint {
  margin: 4px 0 0;
}

.panel-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.panel-head-actions .hint {
  margin: 0;
  white-space: nowrap;
}

.card,
.card.inset {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card.inset + .card.inset {
  margin-top: 14px;
}

.card.login-card {
  padding: 32px 28px 24px;
  border-radius: 18px;
}

.card h2,
.card h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0;
}

.slot-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.slot-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  color: inherit;
  box-shadow: var(--shadow);
}

.slot-card:hover {
  border-color: #d4b89a;
}

.slot-card.active {
  border-color: #1f1712;
  background: #f7efe3;
  box-shadow: 0 0 0 1px #1f1712;
}

.slot-card h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.slot-card .slot-meta {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.slot-card img {
  display: block;
  width: 140px;
  height: 140px;
  margin-top: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.account-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.swipe-row {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.swipe-actions {
  position: absolute;
  inset: 0 0 0 auto;
  display: flex;
}

.swipe-delete {
  width: 88px;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: #dc2626;
  color: #fff;
  font-size: 15px;
}

.swipe-delete:hover {
  background: #b91c1c;
}

.swipe-front {
  position: relative;
  z-index: 1;
  background: var(--surface);
  transition: transform 0.2s ease;
  touch-action: pan-y;
}

.swipe-row.open .swipe-front {
  transform: translateX(-88px);
}

.account-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.account-card.revoked {
  opacity: 0.72;
}

.account-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #efe4d3;
  color: var(--rose);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex: 0 0 42px;
}

.account-body {
  flex: 1;
  min-width: 0;
}

.account-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
}

.account-title strong {
  font-size: 16px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #f7efe3;
  color: var(--text);
}

.pill.ok {
  background: #dcfce7;
  color: #166534;
}

.pill.bad {
  background: #fee2e2;
  color: #991b1b;
}

.account-meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

select,
input[type="datetime-local"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: var(--surface);
}

.table-wrap {
  margin-top: 0;
  overflow: auto;
}

.act-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.act-row button {
  padding: 4px 8px;
  font-size: 12px;
}

.stack-form label {
  margin-top: 10px;
}

.stack-form label:first-child {
  margin-top: 0;
}

.stack-form input[type="text"],
.stack-form input[type="password"] {
  width: 100%;
}

.check-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-weight: normal;
}

.check-row input {
  width: auto;
}

label {
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
}

input[type="password"],
input[type="number"],
input[type="text"],
input[type="file"],
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: var(--surface);
}

textarea {
  font-family: ui-monospace, "Cascadia Code", "SF Mono", monospace;
  font-size: 13px;
  resize: vertical;
}

button {
  padding: 8px 14px;
  border: 1px solid #1f1712;
  border-radius: 999px;
  background: #1f1712;
  color: #fffaf3;
  font: inherit;
  cursor: pointer;
}

button:hover {
  background: #3a2c24;
}

button.secondary {
  background: var(--surface);
  color: var(--muted);
  border-color: var(--line);
}

button.secondary:hover {
  background: #f7efe3;
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text);
  display: none;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#login-form button {
  width: 100%;
  margin-top: 12px;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.btn-row.tight {
  margin-top: 0;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  margin-top: 12px;
}

.inline-form label {
  width: 100%;
}

.inline-form input[type="number"] {
  flex: 1;
  min-width: 120px;
}

.status-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin: 0;
}

.status-grid dt {
  font-weight: 500;
  color: var(--muted);
}

.status-grid dd {
  margin: 0;
}

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

.badge-bad {
  color: var(--bad);
}

.hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.error {
  color: var(--bad);
  margin: 8px 0 0;
}

.ok {
  color: var(--ok);
  margin: 8px 0 0;
}

.tier-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tier-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tier-row input[type="number"] {
  width: 96px;
  flex: 0 0 96px;
}

.tier-row input[type="text"] {
  flex: 1;
  min-width: 180px;
}

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

@media (min-width: 720px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.fold {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7efe3;
}

.fold summary {
  cursor: pointer;
  padding: 8px 12px;
  font-weight: 500;
  color: var(--text);
  list-style: none;
}

.fold summary::-webkit-details-marker {
  display: none;
}

.fold summary::before {
  content: "▸ ";
  color: var(--muted);
}

.fold[open] summary::before {
  content: "▾ ";
}

.fold-body {
  max-height: 220px;
  overflow: auto;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.logs-wrap {
  max-height: 420px;
  overflow: auto;
}

#config-json {
  margin-top: 0;
  border: 0;
  border-radius: 0;
}

.fold textarea {
  display: block;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f7efe3;
  font-weight: 600;
}

td.empty {
  color: #888;
  text-align: center;
}

.empty-state {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  body.sidebar-open .sidebar {
    transform: none;
  }

  button.ghost {
    display: inline-flex;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
  background: rgba(31, 23, 18, 0.4);
    z-index: 15;
  }

  .sidebar-backdrop[hidden] {
    display: none;
  }
}
