/* ============================================================
   AutoWave Admin Dashboard — Styles
   配色与 proof-of-concept/wails/frontend/styles.css 一致 (Catppuccin Mocha)
   Color palette matches the Wails frontend (Catppuccin Mocha)
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  background: #1e1e2e;
  color: #cdd6f4;
  font-size: 13px;
}

[hidden] { display: none !important; }

a { color: #89b4fa; text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: #6c7086; font-size: 11px; }

/* ── App Shell ── */
.app { display: flex; flex-direction: column; height: 100vh; }

/* ── Header ── */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: #181825; border-bottom: 1px solid #313244;
  flex-shrink: 0;
}
.logo { display: flex; align-items: baseline; gap: 10px; }
.logo-text { font-size: 18px; font-weight: 700; color: #cba6f7; letter-spacing: 0.5px; }
.logo .ver { font-size: 11px; color: #6c7086; }

.tabs { display: flex; gap: 4px; }
.tab-btn {
  background: transparent; color: #bac2de; border: none;
  padding: 8px 16px; border-radius: 4px; cursor: pointer;
  font-size: 12px; transition: background .15s, color .15s;
}
.tab-btn:hover { background: #313244; color: #cdd6f4; }
.tab-btn.active { background: #313244; color: #89b4fa; font-weight: 600; }

.header-right { display: flex; align-items: center; gap: 10px; }

/* ── Lang switcher / 语言切换按钮组 ── */
.lang-switcher {
  display: inline-flex;
  border: 1px solid #45475a;
  border-radius: 4px;
  overflow: hidden;
}
.lang-switcher button {
  background: transparent;
  color: #6c7086;
  border: none;
  border-radius: 0;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.lang-switcher button + button {
  border-left: 1px solid #45475a;
}
.lang-switcher button:hover {
  background: #313244;
  color: #cdd6f4;
}
.lang-switcher button.active {
  background: #89b4fa;
  color: #1e1e2e;
}

/* badge: copied from wails styles */
.header-license-badge {
  padding: 3px 10px;
  background: #45475a; color: #cdd6f4;
  border-radius: 10px; font-size: 11px; font-weight: 400;
}
.header-license-badge.active { background: #a6e3a122; color: #a6e3a1; }
.header-license-badge.warn   { background: #f9e2af22; color: #f9e2af; }
.header-license-badge.danger { background: #f38ba822; color: #f38ba8; }

/* ── Buttons ── */
button {
  background: #313244; color: #cdd6f4; border: none;
  padding: 6px 12px; border-radius: 4px; cursor: pointer;
  font-size: 12px; transition: background .15s;
}
button:hover:not(:disabled) { background: #45475a; }
button.primary { background: #89b4fa; color: #1e1e2e; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #74a7ee; }
button.danger { background: #f38ba8; color: #1e1e2e; font-weight: 600; }
button.danger:hover:not(:disabled) { background: #e57396; }
button.warn { background: #f9e2af; color: #1e1e2e; font-weight: 600; }
button.warn:hover:not(:disabled) { background: #efd394; }
button:disabled { opacity: .4; cursor: not-allowed; }

/* ── Main ── */
main {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}

.tab-pane { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: #181825; border: 1px solid #313244; border-radius: 8px;
  padding: 14px 16px;
}
.card h2 {
  font-size: 13px; color: #89b4fa;
  margin-bottom: 10px; font-weight: 600;
}

.grid-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ── Toolbar ── */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.toolbar input[type="text"] {
  flex: 1; min-width: 200px;
  background: #11111b; border: 1px solid #313244; color: #cdd6f4;
  padding: 6px 10px; border-radius: 4px; font-size: 12px;
}
.toolbar select {
  background: #11111b; border: 1px solid #313244; color: #cdd6f4;
  padding: 6px 10px; border-radius: 4px; font-size: 12px;
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%; border-collapse: collapse;
  font-size: 12px;
}
table thead th {
  background: #11111b; color: #89b4fa; font-weight: 600;
  padding: 8px 10px; text-align: left;
  border-bottom: 1px solid #313244; position: sticky; top: 0;
  white-space: nowrap;
}
table tbody td {
  padding: 6px 10px; border-bottom: 1px solid #232334;
  color: #cdd6f4; vertical-align: middle;
}
table tbody tr:hover { background: #1e1e2e; }
table .empty { text-align: center; color: #6c7086; padding: 24px; }

/* monospace ID column */
.mono { font-family: "Consolas", monospace; font-size: 11px; }
.mono-btn {
  background: transparent; border: 1px solid #45475a;
  color: #bac2de; padding: 1px 6px; font-size: 10px;
  margin-left: 4px;
}
.mono-btn:hover { background: #313244; color: #cdd6f4; }

/* status pill */
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
}
.pill.active { background: #a6e3a122; color: #a6e3a1; }
.pill.killed { background: #f38ba822; color: #f38ba8; }
.pill.expired { background: #fab38722; color: #fab387; }
.pill.online { background: #a6e3a1; color: #1e1e2e; }
.pill.offline { background: #45475a; color: #bac2de; }

.row-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.row-actions button { padding: 2px 8px; font-size: 11px; }

/* ── Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.stat-card {
  background: #181825; border: 1px solid #313244; border-radius: 8px;
  padding: 16px;
}
.stat-label { color: #6c7086; font-size: 11px; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value {
  font-size: 28px; font-weight: 700; color: #cdd6f4;
  font-variant-numeric: tabular-nums;
}
.stat-sub { color: #bac2de; font-size: 11px; margin-top: 4px; }
.stat-sub span { color: #89b4fa; font-weight: 600; }

.chart-wrap { position: relative; height: 280px; }

/* ── Form rows ── */
.row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.row label { color: #bac2de; width: 160px; font-size: 12px; padding-top: 6px; flex-shrink: 0; }
.row input[type="text"],
.row input[type="url"],
.row input[type="password"],
.row input[type="number"],
.row select,
.row textarea {
  flex: 1;
  background: #11111b; border: 1px solid #313244; color: #cdd6f4;
  padding: 6px 10px; border-radius: 4px; font-size: 12px;
  font-family: "Consolas", monospace;
}
.row textarea { resize: vertical; min-height: 80px; }
.row input:focus, .row select:focus, .row textarea:focus {
  outline: none; border-color: #89b4fa;
}

.actions { display: flex; gap: 10px; margin-top: 8px; align-items: center; }

/* ── Version cards ── */
.version-card {
  background: #11111b; border: 1px solid #313244; border-radius: 6px;
  padding: 12px; font-family: "Consolas", monospace; font-size: 12px;
  color: #cdd6f4; line-height: 1.6; white-space: pre-wrap;
}
.version-card .v-line { display: flex; gap: 8px; }
.version-card .v-key { color: #6c7086; min-width: 120px; }
.version-card .v-val { color: #a6e3a1; word-break: break-all; }

/* ── Drawer ── */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 520px; max-width: 90vw;
  background: #181825; border-left: 1px solid #45475a;
  z-index: 900;
  display: flex; flex-direction: column;
  box-shadow: -4px 0 16px rgba(0,0,0,.4);
}
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid #313244; flex-shrink: 0;
}
.drawer-head h2 { color: #89b4fa; font-size: 14px; font-weight: 600; }
.drawer-head button {
  background: transparent; color: #6c7086; font-size: 20px;
  padding: 0 8px;
}
.drawer-head button:hover { color: #cdd6f4; background: #313244; }
.drawer-body {
  flex: 1; overflow-y: auto; padding: 16px;
}
.drawer-mask {
  position: fixed; inset: 0; background: rgba(17,17,27,0.6);
  z-index: 800;
}

.detail-section { margin-bottom: 18px; }
.detail-section h3 {
  color: #cba6f7; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.kv-grid {
  display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px;
  font-size: 12px;
}
.kv-grid .k { color: #6c7086; }
.kv-grid .v { color: #cdd6f4; word-break: break-all; font-family: "Consolas", monospace; }

.timeline {
  list-style: none; padding-left: 0;
  border-left: 2px solid #313244;
  margin-left: 6px;
}
.timeline li {
  position: relative; padding: 6px 0 6px 16px; font-size: 11px;
  color: #bac2de;
}
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 12px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #89b4fa;
}
.timeline .ts { color: #6c7086; margin-right: 6px; font-family: "Consolas", monospace; }
.timeline .ev-failed::before { background: #f38ba8; }
.timeline .ev-completed::before { background: #a6e3a1; }
.timeline .ev-launched::before { background: #f9e2af; }

/* ── Modals ── */
.modal {
  position: fixed; inset: 0; background: rgba(17, 17, 27, 0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-body {
  background: #181825; border: 1px solid #45475a; border-radius: 10px;
  padding: 28px; max-width: 520px; width: 90%; position: relative;
}
.modal-body h2 { color: #89b4fa; margin-bottom: 12px; font-size: 16px; }
.modal-body p { color: #bac2de; margin-bottom: 12px; line-height: 1.5; font-size: 12px; }

.modal-close {
  position: absolute; top: 10px; right: 10px;
  background: transparent; border: none; color: #6c7086;
  font-size: 18px; cursor: pointer; padding: 4px 8px;
}
.modal-close:hover { color: #cdd6f4; background: #313244; border-radius: 4px; }

.activate-input { margin: 12px 0; display: flex; flex-direction: column; gap: 6px; }
.activate-input label { color: #bac2de; font-size: 12px; }
.activate-input input {
  background: #11111b; border: 1px solid #45475a; color: #cdd6f4;
  padding: 10px 12px; border-radius: 4px; font-size: 13px;
  font-family: "Consolas", monospace;
}
.activate-input input:focus { outline: none; border-color: #89b4fa; }

.activate-result {
  margin-top: 10px; padding: 8px 12px; border-radius: 4px; font-size: 12px;
}
.activate-result.ok  { background: #a6e3a122; color: #a6e3a1; border-left: 3px solid #a6e3a1; }
.activate-result.err { background: #f38ba822; color: #f38ba8; border-left: 3px solid #f38ba8; }

.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

/* ── Footer ── */
footer {
  padding: 6px 18px; background: #181825;
  border-top: 1px solid #313244;
  font-size: 11px; color: #6c7086;
  display: flex; justify-content: space-between;
  flex-shrink: 0;
}
#footer-api { font-family: "Consolas", monospace; color: #89b4fa; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #11111b; }
::-webkit-scrollbar-thumb { background: #313244; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #45475a; }

/* ============================================================
   Agents Tab — 代理管理 / Agent management
   树形列表 + 状态 pill + 嵌套缩进 + 详情抽屉复用
   Tree list + status pills + nested indent + reuses detail drawer
   ============================================================ */
.agents-list {
  display: flex; flex-direction: column;
  gap: 4px;
  max-height: calc(100vh - 240px);
  overflow-y: auto;
}
.agents-list .empty {
  text-align: center; color: #6c7086; padding: 32px;
}

.agent-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: #11111b;
  border: 1px solid #232334;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  flex-wrap: wrap;
}
.agent-row:hover {
  background: #1e1e2e;
  border-color: #45475a;
  transform: translateX(2px);
}
.agent-row.suspended {
  opacity: 0.55;
  border-left: 3px solid #f9e2af;
}

.agent-tree-branch {
  color: #45475a;
  font-family: "Consolas", monospace;
  font-size: 11px;
  flex-shrink: 0;
}
.agent-name {
  color: #cdd6f4; font-weight: 600;
  min-width: 100px;
}
.agent-level {
  background: #313244; color: #89b4fa;
  padding: 1px 6px; border-radius: 3px;
  font-size: 10px; font-weight: 600;
}
.agent-promo {
  color: #f9e2af; font-weight: 600;
  background: #313244; padding: 2px 8px; border-radius: 3px;
  letter-spacing: 1px;
}
.agent-contact {
  min-width: 120px;
  font-size: 11px;
}
.agent-balance {
  color: #cdd6f4; font-size: 11px;
  font-variant-numeric: tabular-nums;
  min-width: 180px;
}
.agent-balance b { color: #a6e3a1; font-weight: 700; }
.agent-commission {
  color: #cba6f7; font-weight: 600;
  min-width: 50px;
}
.agent-children {
  font-size: 11px; min-width: 60px;
}
.agent-status {
  flex-shrink: 0;
}
.agent-actions {
  display: flex; gap: 4px; flex-wrap: wrap;
  margin-left: auto;
}
.agent-actions button {
  padding: 3px 10px; font-size: 11px;
}

/* status pills (复用现有 pill base) */
.pill.status-active { background: #a6e3a122; color: #a6e3a1; }
.pill.status-suspended { background: #f9e2af22; color: #f9e2af; }

/* Detail drawer — sub-agent list / 详情抽屉里的下线列表 */
.agent-sub-list {
  display: flex; flex-direction: column; gap: 6px;
}
.agent-sub-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  background: #11111b;
  border: 1px solid #232334;
  border-radius: 4px;
  font-size: 11px;
}
.agent-sub-item button {
  margin-left: auto; padding: 2px 8px; font-size: 10px;
}

/* Tx amount pos/neg (流水正负数) */
.tx-pos { color: #a6e3a1; font-weight: 600; }
.tx-neg { color: #f38ba8; font-weight: 600; }

/* Agent create modal — uses .row form pattern but inside modal */
#agent-create-modal .modal-body { max-width: 560px; width: 95%; }
#agent-create-modal .row label { width: 200px; }

/* ── Toast (top-right) ── */
.toast {
  position: fixed; top: 16px; right: 16px;
  padding: 10px 14px; border-radius: 4px;
  font-size: 12px; font-weight: 500; z-index: 1100;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  max-width: 360px;
}
.toast.ok  { background: #a6e3a1; color: #1e1e2e; }
.toast.err { background: #f38ba8; color: #1e1e2e; }
.toast.info { background: #89b4fa; color: #1e1e2e; }
