:root {
  --bg: #12161c;
  --panel: #1a212b;
  --line: #2a3442;
  --text: #e8eef6;
  --muted: #8b9aaf;
  --accent: #c9a45c;
  --accent-dim: #8a6f3a;
  --ok: #5cb88a;
  --danger: #d16b6b;
  --card: #222b38;
  --radius: 10px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }
body.app-on { overflow: hidden; }

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 20% 10%, #2a3344 0%, transparent 50%),
    radial-gradient(ellipse at 80% 90%, #2c2418 0%, transparent 45%),
    var(--bg);
}
.login-card {
  width: min(380px, 92vw);
  padding: 32px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  display: grid;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 28px; letter-spacing: 0.12em; color: var(--accent); }
.login-card .sub { margin: -8px 0 8px; color: var(--muted); }
.login-card label, .panel label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card input, .panel input, .toolbar input, .ad-card input, .ad-card select, .ad-card textarea {
  background: #0f1319;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
}
.login-card button, .toolbar button, .panel button, .ad-card button, .btn {
  background: linear-gradient(180deg, #d4b36a, #a8843d);
  color: #1a1408;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 650;
  cursor: pointer;
}
.err { color: var(--danger); min-height: 1.2em; margin: 0; }
.msg { color: var(--ok); min-height: 1.2em; }

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}
.side {
  position: sticky;
  top: 0;
  align-self: flex-start;
  flex: 0 0 132px;
  width: 132px;
  height: 100vh;
  background: #0e1218;
  border-right: 1px solid var(--line);
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 20;
  overflow-y: auto;
}
.brand {
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 0.06em;
  padding: 6px 8px 12px;
  font-weight: 700;
  white-space: nowrap;
}
.side nav { display: grid; gap: 4px; flex: 1; align-content: start; }
.nav {
  text-align: left;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
}
.nav:hover { color: var(--text); background: #171d27; }
.nav.active { color: var(--accent); background: #1c2430; border-color: var(--line); }
.logout {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
  font-size: 12px;
}
.main {
  flex: 1;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 22px 36px;
}
.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.top h2 { margin: 0; font-size: 22px; font-weight: 650; }
.link { color: var(--accent); text-decoration: none; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card .k { color: var(--muted); font-size: 12px; }
.card .v { font-size: 26px; margin-top: 6px; font-weight: 700; color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.panel h3 { margin: 0 0 12px; font-size: 15px; color: var(--muted); font-weight: 600; }
.panel.narrow { max-width: 420px; display: grid; gap: 12px; }
.list { display: grid; gap: 8px; font-size: 13px; color: var(--muted); }
.list div { padding: 8px 0; border-bottom: 1px solid var(--line); }
.bar-row { display: grid; grid-template-columns: 110px 1fr 64px; gap: 8px; align-items: center; margin: 8px 0; font-size: 13px; }
.bar { height: 8px; background: #0f1319; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-dim), var(--accent)); }
.hint { color: var(--muted); margin: 0 0 14px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input { flex: 1; max-width: 360px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: #151b24; }
tr:hover td { background: #1c2430; }
.col-account {
  max-width: 168px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-account .acc-dy {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
}
.mono-id {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  cursor: help;
}
.dim { color: var(--muted); font-size: 11px; }
.btn-sm {
  background: #2a3442;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}
.btn-danger { background: #3a2222; color: #f0b0b0; border-color: #5a3030; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #2a3442;
  color: var(--muted);
}
.tag.guest { background: #2a2f24; color: #c9d48a; }
.tag.reg { background: #24302a; color: #8fd4b0; }
.detail { margin-top: 14px; }
.detail .sec { margin: 16px 0 8px; font-size: 14px; color: var(--accent); font-weight: 650; }
.detail .empty { color: var(--muted); font-size: 13px; padding: 10px 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 8px; }
.data-table th, .data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
.data-table th { color: var(--muted); font-weight: 600; background: #151b24; }
.data-table td { color: var(--text); }
.data-table tr:hover td { background: #1c2430; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chip {
  background: #0f1319;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 110px;
}
.chip .n { color: var(--muted); font-size: 12px; }
.chip .v { margin-top: 4px; font-size: 16px; font-weight: 650; color: var(--accent); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 12px; }
.kv .item { background: #0f1319; border-radius: 8px; padding: 8px 10px; }
.kv .item b { display: block; color: var(--muted); font-weight: 500; font-size: 12px; margin-bottom: 2px; }
.save-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.save-block {
  background: #0f1319;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
.save-block h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.ads-list {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: stretch;
}
.ad-card {
  flex: 1 1 300px;
  width: 300px;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ad-card .fields { display: grid; gap: 10px; }
.ad-card .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ad-preview {
  background: #0f1319;
  border-radius: 8px;
  min-height: 150px;
  height: 150px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 8px;
}
.ad-preview img, .ad-preview video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  object-fit: contain;
}
.ad-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ad-status {
  min-height: 1.3em;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.ad-status.is-loading { color: #c9b07a; }
.ad-status.is-ok { color: var(--ok); }
.ad-status.is-err { color: var(--danger); }
.upload-box {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: #0f1319;
  border: 1px dashed var(--line);
  border-radius: 8px;
}
.upload-box .up-title { font-size: 12px; color: var(--muted); }
.upload-box .up-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.upload-box .up-name {
  font-size: 12px;
  color: var(--accent);
  word-break: break-all;
  min-height: 1.2em;
}
.switch { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
button.is-loading,
button:disabled {
  opacity: 0.65;
  cursor: wait;
  pointer-events: none;
}
button.is-loading::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  border: 2px solid rgba(26, 20, 8, 0.25);
  border-top-color: rgba(26, 20, 8, 0.9);
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-root {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 9999;
  display: grid;
  gap: 8px;
  pointer-events: none;
}
.toast {
  min-width: 200px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #1a212b;
  color: var(--text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  font-size: 13px;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: auto;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { border-color: #2f5a45; background: #16241e; color: #9fe0bf; }
.toast.err { border-color: #5a3030; background: #2a1818; color: #f0b0b0; }
.toast.loading { border-color: #5a4a2a; background: #241e14; color: #e6d3a0; }

@media (max-width: 960px) {
  .app { flex-direction: column; height: auto; overflow: auto; }
  body.app-on { overflow: auto; }
  .side {
    position: sticky;
    top: 0;
    flex: none;
    width: 100%;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
  }
  .brand { padding: 4px 8px 4px 0; }
  .side nav { display: flex; flex-wrap: wrap; flex: 1; }
  .logout { margin-left: auto; }
  .main { height: auto; overflow: visible; }
  .grid-2, .save-grid { grid-template-columns: 1fr; }
  .ad-card { flex-basis: 100%; width: 100%; }
}
