:root {
  --bg: #0b0f14;
  --surface: #121820;
  --surface-2: #182029;
  --surface-3: #1e2833;
  --border: #232d39;
  --text: #e7edf3;
  --text-dim: #8a97a6;
  --text-faint: #56626f;
  --accent: #33e29b;
  --accent-dim: #1c8f63;
  --accent-soft: rgba(51, 226, 155, 0.12);
  --warn: #ffb020;
  --warn-soft: rgba(255, 176, 32, 0.12);
  --danger: #ff5c72;
  --danger-soft: rgba(255, 92, 114, 0.12);
  --rank-developer: #b388ff;
  --rank-owner: #ffb020;
  --rank-partner: #4fc3f7;
  --rank-reseller: #33e29b;
  --rank-member: #8a97a6;
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  --sidebar-width: 236px;
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  background-image: radial-gradient(circle at 12% -10%, rgba(51, 226, 155, 0.08), transparent 40%),
    radial-gradient(circle at 100% 0%, rgba(79, 195, 247, 0.06), transparent 35%);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: inherit;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  margin: 0 0 4px;
  letter-spacing: 0.01em;
}

p {
  margin: 0 0 12px;
  color: var(--text-dim);
}

.mono {
  font-family: var(--font-mono);
}

.hidden {
  display: none !important;
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  position: relative;
  overflow: hidden;
}

.auth-card::before {
  content: "";
  position: absolute;
  top: -60px;
  right: -60px;
  width: 160px;
  height: 160px;
  background: var(--accent);
  filter: blur(90px);
  opacity: 0.25;
}

.auth-mark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-bottom: 18px;
}

.auth-mark .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.auth-card h1 {
  font-size: 24px;
}

.ladder {
  display: flex;
  flex-direction: column-reverse;
  gap: 4px;
  padding: 10px 12px;
}

.ladder-rung {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-3);
  position: relative;
  transition: background 0.2s ease;
}

.ladder-rung.filled {
  background: var(--rung-color, var(--accent));
}

.ladder-rung.current {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--rung-color, var(--accent));
}

.ladder-horizontal {
  flex-direction: row;
  padding: 0;
  gap: 5px;
}

.ladder-horizontal .ladder-rung {
  height: 5px;
  flex: 1;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input.mono {
  font-family: var(--font-mono);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.row .field {
  flex: 1;
  margin-bottom: 0;
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-primary {
  background: var(--accent);
  color: #04140d;
  width: 100%;
}

.btn-block {
  width: 100%;
}

.btn-ghost {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(255, 92, 114, 0.35);
  padding: 8px 14px;
  font-size: 13px;
}

.btn-small {
  padding: 8px 14px;
  font-size: 13px;
}

.msg {
  min-height: 18px;
  font-size: 13px;
  margin-top: 10px;
}

.msg.ok {
  color: var(--accent);
}

.msg.err {
  color: var(--danger);
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
}

.brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.identity-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.identity-name {
  font-family: var(--font-mono);
  font-size: 14px;
  margin-bottom: 8px;
  word-break: break-all;
}

.role-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--pill-bg, var(--accent-soft));
  color: var(--pill-color, var(--accent));
  font-weight: 700;
}

.role-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.nav-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  flex: 1;
  overflow-y: auto;
  align-content: start;
}

.nav-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 14px 6px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.nav-tile-icon {
  width: 20px;
  height: 20px;
  display: flex;
}

.nav-tile-icon svg {
  width: 100%;
  height: 100%;
}

.nav-tile-label {
  line-height: 1.2;
}

.nav-tile:hover {
  background: var(--surface-3);
  color: var(--text);
}

.nav-tile.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-dim);
}

.logout-form button {
  width: 100%;
}

.btn-icon-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-icon-inline svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 90px;
}

.topbar-mobile {
  display: none;
}

.page-head {
  margin-bottom: 22px;
}

.page-head h1 {
  font-size: 22px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}

.card h2 {
  font-size: 16px;
  margin-bottom: 4px;
}

.card-hint {
  font-size: 13px;
  color: var(--text-faint);
  margin-bottom: 16px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 4px;
  border-top: 1px solid var(--border);
}

.list-item:first-child {
  border-top: none;
}

.list-item .primary {
  font-family: var(--font-mono);
  font-size: 14px;
}

.list-item .meta {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 3px;
  font-family: var(--font-body);
}

.status-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}

.status-tag.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.status-tag.pending {
  background: var(--warn-soft);
  color: var(--warn);
}

.empty {
  color: var(--text-faint);
  font-size: 13px;
  padding: 18px 4px;
  text-align: center;
}

.actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

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

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat .value {
  font-family: var(--font-display);
  font-size: 26px;
}

.stat .label {
  font-size: 12px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chat-box {
  height: 360px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 12px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg .who {
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chat-msg .bubble {
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 14px;
  display: inline-block;
  max-width: 90%;
}

.chat-msg.self .bubble {
  background: var(--accent-soft);
  color: var(--accent);
}

.docs-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.docs-nav a {
  text-decoration: none;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.endpoint {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.method {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 5px;
}

.method.get {
  background: var(--accent-soft);
  color: var(--accent);
}

.method.post {
  background: var(--warn-soft);
  color: var(--warn);
}

.endpoint-path {
  font-family: var(--font-mono);
  font-size: 14px;
}

pre {
  background: #070a0d;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: #c7f9e3;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table th {
  text-align: left;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 11px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
}

.error-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}

.error-code {
  font-family: var(--font-display);
  font-size: 64px;
  color: var(--accent);
  margin-bottom: 6px;
}

.welcome-card {
  background: linear-gradient(135deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.welcome-text h2 {
  font-size: 19px;
  margin-bottom: 3px;
}

.welcome-text p {
  margin: 0;
  font-size: 13px;
}

.verified-badge {
  width: 15px;
  height: 15px;
  display: inline-flex;
  vertical-align: middle;
  flex-shrink: 0;
}

.verified-badge svg {
  width: 100%;
  height: 100%;
}

.key-value {
  font-family: var(--font-mono);
  font-size: 13px;
  overflow-wrap: anywhere;
  word-break: break-all;
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 8px;
}

.upgrade-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.upgrade-row select {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 12, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.modal-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.modal-close svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 860px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    display: none;
  }

  .topbar-mobile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .main {
    padding: 20px 16px 96px;
  }

  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 20;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    overflow-x: auto;
  }

  .bottom-nav a {
    flex: 1;
    min-width: 60px;
    text-align: center;
    text-decoration: none;
    color: var(--text-faint);
    font-size: 10px;
    padding: 8px 4px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .bottom-nav-icon {
    width: 19px;
    height: 19px;
    display: flex;
  }

  .bottom-nav-icon svg {
    width: 100%;
    height: 100%;
  }

  .bottom-nav a.active {
    color: var(--accent);
  }

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

  .row {
    flex-direction: column;
    align-items: stretch;
  }

  .row .btn {
    width: 100%;
  }
}
