/* ═══════════════════════════════════════════════════════════════
   Admin3 shared styles — mobile-first, no build tools, no framework.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --brand-weak: #dbeafe;
  --green: #16a34a;
  --green-weak: #dcfce7;
  --red: #dc2626;
  --red-weak: #fee2e2;
  --amber: #d97706;
  --amber-weak: #fef3c7;
  --purple: #7c3aed;
  --purple-weak: #ede9fe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ── Shell: sidebar (desktop) / drawer (mobile) ── */
.a3-shell { display: flex; min-height: 100vh; }
.a3-nav {
  width: 210px; flex-shrink: 0; background: #111827; color: #d1d5db;
  display: flex; flex-direction: column; position: sticky; top: 0;
  height: 100vh; overflow-y: auto; z-index: 40;
}
.a3-nav .brand { font-size: 17px; font-weight: 700; color: #fff; padding: 18px 16px 12px; letter-spacing: .5px; }
.a3-nav .brand small { display: block; font-size: 11px; font-weight: 400; color: #9ca3af; }
.a3-nav a.item {
  display: flex; align-items: center; gap: 10px; padding: 11px 16px;
  color: #d1d5db; font-size: 14px; border-left: 3px solid transparent;
}
.a3-nav a.item .ico { width: 20px; text-align: center; }
.a3-nav a.item.active { background: #1f2937; color: #fff; border-left-color: var(--brand); }
.a3-nav a.item:hover { color: #fff; }
.a3-nav .foot { margin-top: auto; padding: 12px 16px; border-top: 1px solid #1f2937; }
.a3-nav .foot button { width: 100%; background: none; border: 1px solid #374151; color: #9ca3af; border-radius: 8px; padding: 7px; }

.a3-main { flex: 1; min-width: 0; padding: 14px 14px 40px; }
.a3-topbar {
  display: none; position: sticky; top: 0; z-index: 30; background: #111827; color: #fff;
  padding: 10px 14px; align-items: center; gap: 10px;
}
.a3-topbar .burger { background: none; border: 0; color: #fff; font-size: 20px; line-height: 1; }
.a3-topbar .title { font-weight: 600; flex: 1; }
.a3-topbar a { color: #93c5fd; font-size: 13px; }

@media (max-width: 899px) {
  .a3-shell { display: block; }
  .a3-topbar { display: flex; }
  .a3-nav {
    position: fixed; left: -220px; top: 0; transition: left .2s ease; height: 100vh;
    box-shadow: none;
  }
  .a3-shell.nav-open .a3-nav { left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .a3-main { padding-top: 0; }
}

/* ── Login gate ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 32px 26px; width: 100%; max-width: 360px; text-align: center;
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card p.sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; margin-bottom: 12px;
}
.login-card input:focus { outline: 2px solid var(--brand-weak); border-color: var(--brand); }
.login-err { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 6px; }

/* ── Blocks / cards / grids ── */
.block { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px; }
.block > h3 { font-size: 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.block > h3 .spacer { flex: 1; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px;
}
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 719px) { .two-col { grid-template-columns: 1fr; } }

/* ── Tables ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { color: var(--muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--card); }
.tbl tr:hover td { background: #f9fafb; }
.tbl td.wrap { white-space: normal; min-width: 160px; max-width: 380px; }
.tbl .num { font-variant-numeric: tabular-nums; }
.tbl .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* ── Badges / dots ── */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 500; vertical-align: middle; }
.b-green { background: var(--green-weak); color: var(--green); }
.b-red { background: var(--red-weak); color: var(--red); }
.b-amber { background: var(--amber-weak); color: var(--amber); }
.b-blue { background: var(--brand-weak); color: var(--brand); }
.b-purple { background: var(--purple-weak); color: var(--purple); }
.b-gray { background: #f3f4f6; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px var(--green-weak); }
.dot.off { background: #d1d5db; }

/* ── Buttons / forms ── */
.btn {
  display: inline-flex; align-items: center; gap: 5px; padding: 7px 14px;
  border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  font-size: 13px;
}
.btn:hover { border-color: #c7cdd6; background: #f9fafb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input.f, select.f, textarea.f {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; font-size: 13px;
  background: #fff; color: var(--ink); max-width: 100%;
}
input.f:focus, select.f:focus, textarea.f:focus { outline: 2px solid var(--brand-weak); border-color: var(--brand); }
textarea.f { width: 100%; min-height: 90px; font-family: inherit; }
label.f { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 3px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input.f { min-width: 140px; flex: 1; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 14px; }

/* ── Tabs / pills ── */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button {
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; font-size: 13px;
}
.tabs button.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ── Paginator ── */
.pager { display: flex; gap: 5px; align-items: center; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.pager button { min-width: 32px; padding: 5px 9px; border: 1px solid var(--line); background: #fff; border-radius: 8px; font-size: 13px; }
.pager button.cur { background: var(--brand); color: #fff; border-color: var(--brand); }
.pager button:disabled { opacity: .4; }
.pager .info { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* ── Progress bar ── */
.pbar { height: 6px; border-radius: 4px; background: #e5e7eb; overflow: hidden; min-width: 60px; }
.pbar > i { display: block; height: 100%; background: var(--green); }
.pbar.warn > i { background: var(--amber); }
.pbar.crit > i { background: var(--red); }

/* ── Chat monitor ── */
.chat-scroll {
  display: flex; flex-direction: column; gap: 10px; padding: 12px;
  background: #f8fafc; border-radius: var(--radius); min-height: 50vh; max-height: 66vh; overflow-y: auto;
}
.bubble { max-width: 86%; padding: 8px 12px; border-radius: 14px; font-size: 14px; word-break: break-word; white-space: pre-wrap; }
.bubble.user { align-self: flex-start; background: #e0ecff; border-bottom-left-radius: 4px; }
.bubble.assistant { align-self: flex-end; background: #d9f2dd; border-bottom-right-radius: 4px; }
.bubble.sysmsg { align-self: center; background: #eef0f3; color: var(--muted); font-size: 12px; max-width: 96%; }
.bubble .meta { font-size: 11px; color: var(--muted); margin-top: 4px; user-select: none; }
.bubble .meta .role-tag { font-weight: 600; }
.msg-media img { max-width: 180px; max-height: 180px; border-radius: 8px; cursor: zoom-in; display: block; margin-top: 4px; }
.msg-media video { max-width: 220px; border-radius: 8px; margin-top: 4px; }
.voice-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.voice-row audio { height: 32px; }
.voice-transcription { font-size: 12px; color: var(--muted); font-style: italic; }
.file-link { display: inline-block; font-size: 12px; margin-top: 4px; }
.thinking { align-self: center; color: var(--amber); font-size: 12px; padding: 4px; }
.thinking .dots::after { content: '…'; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* ── Gallery (chat images / market) ── */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.g-card { background: var(--card); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; font-size: 12px; }
.g-card img { width: 100%; height: 120px; object-fit: cover; display: block; cursor: zoom-in; background: #f3f4f6; }
.g-card .g-body { padding: 7px 9px; }
.g-card .g-sub { color: var(--muted); font-size: 11px; margin-top: 2px; }
.g-card .g-ops { padding: 0 9px 8px; display: flex; gap: 6px; }

/* ── Modal / lightbox / toast ── */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal { background: #fff; border-radius: 14px; padding: 18px; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; }
.modal h3 { margin-bottom: 12px; font-size: 16px; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 95; display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 12px; }
.lightbox img, .lightbox video { max-width: 96vw; max-height: 92vh; border-radius: 6px; }
#a3-toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 9px 18px; border-radius: 999px;
  font-size: 13px; z-index: 99; box-shadow: 0 4px 14px rgba(0,0,0,.3); max-width: 90vw;
}
#a3-toast.err { background: var(--red); }
#a3-toast.ok { background: var(--green); }

/* ── Chart (CSS bars) ── */
.bar-chart { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding: 6px 0 0; }
.bar-chart .bar { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 1px; position: relative; opacity: .85; }
.bar-chart .bar:hover { opacity: 1; }
.bar-chart .bar .tip {
  display: none; position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; font-size: 11px; padding: 3px 7px; border-radius: 6px; white-space: nowrap; z-index: 5;
}
.bar-chart .bar:hover .tip { display: block; }

/* ── Misc ── */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 10px; }
.mb { margin-bottom: 10px; }
.flex { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }
.empty { color: var(--muted); text-align: center; padding: 26px 10px; font-size: 13px; }
pre.persona {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; font-size: 12.5px; white-space: pre-wrap; word-break: break-word;
  max-height: 60vh; overflow-y: auto;
}
.skel { color: var(--muted); padding: 20px; text-align: center; }
kbd.k {
  background: #f3f4f6; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: 0 5px; font-size: 11px; font-family: inherit;
}
