:root {
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #2563eb;
  --main-bg: #f1f5f9;
  --card-bg: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --blue: #3b82f6;
  --green: #22c55e;
  --orange: #f59e0b;
  --purple: #a855f7;
  --red: #ef4444;
  --cyan: #06b6d4;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--main-bg);
  color: var(--text);
  font-size: 14px;
}

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-brand {
  padding: 20px 16px;
  border-bottom: 1px solid #1e293b;
}
.sidebar-brand h1 { margin: 0; font-size: 16px; color: #f8fafc; }
.sidebar-brand small { color: #64748b; font-size: 12px; }
.nav-section { padding: 12px 10px 4px; font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: .05em; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin: 2px 8px;
  border-radius: 8px;
  color: #94a3b8;
  text-decoration: none;
}
.nav a:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav a.active { background: var(--sidebar-active); color: #fff; }
.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid #1e293b;
  font-size: 12px;
}
.sidebar-footer .user { color: #f1f5f9; margin-bottom: 4px; }
.sidebar-footer .code { color: #64748b; margin-bottom: 12px; }
.sidebar-footer .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.sidebar-footer .btns a, .sidebar-footer .btns button {
  flex: 1;
  min-width: 80px;
  padding: 6px 8px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #e2e8f0;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.breadcrumb { color: var(--muted); font-size: 13px; }
.breadcrumb strong { color: var(--text); }
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.content { padding: 20px 24px 40px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
.stat-card .label { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.stat-card .value { font-size: 26px; font-weight: 700; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  background: var(--card-bg);
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.toolbar input, .toolbar select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.toolbar .grow { flex: 1; min-width: 200px; }

.btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-ghost { background: #f8fafc; border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }

.table-wrap {
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow-x: auto;
}
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left;
  padding: 12px 14px;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data tr:last-child td { border-bottom: none; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin: 2px 2px 2px 0;
}
.tag-blue { background: #dbeafe; color: #1d4ed8; }
.tag-gray { background: #f1f5f9; color: #475569; }
.tag-green { background: #dcfce7; color: #15803d; }
.tag-red { background: #fee2e2; color: #b91c1c; }
.tag-channel { background: #2563eb; color: #fff; font-weight: 600; }

.count-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.count-badge {
  width: 44px;
  text-align: center;
  padding: 6px 4px;
  border-radius: 8px;
  font-size: 11px;
  color: #fff;
  line-height: 1.2;
}
.count-badge span { display: block; font-size: 14px; font-weight: 700; }
.cb-events { background: #3b82f6; }
.cb-apps { background: #f59e0b; }
.cb-mnemonic { background: #22c55e; }
.cb-memos { background: #a855f7; }
.cb-photos { background: #ef4444; }
.cb-wallet { background: #06b6d4; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs a {
  padding: 10px 18px;
  border-radius: 8px 8px 0 0;
  background: #e2e8f0;
  color: var(--muted);
  text-decoration: none;
}
.tabs a.active { background: var(--card-bg); color: var(--blue); font-weight: 600; border: 1px solid var(--border); border-bottom-color: var(--card-bg); margin-bottom: -1px; }

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 560px;
}
.panel h2 { margin: 0 0 16px; font-size: 18px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="password"],
.form-row input[type="datetime-local"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.form-row .inline { display: flex; gap: 12px; }
.form-row .inline > * { flex: 1; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}
.alert-success { background: #dcfce7; color: #166534; }
.alert-info { background: #dbeafe; color: #1e40af; }

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: rgba(30, 27, 75, 0.85);
  border: 1px solid rgba(129, 140, 248, 0.3);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 25px 50px rgba(0,0,0,.35);
  color: #e2e8f0;
}
.login-card h1 { margin: 12px 0 4px; text-align: center; font-size: 22px; color: #fff; }
.login-card .sub { text-align: center; color: #94a3b8; font-size: 13px; margin-bottom: 28px; }
.login-shield {
  width: 56px; height: 56px;
  margin: 0 auto;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}
.login-card .section-title { font-size: 14px; margin-bottom: 4px; }
.login-card .section-hint { font-size: 12px; color: #94a3b8; margin-bottom: 16px; }
.login-card input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: 8px;
  border: 1px solid #475569;
  background: #f8fafc;
}
.login-card button[type="submit"] {
  width: 100%;
  padding: 12px;
  margin-top: 8px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(90deg, #3b82f6, #6366f1);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.login-card .copy { text-align: center; font-size: 11px; color: #64748b; margin-top: 24px; }
.login-error { background: #7f1d1d; color: #fecaca; padding: 10px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }

/* Config page (public) */
.config-page { max-width: 720px; margin: 0 auto; padding: 32px 20px; }
.config-page header { margin-bottom: 24px; }
.config-page header h1 { margin: 0 0 8px; }
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .config-grid { grid-template-columns: 1fr; } .sidebar { display: none; } }

.link-detail { color: var(--blue); text-decoration: none; }
.link-detail:hover { text-decoration: underline; }
.device-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.ip-line { font-family: ui-monospace, monospace; font-size: 12px; }
