:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2f3f56;
  --text: #e8eef7;
  --muted: #93a4bd;
  --primary: #4f8cff;
  --primary-hover: #3d78e6;
  --danger: #ef5f5f;
  --success: #3ecf8e;
  --warning: #f0b429;
  --radius: 12px;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  font-family: Inter, Segoe UI, system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: linear-gradient(180deg, #0b1017 0%, #121926 100%);
  color: var(--text);
  min-height: 100vh;
}

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

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 20, 25, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-self: start;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-self: end;
}

.brand-inline {
  font-weight: 700;
  font-size: 1.1rem;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.container.narrow { max-width: 760px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.page-header h2 { margin: 0 0 8px; font-size: 1.75rem; }
.muted { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card.stack { display: grid; gap: 16px; margin-bottom: 20px; }
.card.stack h3 { margin: 0; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
}

.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: rgba(239, 95, 95, 0.15); color: #ffb4b4; border: 1px solid rgba(239, 95, 95, 0.35); }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.btn.full { width: 100%; }

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th, .table td {
  text-align: left;
  padding: 14px 8px;
  border-bottom: 1px solid var(--border);
}

.table th { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.table tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge.active { background: rgba(62, 207, 142, 0.15); color: var(--success); }
.badge.ready { background: rgba(79, 140, 255, 0.12); color: var(--primary); }
.badge.pending_otp { background: rgba(240, 180, 41, 0.15); color: var(--warning); }
.badge.disconnected { background: rgba(147, 164, 189, 0.15); color: var(--muted); }
.badge.off { background: rgba(147, 164, 189, 0.08); color: var(--muted); opacity: 0.7; }

.platform-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.platform-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.platform-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface-2);
}

.platform-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.platform-actions {
  margin-top: 12px;
}

.badge.platform.rubika.active { background: rgba(79, 140, 255, 0.15); color: #7eb0ff; }
.badge.platform.eitaa.active { background: rgba(62, 207, 142, 0.15); color: var(--success); }
.badge.platform.bale.active { background: rgba(0, 166, 156, 0.15); color: #4ecdc4; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.brand { text-align: center; margin-bottom: 28px; }
.brand-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #4f8cff, #7c5cff);
  font-size: 1.5rem;
  font-weight: 800;
}
.brand h1 { margin: 0; }
.brand p { margin: 8px 0 0; color: var(--muted); }

.form { display: grid; gap: 16px; }
.form label {
  display: grid;
  gap: 8px;
  font-size: 0.92rem;
  font-weight: 600;
}

input[type="text"], input[type="password"], input[type="tel"], input[type="url"], textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
  min-height: 84px;
}

input:focus, textarea:focus {
  outline: 2px solid rgba(79, 140, 255, 0.35);
  border-color: var(--primary);
}

.error { color: #ff9d9d; font-size: 0.9rem; }
.success { color: var(--success); font-size: 0.9rem; }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 12px; }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 100;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-card {
  position: relative;
  width: min(520px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 { margin: 0; }
.modal-step { display: grid; gap: 12px; }
.modal-step label {
  display: grid;
  gap: 8px;
  font-size: 0.92rem;
  font-weight: 600;
}

.phone-name { font-weight: 600; }
.phone-desc {
  margin-top: 4px;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.muted.small, .small.muted { font-size: 0.82rem; }

.credential-block label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

code {
  display: block;
  padding: 12px;
  border-radius: 10px;
  background: #0d121a;
  border: 1px solid var(--border);
  word-break: break-all;
  font-size: 0.85rem;
  line-height: 1.5;
}

code.small { font-size: 0.75rem; }

.copy-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.75rem;
}

.success-banner {
  padding: 12px;
  border-radius: 10px;
  background: rgba(62, 207, 142, 0.12);
  color: var(--success);
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
}

.empty-state p { margin-bottom: 16px; }

.echo-mode-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.echo-mode-header h3 { margin: 0; }
.echo-mode-header .hint { margin-bottom: 0; }

.echo-active {
  color: var(--success);
  font-weight: 600;
  margin: 0;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: center;
}

.nav-link {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  transition: 0.15s ease;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-link.active {
  color: var(--primary);
  background: rgba(79, 140, 255, 0.12);
}

.docs-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  align-items: start;
}

.docs-sidebar {
  position: sticky;
  top: 80px;
  padding: 20px;
}

.docs-sidebar h3 {
  margin: 0 0 12px;
  font-size: 0.95rem;
}

.docs-toc {
  display: grid;
  gap: 4px;
}

.docs-toc a {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 6px 8px;
  border-radius: 6px;
}

.docs-toc a:hover {
  color: var(--text);
  background: var(--surface-2);
}

.docs-content {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.docs-section {
  display: grid;
  gap: 14px;
}

.docs-section h3,
.docs-section h4 {
  margin: 0;
}

.docs-section h4 {
  font-size: 0.92rem;
  color: var(--muted);
}

.docs-section > code:not(.endpoint-path):not(.small) {
  white-space: pre-wrap;
}

code.inline {
  display: inline;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.85em;
}

.endpoint-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.endpoint-path {
  display: inline;
  padding: 6px 10px;
  font-size: 0.9rem;
}

.method {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.method.get { background: rgba(79, 140, 255, 0.18); color: #8eb8ff; }
.method.post { background: rgba(62, 207, 142, 0.18); color: var(--success); }
.method.put { background: rgba(240, 180, 41, 0.18); color: var(--warning); }
.method.delete { background: rgba(239, 95, 95, 0.18); color: #ffb4b4; }

.docs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.docs-table th,
.docs-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.docs-table th {
  color: var(--muted);
  font-weight: 600;
}

.docs-table td code {
  display: inline;
  padding: 2px 6px;
  font-size: 0.82rem;
}

.admin-endpoint {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.admin-endpoint:first-of-type {
  border-top: none;
  padding-top: 0;
}

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

  .docs-sidebar {
    position: static;
  }

  .topbar-nav {
    display: none;
  }
}
