* { box-sizing: border-box; }
:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel-2: #243044;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-2: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}
.hidden { display: none !important; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
button, input, textarea, select {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.success { background: #166534; border-color: #166534; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
input, textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
}
textarea { min-height: 88px; resize: vertical; }
label { display: block; font-size: 0.82rem; color: var(--muted); margin: 0.5rem 0 0.25rem; }
.muted { color: var(--muted); font-size: 0.88rem; }
.guide-toc {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
}
.guide-toc ul { margin: 0.5rem 0 0; padding-left: 1.25rem; }
.guide-toc a { color: var(--accent); }
.guide-table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.9rem; }
.guide-table th, .guide-table td { border: 1px solid var(--border); padding: 0.5rem 0.65rem; text-align: left; }
.guide-table th { background: var(--panel); color: var(--muted); }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.app-header h1 { margin: 0; font-size: 1.1rem; font-weight: 600; }
.app-header-brand {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.85rem;
}
.app-logo-link {
  display: flex;
  align-items: center;
  line-height: 0;
  text-decoration: none;
}
.app-header-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}
.site-logo {
  display: block;
  height: 40px;
  width: auto;
  max-width: min(280px, 65vw);
}
.app-header-brand .header-nav {
  flex-basis: 100%;
  margin-top: 0;
}
.header-nav { display: flex; gap: 0.35rem; margin-top: 0.35rem; }
.header-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  border: 1px solid transparent;
}
.header-nav a:hover { color: var(--text); border-color: var(--border); }
.header-nav a.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.status-pill {
  font-size: 0.78rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: var(--panel-2);
}
.status-pill.live { background: #14532d; color: #bbf7d0; }
.status-pill.static { background: #1e3a5f; color: #bfdbfe; }
.status-pill.offline { background: #451a1a; color: #fecaca; }
.status-pill.warn { background: #713f12; color: #fde68a; }
.status-pill.clickable { cursor: pointer; }
.status-pill.clickable:hover { filter: brightness(1.08); }
.header-right { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.user-badge { font-size: 0.78rem; color: var(--muted); background: var(--panel-2); padding: 0.25rem 0.5rem; border-radius: 6px; }

.connect-bar {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: end;
  padding: 0.75rem 1.25rem;
  background: #121a24;
  border-bottom: 1px solid var(--border);
}
.connect-bar input { max-width: 420px; }
.connect-bar button { margin: 0; }

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 120px);
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 0.75rem;
}
.sidebar h2 { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.project-list { list-style: none; margin: 0; padding: 0; }
.project-list li button {
  width: 100%;
  text-align: left;
  margin-bottom: 0.35rem;
  background: transparent;
}
.project-list li button.active { background: var(--panel-2); border-color: var(--accent); }
.project-list .slug { display: block; font-size: 0.72rem; color: var(--muted); }
.progress-mini {
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin-top: 0.35rem;
  overflow: hidden;
}
.progress-mini span { display: block; height: 100%; background: var(--accent-2); }

.main { padding: 1rem 1.25rem 2rem; overflow-x: auto; }
.view-tabs { display: flex; gap: 0.35rem; margin-bottom: 1rem; flex-wrap: wrap; }
.view-tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.summary-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  min-width: 120px;
}
.stat-card strong { font-size: 1.35rem; display: block; }

.kanban {
  display: grid;
  grid-template-columns: repeat(5, minmax(180px, 1fr));
  gap: 0.75rem;
  align-items: start;
}
@media (max-width: 1200px) {
  .kanban { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
}
.kanban-col {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 280px;
}
.kanban-col h3 {
  margin: 0;
  padding: 0.65rem 0.75rem;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}
.kanban-cards { padding: 0.5rem; display: flex; flex-direction: column; gap: 0.5rem; }
.kanban-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.65rem;
}
.kanban-card .title { font-size: 0.88rem; font-weight: 600; margin-bottom: 0.25rem; }
.kanban-card .meta { font-size: 0.72rem; color: var(--muted); margin-bottom: 0.45rem; }
.kanban-card .move-row { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.kanban-card .move-row button { font-size: 0.72rem; padding: 0.2rem 0.4rem; margin: 0; }

.task-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.task-table th, .task-table td {
  text-align: left;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border);
}
.task-table th { background: var(--panel-2); color: var(--muted); font-size: 0.78rem; }
.task-table tr:last-child td { border-bottom: none; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.panel h3 { margin: 0 0 0.75rem; font-size: 0.95rem; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1; min-width: 140px; }
.row button { flex: 0; margin: 0; }

.output-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  white-space: pre-wrap;
  max-height: 260px;
  overflow: auto;
  margin-top: 0.75rem;
}
.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  max-width: 360px;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }
.toast.error { border-color: var(--danger); }

.docs-page { max-width: 820px; margin: 0 auto; padding: 1.25rem; }
.docs-page h2 { margin-top: 1.5rem; font-size: 1.05rem; }
.docs-page h2:first-child { margin-top: 0; }
.docs-page h3 { margin-top: 1.25rem; font-size: 1rem; }
.docs-page p, .docs-page li { line-height: 1.55; color: var(--text); }
.docs-page code { background: var(--panel-2); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.88em; }
.docs-page pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  overflow: auto;
  font-size: 0.82rem;
}

.blocked-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.blocked-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  display: flex;
  flex-direction: column;
  height: min(88vh, 720px);
  max-height: min(88vh, 720px);
  overflow: hidden;
  padding: 0;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}
.setup-card { max-width: 520px; }
.setup-card-wide { max-width: 580px; }
.setup-card-header {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 0.75rem;
  padding: 1rem 1.25rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.setup-card-header h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.35;
  font-weight: 600;
}
.setup-card-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 1.25rem;
  -webkit-overflow-scrolling: touch;
}
.setup-card-footer {
  flex-shrink: 0;
  padding: 1rem 1.25rem 1.1rem;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.2);
}
.setup-footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
}
.setup-close {
  flex-shrink: 0;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}
.setup-close:hover { border-color: var(--accent); color: #fff; background: var(--accent); }
.blocked-overlay:not(.hidden) {
  display: flex !important;
}
.blocked-overlay.hidden {
  display: none !important;
}
.blocked-overlay:not(.hidden) .setup-close,
.blocked-overlay:not(.hidden) #btnOverlayCloseFooter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ton-payment {
  margin-top: 0.75rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.ton-payment h4 { margin: 0 0 0.5rem; font-size: 0.92rem; }
.ton-payment label { display: block; margin: 0.5rem 0 0.25rem; font-size: 0.82rem; color: var(--muted); }
.ton-payment input { width: 100%; }
.ton-payment a.primary { background: var(--accent); color: #fff; border: 1px solid var(--accent); }

.setup-subhead {
  margin: 1rem 0 0.35rem;
  font-size: 0.92rem;
  font-weight: 600;
}
.setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0 0.25rem;
}
.setup-btn {
  display: inline-block;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--text);
  background: var(--bg);
}
.setup-btn.primary,
a.setup-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.connect-hint {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
}
.connect-hint a { color: var(--accent); }
.connect-hint kbd {
  font-size: 0.78rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel-2);
}
.docs-actions {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.docs-btn {
  display: inline-block;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  background: var(--accent);
  color: #fff !important;
  text-decoration: none;
  font-size: 0.88rem;
}
.docs-btn.ghost {
  background: transparent;
  color: var(--accent) !important;
  border: 1px solid var(--border);
}
.setup-steps {
  margin: 0.75rem 0 1rem;
  padding-left: 1.25rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.65;
}
.setup-steps code {
  font-size: 0.82rem;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}
.setup-note { font-size: 0.82rem; margin: 0.75rem 0 0; }
.install-cmd { margin: 0.5rem 0 1rem; }
.install-cmd label {
  display: block;
  margin: 0.5rem 0 0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.install-cmd-row {
  display: flex;
  gap: 0.4rem;
  align-items: stretch;
}
.install-cmd-text {
  flex: 1;
  display: block;
  font-size: 0.72rem;
  line-height: 1.45;
  padding: 0.45rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  white-space: nowrap;
  max-width: 100%;
}
.install-cmd-note { font-size: 0.78rem; margin: 0.5rem 0 0; }
.install-cmd-row .setup-btn { flex-shrink: 0; align-self: stretch; }
#authDialog label { display: block; margin: 0.5rem 0 0.25rem; font-size: 0.85rem; color: var(--muted); }
#authDialog input, #authDialog select { width: 100%; }
#btnSignIn { margin: 0; font-size: 0.85rem; }
