:root {
  --bg: #ffffff;
  --fg: #1d1d1f;
  --gray-1: #f5f5f7;
  --gray-2: #e8e8ed;
  --gray-3: #86868b;
  --gray-4: #6e6e73;
  --border: #d2d2d7;
  --accent: #000000;
  --danger: #ff3b30;
  --success: #34c759;
  --radius: 14px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Monaco', 'Menlo', monospace;
  --shadow: 0 2px 20px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.12);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ─── NAVBAR ─────────────────────────────────────────── */
#navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
}

.nav-brand {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
  cursor: pointer;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-links a {
  font-size: 14px;
  color: var(--gray-4);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  cursor: pointer;
}

.nav-links a:hover, .nav-links a.active {
  color: var(--fg);
  background: var(--gray-1);
}

.nav-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  cursor: pointer;
  background: var(--gray-2);
  border: 1.5px solid var(--border);
}

.nav-avatar-placeholder {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--fg);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ─── VIEWS ──────────────────────────────────────────── */
.view {
  display: none;
  min-height: 100vh;
}

.view.active {
  display: block;
}

.page-content {
  max-width: 860px;
  margin: 0 auto;
  padding: 92px 24px 60px;
}

.page-content.narrow {
  max-width: 480px;
}

/* ─── LANDING ────────────────────────────────────────── */
#view-landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: 40px 24px;
}

.landing-logo {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -2px;
  margin-bottom: 16px;
}

.landing-tagline {
  font-size: 21px;
  color: var(--gray-3);
  font-weight: 400;
  max-width: 400px;
  margin-bottom: 48px;
  line-height: 1.4;
}

.landing-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ─── BUTTONS ────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 980px;
  font-size: 15px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: -0.1px;
}

.btn-primary {
  background: var(--fg);
  color: var(--bg);
}

.btn-primary:hover {
  background: #333;
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--gray-1);
  color: var(--fg);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--gray-2);
}

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

.btn-danger:hover {
  background: #e0352b;
}

.btn-ghost {
  background: transparent;
  color: var(--gray-4);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  color: var(--fg);
  border-color: var(--fg);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 17px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ─── AUTH ───────────────────────────────────────────── */
#view-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 40px 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

.auth-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.auth-sub {
  color: var(--gray-3);
  font-size: 15px;
  margin-bottom: 32px;
}

.auth-toggle {
  font-size: 14px;
  color: var(--gray-3);
  margin-top: 20px;
  text-align: center;
}

.auth-toggle a {
  color: var(--fg);
  cursor: pointer;
  text-decoration: underline;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--gray-3);
  font-size: 13px;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── FORMS ──────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-4);
  margin-bottom: 6px;
  letter-spacing: 0.1px;
}

input, textarea, select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  transition: border-color 0.15s;
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--fg);
}

input::placeholder, textarea::placeholder {
  color: var(--gray-3);
}

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

.form-actions {
  margin-top: 24px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.form-actions .btn {
  flex: 1;
}

/* ─── CARDS ──────────────────────────────────────────── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.card-sm {
  padding: 16px 20px;
}

.card + .card {
  margin-top: 12px;
}

/* ─── PAGE HEADER ────────────────────────────────────── */
.page-header {
  margin-bottom: 32px;
}

.page-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.page-subtitle {
  color: var(--gray-3);
  font-size: 15px;
}

/* ─── SECTION ────────────────────────────────────────── */
.section {
  margin-bottom: 40px;
}

.section-title {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.3px;
  margin-bottom: 16px;
}

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

/* ─── PROFILE ────────────────────────────────────────── */
.profile-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 32px;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--gray-2);
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.profile-avatar-placeholder {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--fg);
  color: var(--bg);
  font-size: 28px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.profile-info h2 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.profile-info p {
  color: var(--gray-3);
  font-size: 14px;
  margin-top: 2px;
}

/* ─── STATS GRID ─────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--gray-1);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1px;
}

.stat-label {
  font-size: 13px;
  color: var(--gray-3);
  margin-top: 4px;
}

/* ─── SESSION LIST ───────────────────────────────────── */
.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--gray-2);
}

.session-item:last-child {
  border-bottom: none;
}

.session-app {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--gray-2);
  border: 1px solid var(--border);
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--gray-4);
  flex-shrink: 0;
}

.app-icon img {
  width: 100%;
  height: 100%;
  border-radius: 9px;
  object-fit: cover;
}

.session-name {
  font-size: 15px;
  font-weight: 500;
}

.session-meta {
  font-size: 12px;
  color: var(--gray-3);
  margin-top: 2px;
}

/* ─── DEVELOPER PANEL ────────────────────────────────── */
.app-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}

.app-card:hover {
  border-color: var(--gray-3);
}

.app-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.app-card-name {
  font-size: 17px;
  font-weight: 600;
}

.app-card-desc {
  font-size: 13px;
  color: var(--gray-3);
  margin-top: 2px;
}

.app-card-actions {
  display: flex;
  gap: 8px;
}

.credential-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--gray-1);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 8px;
}

.credential-label {
  font-size: 12px;
  color: var(--gray-3);
  min-width: 80px;
  font-weight: 500;
}

.credential-value {
  font-family: var(--font-mono);
  font-size: 13px;
  flex: 1;
  word-break: break-all;
  color: var(--fg);
}

.credential-value.masked {
  letter-spacing: 2px;
  color: var(--gray-3);
}

.copy-btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  color: var(--gray-4);
  font-family: var(--font);
  transition: all 0.15s;
  white-space: nowrap;
}

.copy-btn:hover {
  border-color: var(--fg);
  color: var(--fg);
}

/* ─── CODE BLOCKS ────────────────────────────────────── */
.code-block {
  background: #1c1c1e;
  border-radius: var(--radius);
  overflow: hidden;
  margin: 16px 0;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.code-lang {
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  font-weight: 500;
  font-family: var(--font-mono);
}

.code-copy {
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  background: transparent;
  font-family: var(--font);
  transition: all 0.15s;
}

.code-copy:hover {
  color: #fff;
  border-color: rgba(255,255,255,0.4);
}

.code-block pre {
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  color: #f8f8f2;
  overflow-x: auto;
  white-space: pre;
}

/* ─── BADGE ──────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.badge-dev {
  background: #000;
  color: #fff;
}

.badge-green {
  background: rgba(52,199,89,0.12);
  color: #1a9e44;
}

.badge-gray {
  background: var(--gray-2);
  color: var(--gray-4);
}

/* ─── TOGGLE ─────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--gray-2);
}

.toggle-row:last-child {
  border-bottom: none;
}

.toggle-info h4 {
  font-size: 15px;
  font-weight: 500;
}

.toggle-info p {
  font-size: 13px;
  color: var(--gray-3);
  margin-top: 2px;
}

.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--gray-2);
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.2s;
}

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

.toggle input:checked + .toggle-slider {
  background: var(--fg);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* ─── AUTHORIZE VIEW ─────────────────────────────────── */
#view-authorize {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 40px 24px;
  background: var(--gray-1);
}

.authorize-card {
  background: var(--bg);
  border-radius: 20px;
  padding: 40px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.authorize-icons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 24px;
}

.authorize-app-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--gray-1);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  object-fit: cover;
}

.authorize-candylog-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--fg);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
}

.authorize-arrow {
  color: var(--gray-3);
  font-size: 20px;
}

.authorize-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 8px;
}

.authorize-sub {
  font-size: 14px;
  color: var(--gray-3);
  margin-bottom: 24px;
  line-height: 1.5;
}

.scopes-list {
  text-align: left;
  background: var(--gray-1);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 24px;
}

.scope-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  padding: 5px 0;
  color: var(--gray-4);
}

.scope-item::before {
  content: '✓';
  color: var(--success);
  font-weight: 700;
  font-size: 13px;
}

.authorize-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ─── MODAL ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal {
  background: var(--bg);
  border-radius: 20px;
  padding: 32px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.modal-actions .btn {
  flex: 1;
}

/* ─── ALERT ──────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
}

.alert-error {
  background: rgba(255,59,48,0.08);
  color: var(--danger);
  border: 1px solid rgba(255,59,48,0.2);
}

.alert-success {
  background: rgba(52,199,89,0.08);
  color: #1a9e44;
  border: 1px solid rgba(52,199,89,0.2);
}

/* ─── DOC TABS ───────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
}

.tab.active {
  color: var(--fg);
  border-bottom-color: var(--fg);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ─── AVATAR UPLOAD ──────────────────────────────────── */
.avatar-upload {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.avatar-upload-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--gray-2);
  border: 2px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-3);
}

.avatar-upload-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ─── EMPTY STATE ────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-3);
}

.empty-state h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 20px;
}

/* ─── SPINNER ────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

/* ─── RESPONSIVE ─────────────────────────────────────── */
@media (max-width: 600px) {
  #navbar { padding: 0 16px; }
  .page-content { padding: 80px 16px 48px; }
  .landing-logo { font-size: 36px; }
  .landing-tagline { font-size: 18px; }
  .authorize-card { padding: 28px 20px; }
  .modal { padding: 24px 20px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ─── SYNTAX HIGHLIGHT ───────────────────────────────── */
.kw { color: #ff79c6; }
.str { color: #f1fa8c; }
.fn { color: #50fa7b; }
.cm { color: #6272a4; }
.num { color: #bd93f9; }
.var { color: #8be9fd; }
