:root {
  --bg: #0f1419;
  --bg-elevated: #1a222c;
  --bg-panel: #151c24;
  --border: #2a3542;
  --text: #e8eef4;
  --text-muted: #8b9aab;
  --accent: #2dd4bf;
  --accent-dim: #14b8a6;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #34d399;
  --radius: 10px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", "Consolas", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(45, 212, 191, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(56, 189, 248, 0.08), transparent),
    var(--bg);
  line-height: 1.55;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: rgba(15, 20, 25, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #38bdf8);
  box-shadow: 0 0 0 1px rgba(45, 212, 191, 0.3);
}

.nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.nav a {
  color: var(--text-muted);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.9rem;
}

.nav a:hover,
.nav a.active {
  color: var(--text);
  background: var(--bg-elevated);
  text-decoration: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 1.5rem;
  max-width: 1220px;
  margin: 0 auto;
  padding: 1.5rem;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.hero {
  padding: 2.5rem 0 1.5rem;
}

.hero h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(1.75rem, 4vw, 2.35rem);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.hero p {
  margin: 0;
  max-width: 36rem;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1.75rem;
}

.card {
  padding: 1.15rem 1.2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card h3 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.panel {
  position: sticky;
  top: 4.5rem;
  align-self: start;
  max-height: calc(100vh - 5.5rem);
  overflow: auto;
  padding: 1.15rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.panel h2 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.panel-desc {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.field {
  margin-bottom: 0.85rem;
}

.field label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.field textarea {
  min-height: 72px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 2px rgba(45, 212, 191, 0.2);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: #243040;
  border-color: #3d4f63;
}

.btn-primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #042f2e;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent);
}

.btn-danger {
  border-color: rgba(248, 113, 113, 0.4);
  color: var(--danger);
}

.status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.5rem 0 1rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status.is-ready .status-dot {
  background: var(--ok);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.6);
}

.status.is-error .status-dot {
  background: var(--danger);
}

.status.is-idle .status-dot {
  background: var(--warn);
}

.divider {
  height: 1px;
  margin: 1rem 0;
  background: var(--border);
}

.section {
  margin-top: 2rem;
  padding: 1.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.section h2 {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
}

.section p {
  margin: 0 0 1rem;
  color: var(--text-muted);
}

.log {
  margin-top: 0.75rem;
  padding: 0.65rem;
  max-height: 160px;
  overflow: auto;
  border-radius: 8px;
  background: #0a0e12;
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-all;
}

.log:empty::before {
  content: "事件日志为空";
  color: #5a6a7a;
}

.page-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(45, 212, 191, 0.1);
  color: var(--accent);
  font-size: 0.78rem;
}

.footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1rem 1.5rem 5rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  border-top: 1px solid transparent;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.check input {
  accent-color: var(--accent);
}

.slot-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.widget-slot {
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.slot-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.65rem;
}

.slot-head strong {
  font-size: 0.85rem;
}

.slot-badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.slot-badge.is-on {
  border-color: rgba(52, 211, 153, 0.5);
  color: var(--ok);
  background: rgba(52, 211, 153, 0.1);
}

.slot-unread {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.btn-tiny {
  padding: 0.2rem 0.45rem;
  font-size: 0.72rem;
}

.slot-auth {
  margin-top: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.slot-auth summary {
  cursor: pointer;
  user-select: none;
  margin-bottom: 0.5rem;
}

.slot-auth[open] summary {
  margin-bottom: 0.65rem;
  color: var(--text);
}

/* Draggable parent dock — outside widget iframes */
#widget-dock {
  position: fixed;
  z-index: 10050;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 160px;
  max-width: min(360px, calc(100vw - 16px));
  padding: 0.55rem 0.65rem 0.65rem;
  background: rgba(21, 28, 36, 0.94);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  color: var(--text);
  font-family: var(--font);
  touch-action: none;
}

#widget-dock[hidden] {
  display: none !important;
}

#widget-dock.is-dragging {
  opacity: 0.92;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}

.widget-dock-handle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: grab;
  user-select: none;
  padding: 0.15rem 0.1rem 0.35rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
}

.widget-dock-handle:active {
  cursor: grabbing;
}

.widget-dock-grip {
  letter-spacing: -0.12em;
  opacity: 0.7;
}

.widget-dock-title {
  font-weight: 600;
  color: var(--text);
}

.widget-dock-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.widget-dock-btn {
  position: relative;
  appearance: none;
  border: 1px solid rgba(45, 212, 191, 0.45);
  background: var(--accent-dim);
  color: #042f2e;
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, border-color 0.15s;
}

.widget-dock-btn:hover {
  background: var(--accent);
}

.widget-dock-btn.is-open {
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.35);
}

.widget-dock-btn-badge {
  position: absolute;
  top: -6px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-panel);
}

/* Test-client only: per-widget draggable header (not in production widget.js) */
.client-widget-chrome {
  position: fixed;
  z-index: 10040;
  height: 36px;
  box-sizing: border-box;
  pointer-events: auto;
}

.client-widget-chrome[hidden] {
  display: none !important;
}

.client-widget-chrome-header {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 10px;
  border-radius: 12px 12px 0 0;
  background: linear-gradient(180deg, #1a222c 0%, #151c24 100%);
  border: 1px solid var(--border);
  border-bottom: none;
  color: var(--text);
  cursor: grab;
  user-select: none;
  touch-action: none;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.25);
}

.client-widget-chrome.is-dragging .client-widget-chrome-header {
  cursor: grabbing;
}

.client-widget-chrome-grip {
  opacity: 0.55;
  letter-spacing: -0.12em;
  font-size: 0.75rem;
}

.client-widget-chrome-title {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-widget-chrome-close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 6px;
}

.client-widget-chrome-close:hover {
  color: var(--text);
}
