:root {
  --bg: #0c1017;
  --bg2: #121821;
  --panel: #171e29;
  --panel-2: #1c2431;
  --line: #2a3546;
  --line-soft: rgba(42, 53, 70, .72);
  --text: #e8eef6;
  --muted: #8b9bb0;
  --accent: #4aa3ff;
  --accent-2: #2f7de0;
  --coruna: #8aa4ff;
  --ds: #3dce8e;
  --warn: #e0a14a;
  --danger: #e36b6b;
  --ok: #3dce8e;
  --shadow: 0 10px 30px rgba(0, 0, 0, .28);
  --radius: 14px;
  --radius-sm: 10px;
  --focus: 0 0 0 3px rgba(74, 163, 255, .22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 12% -10%, rgba(74, 163, 255, .08), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(61, 206, 142, .05), transparent 45%),
    var(--bg);
  color: var(--text);
  font: 14px/1.5 "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2f3b4d; border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

a { color: var(--accent); text-decoration: none; transition: color .15s ease; }
a:hover { color: #7bbcff; text-decoration: none; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: #c9d8ea;
  background: rgba(255, 255, 255, .03);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 1px 6px;
}

/* ========== Shell ========== */
.layout { display: flex; min-height: 100vh; }

.side {
  width: 232px;
  background: linear-gradient(180deg, #121821 0%, #0f141c 100%);
  border-right: 1px solid var(--line);
  padding: 20px 14px 28px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .03em;
  margin: 2px 8px 22px;
  color: #fff;
  padding: 10px 10px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(74, 163, 255, .12), rgba(61, 206, 142, .06));
  border: 1px solid rgba(74, 163, 255, .16);
}
.brand img { height: 22px; vertical-align: -5px; border-radius: 5px; }
.brand span { color: var(--accent); }

.nav-sec {
  margin: 14px 8px 6px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #5f7088;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  padding: 9px 12px;
  border-radius: 10px;
  margin-bottom: 3px;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
  border: 1px solid transparent;
}
.nav a:hover {
  background: rgba(255, 255, 255, .035);
  color: var(--text);
}
.nav a.on {
  background: linear-gradient(135deg, rgba(74, 163, 255, .16), rgba(74, 163, 255, .06));
  color: #fff;
  border-color: rgba(74, 163, 255, .22);
  box-shadow: inset 3px 0 0 var(--accent);
}

.main {
  flex: 1;
  min-width: 0;
  padding: 22px 28px 56px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
}
.top h1 {
  font-size: 22px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -.02em;
}
.top-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.user {
  color: var(--muted);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .03);
  border: 1px solid var(--line-soft);
}
.user a { margin-left: 10px; font-weight: 600; }

/* ========== Primitives ========== */
.muted { color: var(--muted); }

.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .02) inset;
}
.card > h3:first-child,
.card-title {
  margin: 0 0 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 15px;
  font-weight: 650;
}
.card-title .muted,
.card > h3:first-child .muted { font-weight: 500; }

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

.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 14px;
  font-weight: 600;
  border: 1px solid transparent;
}
.flash.ok { background: rgba(61, 206, 142, .10); border-color: rgba(61, 206, 142, .28); color: #7fdcb0; }
.flash.err { background: rgba(227, 107, 107, .10); border-color: rgba(227, 107, 107, .28); color: #f0a0a0; }
.flash.info { background: rgba(74, 163, 255, .10); border-color: rgba(74, 163, 255, .28); color: #9bc8ff; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .02);
  border: 1px solid var(--line-soft);
}
.hint { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 8px 0 0; }
.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .015);
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}
.back-link:hover { color: var(--accent); }

.form-panel { max-width: 460px; }
.form-panel label,
.form-label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}
.form-panel .field { margin: 0 0 14px; }
.form-panel input[type=text],
.form-panel input[type=password],
.form-panel select,
.form-panel textarea { width: 100%; }

input, select, textarea, button { font: inherit; }
input[type=text],
input[type=password],
input[type=date],
input[type=file],
select,
textarea {
  background: rgba(8, 12, 18, .65);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input:hover, select:hover, textarea:hover { border-color: #3a4a60; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--focus);
  background: rgba(8, 12, 18, .85);
}
input[type=date] { color-scheme: dark; }

button, .btn {
  background: linear-gradient(180deg, #5aadff, var(--accent));
  color: #061018;
  border: 0;
  border-radius: 9px;
  padding: 8px 14px;
  font-weight: 650;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition: transform .12s ease, filter .12s ease, border-color .15s ease, background .15s ease, color .15s ease;
  line-height: 1.2;
}
button:hover, .btn:hover { filter: brightness(1.06); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button.ghost, .btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
button.ghost:hover, .btn.ghost:hover {
  border-color: rgba(74, 163, 255, .45);
  color: var(--accent);
  background: rgba(74, 163, 255, .08);
  filter: none;
}
button.danger, .btn.danger {
  background: linear-gradient(180deg, #ef7f7f, var(--danger));
  color: #1a0b0b;
}
button.ok, .btn.ok {
  background: linear-gradient(180deg, #56dba0, var(--ds));
  color: #061018;
}
button.sm, .btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-mnemonic-reveal { font-size: 13px; padding: 6px 12px; }
.table .btn.danger { padding: 4px 10px; font-size: 12px; }
.btn-soft-danger {
  background: transparent !important;
  color: #e0705f !important;
  border: 1px solid #5a2c26 !important;
}
.btn-soft-danger:hover {
  background: rgba(227, 107, 107, .1) !important;
  color: #ff9a8c !important;
  filter: none !important;
}

.grow { flex: 1; }

/* ========== Tables ========== */
.table-wrap { overflow-x: auto; border-radius: 10px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
.table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .02em;
  background: rgba(255, 255, 255, .02);
}
.table thead th:first-child,
.table tr:first-child th:first-child { border-top-left-radius: 8px; }
.table thead th:last-child,
.table tr:first-child th:last-child { border-top-right-radius: 8px; }
.table tr:hover td { background: rgba(74, 163, 255, .035); }
.table tr:last-child td { border-bottom: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .01em;
  border: 1px solid transparent;
  background: rgba(139, 155, 176, .12);
  color: var(--muted);
}
.badge.coruna { background: rgba(138, 164, 255, .15); color: var(--coruna); border-color: rgba(138, 164, 255, .18); }
.badge.darksword { background: rgba(61, 206, 142, .15); color: var(--ds); border-color: rgba(61, 206, 142, .18); }
.badge.on { background: rgba(61, 206, 142, .15); color: var(--ds); border-color: rgba(61, 206, 142, .2); }
.badge.off { background: rgba(139, 155, 176, .12); color: var(--muted); }
.badge.pending { background: rgba(224, 161, 74, .15); color: var(--warn); border-color: rgba(224, 161, 74, .2); }
.badge.sent { background: rgba(74, 163, 255, .15); color: var(--accent); border-color: rgba(74, 163, 255, .2); }
.badge.done { background: rgba(61, 206, 142, .15); color: var(--ds); border-color: rgba(61, 206, 142, .2); }
.badge.likely { background: rgba(255, 107, 107, .18); color: #ff8a8a; border-color: rgba(255, 107, 107, .22); }

/* ========== Tabs / KV / Pager ========== */
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 6px;
  background: rgba(255, 255, 255, .02);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
}
.tabs a {
  padding: 8px 12px;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  text-decoration: none;
  border: 1px solid transparent;
  transition: all .15s ease;
}
.tabs a:hover { color: var(--text); background: rgba(255, 255, 255, .04); }
.tabs a.on {
  color: #061018;
  background: linear-gradient(180deg, #5aadff, var(--accent));
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(74, 163, 255, .25);
}

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 10px 14px; }
.kv b { color: var(--muted); font-weight: 550; }

.pager { margin-top: 14px; color: var(--muted); }
.pager a { margin-right: 8px; }
.pagination { display: flex; gap: 6px; list-style: none; padding: 0; margin: 12px 0 0; flex-wrap: wrap; }
.pagination li a,
.pagination li span {
  display: inline-block;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, .02);
}
.pagination li a:hover { border-color: var(--accent); color: var(--accent); }
.pagination li.active span {
  background: var(--accent);
  color: #061018;
  border-color: var(--accent);
  font-weight: 700;
}

/* ========== Photos / Notes ========== */
.photo-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.photo-item {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.photo-item:hover {
  border-color: rgba(74, 163, 255, .35);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.photo-thumb { position: relative; display: block; }
.photo-scan-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  font-size: 11px;
  padding: 2px 7px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  pointer-events: none;
}
.photo-scan-badge.likely { font-size: 10px; max-width: 92%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-item img { width: 100%; height: 160px; object-fit: cover; display: block; }
.photo-meta { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; }
.photo-meta code { font-size: 11px; word-break: break-all; }
.photo-missing {
  width: 100%;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: #141b24;
  border: 1px dashed #3a4658;
  color: #7d8ea6;
  font-size: 12px;
  padding: 8px;
  text-align: center;
}

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photos a {
  display: block;
  background: var(--bg);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  transition: border-color .15s ease, transform .15s ease;
}
.photos a:hover { border-color: rgba(74, 163, 255, .35); transform: translateY(-1px); }
.photos .photo-thumb { position: relative; }
.photos img { width: 100%; height: 140px; object-fit: cover; display: block; }

.note-list-tg { display: flex; flex-direction: column; gap: 8px; }
.note-row-tg {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 11px;
  color: inherit;
  border: 1px solid var(--line);
  background: rgba(8, 12, 18, .35);
  transition: border-color .15s ease, background .15s ease;
}
.note-row-tg:hover { background: rgba(74, 163, 255, .04); border-color: rgba(74, 163, 255, .25); }
.note-row-device { flex: 0 0 auto; max-width: 28%; }
.note-row-device a { text-decoration: none; }
.note-row-device a:hover code { color: var(--accent); }
.note-row-device code { font-size: 11px; word-break: break-all; }
.note-row-main { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.note-row-meta { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }
.note-row-meta .btn.ghost { padding: 4px 10px; font-size: 12px; white-space: nowrap; }
.note-detail-block p { margin: 0 0 10px; text-align: left; }
.note-detail-body { max-height: 420px; text-align: left; margin: 0; }
.note-item {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.note-item h3 { margin: 6px 0 8px; font-size: 15px; font-weight: 600; }

.pre {
  white-space: pre-wrap;
  word-break: break-all;
  background: rgba(8, 12, 18, .55);
  padding: 12px;
  border-radius: 10px;
  font-size: 12px;
  color: #c9d6e5;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line-soft);
}

.secret {
  background: linear-gradient(180deg, #2a1a1e, #23181b);
  border: 1px solid #4a2c32;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 8px;
}
.secret code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-all;
  background: transparent;
  border: 0;
  padding: 0;
  color: #f0c9cf;
}
.secret-cell { min-width: 280px; max-width: 560px; }

.wallet-group h3 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.wallet-pair {
  border: 1px solid #3a2a30;
  border-radius: 12px;
  padding: 12px 14px 6px;
  margin-bottom: 14px;
  background: rgba(0, 0, 0, .16);
}
.wallet-pair .secret { margin-bottom: 8px; }
.wallet-pair .wallet-fold { margin-top: 0; }
.wallet-fold {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 10px 0;
  background: rgba(8, 12, 18, .4);
}
.wallet-fold summary {
  cursor: pointer;
  padding: 10px 12px;
  color: var(--text);
  list-style: none;
  display: flex;
  gap: 8px;
  align-items: center;
}
.wallet-fold summary::-webkit-details-marker { display: none; }
.wallet-fold summary::before { content: "▸"; color: var(--muted); }
.wallet-fold[open] summary::before { content: "▾"; }
.wallet-fold .table { margin: 0 10px 10px; width: calc(100% - 20px); }

.cmd-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.apps-all { display: none; margin-top: 12px; }
.apps-all.show { display: block; }

/* ========== Promo / Channels ========== */
.promo-link-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.promo-iframe-wrap { margin-top: 10px; max-width: 520px; }
.promo-iframe-snippet {
  display: block;
  font-size: 11px;
  line-height: 1.45;
  word-break: break-all;
  white-space: pre-wrap;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--line);
  color: #c9d6e5;
}
button.btn-toggle-iframe.on { border-color: var(--accent); color: var(--accent); }
.tg-inline-form { display: flex; flex-direction: column; gap: 6px; }

/* ========== Login ========== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 20% 10%, rgba(74, 163, 255, .16), transparent 55%),
    radial-gradient(700px 420px at 85% 80%, rgba(61, 206, 142, .10), transparent 50%),
    linear-gradient(160deg, #0a0e14, #121821 55%, #0d131b);
}
.login-box {
  width: 380px;
  background: linear-gradient(180deg, rgba(28, 36, 49, .96), rgba(23, 30, 41, .98));
  border: 1px solid rgba(74, 163, 255, .18);
  border-radius: 18px;
  padding: 32px 30px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .04);
}
.login-box h1 { margin: 0 0 6px; font-size: 24px; font-weight: 750; letter-spacing: -.02em; }
.login-box > p { margin: 0 0 22px; color: var(--muted); }
.login-box label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }
.login-box input[type=text],
.login-box input[type=password] { width: 100%; }
.login-box button {
  width: 100%;
  margin-top: 20px;
  padding: 11px 14px;
  font-size: 15px;
}
.login-remember {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin: 14px 0 0 !important;
  font-size: 14px;
  cursor: pointer;
  color: var(--text) !important;
}
.login-remember input { width: auto !important; margin: 0; }

.err { color: var(--danger); margin: 0 0 10px; }
.ok { color: var(--ok); }

/* ========== Stats helpers ========== */
.seg {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.seg .btn.on,
.seg a.on,
button.ghost.on,
.btn.ghost.on {
  background: linear-gradient(180deg, #5aadff, var(--accent)) !important;
  color: #061018 !important;
  border-color: transparent !important;
  filter: none !important;
}
.bar-track {
  background: #243040;
  border-radius: 999px;
  height: 10px;
  width: 100%;
  overflow: hidden;
}
.bar-fill {
  background: linear-gradient(90deg, #3a8eef, #4aa3ff);
  height: 10px;
  border-radius: 999px;
}

/* ========== SweetAlert ========== */
.swal2-popup.adm-swal {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.swal2-popup.adm-swal .swal2-title { color: var(--text); font-size: 18px; }
.swal2-popup.adm-swal .swal2-html-container { color: var(--muted); }
.swal2-popup.adm-swal .swal2-actions { gap: 10px; }
.swal-json {
  max-height: 70vh;
  overflow: auto;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 0;
}
.swal-json .jk { color: #7dd3fc; }
.swal-json .js { color: #86efac; }
.swal-json .jn { color: #fcd34d; }
.swal-json .jl { color: #f472b6; }

@media (max-width: 900px) {
  .layout { display: block; }
  .side { width: auto; height: auto; position: relative; border-right: 0; border-bottom: 1px solid var(--line); }
  .cmd-grid { grid-template-columns: 1fr; }
  .main { padding: 16px 14px 40px; }
  .kv { grid-template-columns: 110px 1fr; }
}
