:root {
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --card: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: #eef2ff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --success: #16a34a;
  --error: #dc2626;
  --warning: #d97706;
  --input-bg: #ffffff;
  --sidebar: #ffffff;
  --sidebar-width: 248px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 14px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --ease: 160ms ease;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

button,
input,
textarea,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: var(--space-5) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  z-index: 40;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-2);
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--accent), #818cf8);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: -0.02em;
}

.brand-text {
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.nav-section {
  display: grid;
  gap: var(--space-1);
}

.nav-label {
  margin: 0 0 var(--space-2);
  padding: 0 var(--space-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #94a3b8;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition:
    background var(--ease),
    color var(--ease);
}

.nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-link:hover {
  background: #f1f5f9;
  color: var(--ink);
}

.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-link.active svg {
  opacity: 1;
}

.sidebar-footer {
  margin-top: auto;
  padding: var(--space-3);
  border-top: 1px solid var(--border);
}

.token-bar {
  display: grid;
  gap: var(--space-2);
  font-size: 12px;
  color: var(--muted);
}

.token-bar.hidden {
  display: none !important;
}

/* ── Main ────────────────────────────────────────────────── */
.main {
  min-width: 0;
  padding: var(--space-6) var(--space-6) 64px;
}

.page-header {
  margin-bottom: var(--space-5);
  max-width: 920px;
}

.page-header h1 {
  margin: 0 0 var(--space-2);
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--ink);
}

.page-header p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.content {
  max-width: 920px;
  display: grid;
  gap: var(--space-5);
}

.content-wide {
  max-width: 1100px;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.card-title {
  margin: 0 0 var(--space-4);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.card-head .card-title {
  margin: 0;
}

/* ── Forms ────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  gap: var(--space-4);
}

.field {
  display: grid;
  gap: var(--space-2);
}

.field label,
.field-label {
  font-size: 13px;
  font-weight: 550;
  color: #334155;
}

.field .hint,
.hint {
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--ink);
  font-size: 14px;
  transition:
    border-color var(--ease),
    box-shadow var(--ease);
}

.textarea {
  resize: vertical;
  min-height: 110px;
  line-height: 1.5;
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--border-strong);
}

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

.input-with-suffix {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.input-with-suffix .input {
  flex: 1;
}

.suffix {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
  gap: 2px;
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
  transition:
    background var(--ease),
    color var(--ease),
    box-shadow var(--ease);
}

.segmented label:has(input:checked) span {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.segmented label:hover span {
  color: var(--ink);
}

.preview-url {
  display: inline-block;
  margin-top: var(--space-2);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition:
    background var(--ease),
    border-color var(--ease),
    color var(--ease),
    box-shadow var(--ease);
}

.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

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

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

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

.btn-secondary:hover:not(:disabled) {
  background: #f8fafc;
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
  padding: 8px 10px;
  font-size: 13px;
}

.btn-ghost:hover:not(:disabled) {
  background: #f1f5f9;
  color: var(--ink);
}

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

.btn-danger:hover:not(:disabled) {
  background: #fef2f2;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.btn-row-top {
  margin-top: var(--space-4);
}

/* ── Lists / tables ───────────────────────────────────────── */
.list {
  display: grid;
  gap: var(--space-3);
}

.link-item {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  transition: border-color var(--ease);
}

.link-item:hover {
  border-color: var(--border-strong);
}

.link-item a.short {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  word-break: break-all;
}

.link-item a.short:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 12px;
  color: var(--muted);
}

.dest {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.post-quote {
  font-size: 14px;
  font-weight: 550;
  color: var(--ink);
  line-height: 1.45;
  word-break: break-word;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.actions .btn {
  text-decoration: none;
}

/* ── AI two-column ────────────────────────────────────────── */
.ai-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  align-items: start;
}

.preview-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: var(--space-3);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.post-preview {
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  color: var(--ink);
  min-height: 180px;
}

.post-preview.empty {
  color: var(--muted);
  display: grid;
  place-items: center;
  text-align: center;
}

.field-stack {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

/* ── Stats / chips ────────────────────────────────────────── */
.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.stat {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  min-width: 110px;
}

.stat-value {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  font-size: 13px;
}

.tag-chip.disabled {
  opacity: 0.55;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.tag-row.disabled {
  opacity: 0.55;
}

/* ── Empty / status ───────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  color: var(--ink);
  font-size: 15px;
  margin-bottom: 6px;
}

.error {
  color: var(--error);
  font-size: 13px;
  margin: var(--space-3) 0 0;
}

.success {
  color: var(--success);
  font-size: 13px;
  margin: var(--space-3) 0 0;
}

.status {
  color: var(--muted);
  font-size: 13px;
  margin: var(--space-3) 0 0;
}

.hidden,
[hidden] {
  display: none !important;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: toast-in 180ms ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Mobile top bar */
.mobile-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--ink);
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 960px) {
  .ai-grid {
    grid-template-columns: 1fr;
  }
}

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

  .mobile-bar {
    display: flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
    z-index: 35;
  }

  .sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }

  .main {
    padding: var(--space-5) var(--space-4) 48px;
  }

  .page-header h1 {
    font-size: 24px;
  }

  .segmented {
    width: 100%;
  }

  .segmented label {
    flex: 1;
  }

  .segmented span {
    width: 100%;
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
