:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e7e7e8;
  --border-strong: #d4d4d6;
  --text: #111113;
  --text-muted: #6b6b72;
  --text-faint: #9a9aa1;
  --accent: #111113;
  --accent-hover: #2a2a2e;
  --live: #16a34a;
  --dev: #f59e0b;
  --external: #6366f1;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(15,15,20,.04), 0 1px 3px rgba(15,15,20,.06);
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.875rem 1.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-link { display: flex; align-items: center; gap: 0.75rem; }
.brand-mark {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--text); border-radius: 50%;
  font-weight: 700; font-size: 13px;
  letter-spacing: -0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}
.logo-dot { margin: 0 1px; }
.brand-name { font-weight: 600; font-size: 15px; }
.brand-sub { color: var(--text-muted); font-size: 12px; }

.tabs {
  display: flex; gap: 0.25rem;
  margin-left: auto;
}
.tab {
  background: transparent;
  border: 1px solid transparent;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font: inherit; cursor: pointer;
  color: var(--text-muted);
  font-weight: 500;
}
.tab:hover { color: var(--text); background: #f3f3f5; }
.tab.active {
  color: var(--text);
  background: #f3f3f5;
  border-color: var(--border);
}

.user-area { display: flex; align-items: center; gap: 0.875rem; margin-left: 1.5rem; }
.user-name { font-size: 13px; color: var(--text-muted); }

.btn, .btn-ghost, .link-btn {
  font: inherit; cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}
.btn:hover { background: #f5f5f7; }
.btn-primary {
  background: var(--accent); color: white;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding: 0.4rem 0.7rem;
}
.btn-ghost:hover { color: var(--text); background: #f3f3f5; }
.btn-ghost.danger { color: var(--danger); }
.link-btn {
  background: none; border: none; padding: 0.25rem 0.5rem;
  color: var(--text-muted); cursor: pointer; text-decoration: underline;
}
.link-btn.danger { color: var(--danger); }

/* ---------- Hub main ---------- */
.hub-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 1.75rem 4rem;
}
.hero h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 0.25rem;
}
.hero-sub { color: var(--text-muted); margin: 0 0 1.5rem; }
.hero-actions {
  display: flex; gap: 0.75rem; align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.search {
  flex: 1; max-width: 420px;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface);
}
.search:focus { outline: 2px solid var(--text); outline-offset: -1px; }

/* ---------- Grid ---------- */
.grid { display: flex; flex-direction: column; gap: 2rem; }
.category {
  display: flex; flex-direction: column; gap: 0.75rem;
}
.category-header {
  display: flex; justify-content: space-between; align-items: baseline;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.category-header h2 {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0;
}
.category-count { color: var(--text-faint); font-size: 12px; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 0.75rem;
}
.tile {
  display: flex; gap: 0.875rem; align-items: flex-start;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s, transform .15s;
  cursor: pointer;
  position: relative;
}
.tile:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}
.tile.dragging { opacity: 0.5; }
.tile-icon {
  font-size: 26px;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: #f3f3f5;
  border-radius: 8px;
  flex-shrink: 0;
}
.tile-icon img { width: 26px; height: 26px; }
.tile-body { flex: 1; min-width: 0; }
.tile-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem;
}
.tile-name { font-weight: 600; font-size: 14px; }
.tile-desc { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; line-height: 1.4; }
.status {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.05em;
  display: inline-flex; align-items: center; gap: 4px;
  white-space: nowrap;
}
.status::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  display: inline-block;
}
.status.LIVE { color: var(--live); }
.status.LIVE::before { background: var(--live); }
.status.DEV { color: var(--dev); }
.status.DEV::before { background: var(--dev); }
.status.EXTERNAL { color: var(--external); }
.status.EXTERNAL::before { background: var(--external); }

.tile-edit {
  position: absolute; top: 8px; right: 8px;
  width: 26px; height: 26px;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-faint);
  border-radius: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.tile:hover .tile-edit { opacity: 1; }
.tile-edit:hover { background: #f3f3f5; color: var(--text); }

/* ---------- Login ---------- */
.auth-body {
  min-height: 100vh;
  display: grid; place-items: center;
  background: linear-gradient(180deg, #fafafa 0%, #f3f3f5 100%);
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2.5rem;
  width: 100%; max-width: 380px;
  box-shadow: 0 4px 20px rgba(0,0,0,.04);
}
.auth-logo {
  width: 56px; height: 56px;
  margin: 0 auto 1.25rem;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--text); border-radius: 50%;
  font-weight: 700; font-size: 16px;
  white-space: nowrap;
  letter-spacing: -0.02em;
}
.auth-title { text-align: center; margin: 0 0 .25rem; font-size: 22px; }
.auth-sub { text-align: center; color: var(--text-muted); margin: 0 0 1.5rem; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-form label, .settings-main label {
  display: flex; flex-direction: column; gap: 0.35rem;
  font-size: 12.5px; font-weight: 500; color: var(--text-muted);
}
.auth-form input, .settings-main input, .settings-main select, .modal input, .modal select {
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--text);
  background: var(--surface);
}
.auth-form input:focus, .settings-main input:focus, .modal input:focus {
  outline: 2px solid var(--text); outline-offset: -1px;
}
.auth-divider {
  display: flex; align-items: center; gap: 0.75rem;
  color: var(--text-faint);
  margin: 1.25rem 0;
  font-size: 12px;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.text-center { text-align: center; }
.alert {
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #78350f;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 13px;
}
.alert-error { background: #fee2e2; border-color: #fecaca; color: #991b1b; }

/* ---------- Settings ---------- */
.settings-main {
  max-width: 720px;
  margin: 2rem auto;
  padding: 0 1.75rem;
  display: flex; flex-direction: column; gap: 1.25rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.card h2 {
  margin: 0 0 0.75rem;
  font-size: 15px; font-weight: 600;
}
.list { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.list li {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 0.85rem;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
}
.list li button { margin-left: auto; }
code {
  background: #f3f3f5;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 12px;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(15,15,20,.4);
  display: grid; place-items: center;
  z-index: 100;
}
.modal-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.75rem;
  width: 100%; max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-card h3 { margin: 0 0 1.25rem; }
.modal-card form { display: flex; flex-direction: column; gap: 0.875rem; }
.modal-card label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 12.5px; color: var(--text-muted); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.875rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.75rem; }
.modal-actions .danger { margin-right: auto; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 0.75rem; padding: 0.75rem 1rem; }
  .tabs { width: 100%; order: 10; margin-left: 0; overflow-x: auto; }
  .user-area { margin-left: auto; }
  .hub-main { padding: 1.5rem 1rem 3rem; }
  .row { grid-template-columns: 1fr; }
}
