/* BWT — Tabler / GitHub Primer inspired · 16px base */

:root,
[data-theme="light"] {
  --bg-base: #f4f6f8;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-muted: #eef1f4;
  --bg-subtle: #f8f9fb;
  --bg-hover: #e8ecf0;
  --bg-active: #dce3ea;

  --border: #d8dee4;
  --border-strong: #b8c0cc;

  --text: #1a1d21;
  --text-secondary: #4a5568;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;

  --accent: #206bc4;
  --accent-hover: #1a569d;
  --accent-subtle: rgba(32, 107, 196, 0.08);

  --tg-primary: #3390ec;
  --tg-success: #4fae4e;
  --tg-danger: #e53935;

  --success: #2fb344;
  --success-subtle: rgba(47, 179, 68, 0.1);
  --danger: #d63939;
  --danger-subtle: rgba(214, 57, 57, 0.1);
  --warning: #f59f00;
  --warning-subtle: rgba(245, 159, 0, 0.1);

  --shadow-sm: 0 1px 2px rgba(26, 29, 33, 0.06);
  --shadow-md: 0 2px 8px rgba(26, 29, 33, 0.08);

  --radius: 5px;
  --radius-lg: 8px;

  --sidebar-w: 280px;
  --header-h: 60px;
  --content-max: 1080px;

  --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg-base: #0f1419;
  --bg-surface: #161b22;
  --bg-elevated: #1c2128;
  --bg-muted: #1c2128;
  --bg-subtle: #13171d;
  --bg-hover: #262c36;
  --bg-active: #30363d;

  --border: #30363d;
  --border-strong: #484f58;

  --text: #e6edf3;
  --text-secondary: #b1bac4;
  --text-muted: #8b949e;
  --text-faint: #656d76;

  --accent: #388bfd;
  --accent-hover: #58a6ff;
  --accent-subtle: rgba(56, 139, 253, 0.12);

  --tg-primary: #3390ec;
  --tg-success: #4fae4e;
  --tg-danger: #e53935;

  --success: #3fb950;
  --success-subtle: rgba(63, 185, 80, 0.12);
  --danger: #f85149;
  --danger-subtle: rgba(248, 81, 73, 0.12);
  --warning: #d29922;
  --warning-subtle: rgba(210, 153, 34, 0.12);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);

  color-scheme: dark;
}

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

html { font-size: 16px; }

body {
  font-family: var(--font-sans);
  font-size: 1rem;
  background: var(--bg-base);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Theme toggle ── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-surface);
}

.theme-toggle button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.theme-toggle button:hover { color: var(--text); background: var(--bg-hover); }
.theme-toggle button.active {
  background: var(--accent-subtle);
  color: var(--accent);
}

.theme-toggle button svg { width: 16px; height: 16px; }

/* ── Auth ── */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.auth-brand {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3.5rem 4.5rem;
}

.auth-brand .brand-mark {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}

.auth-brand .brand-logo {
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--accent);
  line-height: 1;
}

.auth-brand .brand-sub {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  text-transform: uppercase;
}

.auth-brand h1 {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin-bottom: 1rem;
}

.auth-brand p {
  color: var(--text-muted);
  font-size: 1.0625rem;
  max-width: 360px;
  line-height: 1.65;
}

.auth-brand .feature-list {
  margin-top: 2.75rem;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.auth-brand .feature-list li {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  padding-left: 1.375rem;
  position: relative;
}

.auth-brand .feature-list li::before {
  content: "—";
  position: absolute;
  left: 0;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

.auth-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem;
  background: var(--bg-base);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
  box-shadow: var(--shadow-sm);
}

.auth-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.auth-card h2 {
  font-size: 1.375rem;
  font-weight: 600;
}

.auth-tabs { width: 100%; margin-bottom: 1.5rem; }

/* ── Layout ── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-top {
  padding: 1.25rem 1.125rem 1rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.brand-icon {
  width: 34px;
  height: 34px;
  background: var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 700;
  color: #fff;
}

.brand-text {
  font-size: 1rem;
  font-weight: 600;
}

.brand-sub {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 0.125rem;
}

.sidebar-section-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 0.875rem 1.125rem 0.5rem;
}

.bot-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.375rem 0.625rem;
}

.bot-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.1s;
  margin-bottom: 2px;
}

.bot-item:hover { background: var(--bg-hover); }

.bot-item.active {
  background: var(--accent-subtle);
  border-color: var(--accent);
}

.bot-item .status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}

.bot-item .status-dot.running { background: var(--success); }

.bot-item .name {
  flex: 1;
  font-size: 0.9375rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-actions {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Main */
.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.75rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: baseline;
  gap: 0.875rem;
}

.topbar h1 {
  font-size: 1.125rem;
  font-weight: 600;
}

.breadcrumb {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.stat-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.stat-item {
  padding: 0.375rem 0.875rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
  background: var(--bg-subtle);
  font-family: var(--font-mono);
}

.stat-item:last-child { border-right: none; }
.stat-item strong { color: var(--text); font-weight: 600; }

.user-chip {
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
}

.main {
  flex: 1;
  padding: 1.5rem 1.75rem 2.5rem;
  overflow-y: auto;
}

.content-wrap {
  max-width: var(--content-max);
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.tab {
  padding: 0.625rem 1.25rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s, border-color 0.12s;
}

.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tabs-segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tabs-segmented .tab {
  border-bottom: none;
  margin-bottom: 0;
  border-right: 1px solid var(--border);
  flex: 1;
}

.tabs-segmented .tab:last-child { border-right: none; }
.tabs-segmented .tab.active {
  background: var(--accent-subtle);
}

/* ── Panel ── */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  min-height: 52px;
}

.panel-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.panel-title .hint {
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 0.5rem;
  font-size: 0.875rem;
}

.panel-body { padding: 1.25rem; }

.callout {
  font-size: 0.9375rem;
  color: var(--text-muted);
  padding: 0.75rem 1rem;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  line-height: 1.6;
}

.callout code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--bg-hover);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  color: var(--text-secondary);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* ── Form ── */
label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

label .hint {
  font-weight: 400;
  color: var(--text-faint);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
textarea,
select {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5625rem 0.875rem;
  color: var(--text);
  font-size: 0.9375rem;
  font-family: inherit;
  line-height: 1.5;
  transition: border-color 0.12s, box-shadow 0.12s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

textarea {
  resize: vertical;
  min-height: 130px;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.65;
}

.form-group { margin-bottom: 1rem; }
.form-group:last-child { margin-bottom: 0; }

.form-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.form-row .form-group { flex: 1; min-width: 140px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
  min-height: 38px;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-ghost {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  min-height: 34px;
}

.btn-block { width: 100%; }

.action-bar {
  display: flex;
  gap: 0.625rem;
  flex-wrap: wrap;
  padding-top: 0.5rem;
}

/* ── Toggle ── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

.toggle {
  position: relative;
  width: 42px;
  height: 24px;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle input { display: none; }

.toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 12px;
  transition: background 0.15s;
}

.toggle .slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(18px); }

/* ── Mode selector ── */
.mode-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.mode-btn {
  padding: 0.4375rem 1rem;
  border: none;
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9375rem;
  font-family: inherit;
  border-right: 1px solid var(--border);
  transition: background 0.1s, color 0.1s;
  min-height: 36px;
}

.mode-btn:last-child { border-right: none; }
.mode-btn:hover { background: var(--bg-hover); color: var(--text); }
.mode-btn.active {
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 500;
}

/* ── Inline button editor ── */
.button-rows { display: flex; flex-direction: column; gap: 0.625rem; }

.button-row {
  display: grid;
  grid-template-columns: 1fr 1.6fr auto 36px;
  gap: 0.625rem;
  align-items: center;
  padding: 0.625rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.button-row-header {
  display: grid;
  grid-template-columns: 1fr 1.6fr auto 36px;
  gap: 0.625rem;
  padding: 0 0.625rem 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}

.style-picker { display: flex; gap: 4px; }

.style-chip {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0;
  transition: border-color 0.12s, transform 0.1s;
}

.style-chip:hover { transform: scale(1.06); }

.style-chip.active {
  border-color: var(--text);
  box-shadow: 0 0 0 1px var(--text);
}

.style-chip[data-style=""] { background: var(--bg-surface); }
.style-chip[data-style="primary"] { background: var(--tg-primary); }
.style-chip[data-style="success"] { background: var(--tg-success); }
.style-chip[data-style="danger"] { background: var(--tg-danger); }

.style-picker-wrap { padding-bottom: 2px; }

.btn-rm {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--text-faint);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.1s, border-color 0.1s;
}

.btn-rm:hover { color: var(--danger); border-color: var(--danger); }

/* ── Log ── */
.log-panel {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem;
  height: 200px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.75;
}

.log-line { color: var(--text-muted); }
.log-line.error { color: var(--danger); }
.log-line.warning { color: var(--warning); }

/* ── Table ── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

th {
  text-align: left;
  padding: 0.625rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }

td code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text);
}

/* ── Badge ── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: var(--font-mono);
  border: 1px solid transparent;
}

.badge-green {
  background: var(--success-subtle);
  color: var(--success);
  border-color: rgba(47, 179, 68, 0.2);
}

.badge-gray {
  background: var(--bg-muted);
  color: var(--text-muted);
  border-color: var(--border);
}

.badge-blue {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: rgba(32, 107, 196, 0.2);
}

/* ── Empty ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5rem 2rem;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  font-size: 1rem;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1.125rem;
  font-size: 0.9375rem;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  animation: toastIn 0.2s ease;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }

@keyframes toastIn {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── DM chat ── */
.dm-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 320px;
}

.dm-messages {
  flex: 1;
  max-height: 360px;
  overflow-y: auto;
  padding: 0.75rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.dm-bubble {
  max-width: 85%;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.dm-bubble.in {
  align-self: flex-start;
  background: var(--bg-surface);
  border: 1px solid var(--border);
}

.dm-bubble.out {
  align-self: flex-end;
  background: var(--accent-subtle);
  border: 1px solid var(--accent);
  color: var(--text);
}

.dm-meta {
  font-size: 0.6875rem;
  color: var(--text-faint);
  margin-top: 0.25rem;
}

.dm-compose {
  display: flex;
  gap: 0.625rem;
  align-items: flex-end;
}

.dm-compose textarea {
  flex: 1;
  resize: vertical;
  min-height: 4.5rem;
}

.dm-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
  padding: 2rem 1rem;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  html { font-size: 15px; }
  .auth-page { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .grid-2 { grid-template-columns: 1fr; }
  .button-row, .button-row-header { grid-template-columns: 1fr; }
  .stat-group { display: none; }
}
