/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0f0f11;
  --bg2:          #17171a;
  --bg3:          #1e1e22;
  --border:       #2a2a30;
  --border2:      #38383f;
  --text:         #e8e8ec;
  --text2:        #9898a8;
  --text3:        #5c5c6e;
  --accent:       #6c63ff;
  --accent-hover: #7d75ff;
  --accent-dim:   rgba(108,99,255,.15);
  --success:      #22c55e;
  --danger:       #ef4444;
  --warn:         #f59e0b;
  --radius:       8px;
  --radius-lg:    12px;
  --shadow:       0 4px 24px rgba(0,0,0,.4);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
}

html { font-size: 15px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  min-height: 100dvh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── Typography ──────────────────────────────────────────────────────────── */
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p  { color: var(--text2); }

.text-sm   { font-size: .825rem; }
.text-xs   { font-size: .75rem; }
.text-muted { color: var(--text2); }
.text-mono  { font-family: var(--mono); }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100dvh;
}

.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 0 1.25rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: .75rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: .5rem;
}

.sidebar-logo span { font-size: 1.3rem; }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 .75rem; }

.nav-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .75rem;
  border-radius: var(--radius);
  color: var(--text2);
  font-size: .9rem;
  cursor: pointer;
  transition: background .15s, color .15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  text-decoration: none;
}
.nav-link:hover { background: var(--bg3); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-dim); color: var(--accent); }
.nav-link .nav-icon { font-size: 1rem; width: 1.1rem; text-align: center; }

.sidebar-footer { padding: .75rem; border-top: 1px solid var(--border); margin-top: auto; }
.user-pill {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .4rem .5rem;
  border-radius: var(--radius);
  font-size: .825rem;
  color: var(--text2);
}
.user-pill strong { color: var(--text); font-size: .85rem; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 2rem; height: 2rem;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: .8rem;
  flex-shrink: 0;
}

.main-content {
  padding: 2rem 2.5rem;
  min-width: 0;
  overflow-x: hidden;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}
.page-header h1 { margin: 0; }

/* ── Auth pages ──────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--bg);
}

.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-card h1 { font-size: 1.4rem; margin-bottom: .25rem; }
.auth-card p  { margin-bottom: 1.5rem; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.form-group label { font-size: .85rem; font-weight: 500; color: var(--text2); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
select,
textarea {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  padding: .55rem .75rem;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
input::placeholder, textarea::placeholder { color: var(--text3); }
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--bg2); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: .9rem;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s, transform .1s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

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

.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border2); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-danger    { background: rgba(239,68,68,.15); color: var(--danger); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,.25); }

.btn-success   { background: rgba(34,197,94,.15); color: var(--success); border: 1px solid rgba(34,197,94,.3); }
.btn-success:hover:not(:disabled) { background: rgba(34,197,94,.25); }

.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-full { width: 100%; }
.btn-icon { padding: .45rem; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}
.card-sm { padding: 1rem 1.25rem; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.project-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.project-card:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-dim); }
.project-card h3 { font-size: 1rem; color: var(--text); }
.project-card .slug { font-family: var(--mono); font-size: .75rem; color: var(--text3); }
.project-card .meta { font-size: .78rem; color: var(--text3); margin-top: auto; }

/* ── Stat tiles ──────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.stat-tile {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem;
}
.stat-tile .label { font-size: .75rem; color: var(--text3); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .25rem; }
.stat-tile .value { font-size: 1.6rem; font-weight: 700; color: var(--text); line-height: 1; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead tr { background: var(--bg3); }
th {
  text-align: left;
  padding: .65rem 1rem;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text3);
  font-weight: 600;
  white-space: nowrap;
}
td {
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  color: var(--text2);
  vertical-align: middle;
}
tbody tr:hover { background: var(--bg3); }
td strong { color: var(--text); }
td .mono { font-family: var(--mono); font-size: .8rem; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .55rem;
  border-radius: 100px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-green  { background: rgba(34,197,94,.12); color: var(--success); }
.badge-red    { background: rgba(239,68,68,.12); color: var(--danger); }
.badge-yellow { background: rgba(245,158,11,.12); color: var(--warn); }
.badge-blue   { background: rgba(108,99,255,.15); color: var(--accent); }
.badge-gray   { background: var(--bg3); color: var(--text3); }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs-bar {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
  overflow-x: auto;
  padding-bottom: 0;
}
.tab-btn {
  padding: .6rem 1rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text2);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 1rem;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
  animation: modal-in .2s ease;
}
.modal-wide { max-width: 640px; }
@keyframes modal-in {
  from { opacity: 0; transform: scale(.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1)  translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem;
}
.modal-header h2 { margin: 0; }
.modal-close { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 1.2rem; padding: .2rem; }
.modal-close:hover { color: var(--text); }
.modal-footer { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }

/* ── Toasts ──────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  z-index: 2000;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  max-width: 360px;
  box-shadow: var(--shadow);
  animation: toast-in .25s ease, toast-out .3s ease 2.7s forwards;
  pointer-events: all;
}
.toast-success { background: #14532d; border: 1px solid #166534; color: #86efac; }
.toast-error   { background: #450a0a; border: 1px solid #7f1d1d; color: #fca5a5; }
.toast-info    { background: var(--bg3); border: 1px solid var(--border2); color: var(--text); }
@keyframes toast-in  { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateX(20px); } }

/* ── Code block ──────────────────────────────────────────────────────────── */
.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--text2);
  overflow-x: auto;
  word-break: break-all;
}

/* ── Misc helpers ────────────────────────────────────────────────────────── */
.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: .4rem; }
.gap-2 { gap: .75rem; }
.gap-3 { gap: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.w-full { width: 100%; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.section-header h2 { margin: 0; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text3);
}
.empty-state p { margin: 0; }

.spinner {
  width: 1.25rem; height: 1.25rem;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-center {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 3rem;
}

.error-banner {
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  color: var(--danger);
  font-size: .875rem;
  margin-bottom: 1rem;
}

.success-banner {
  background: rgba(34,197,94,.1);
  border: 1px solid rgba(34,197,94,.3);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  color: var(--success);
  font-size: .875rem;
  margin-bottom: 1rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .85rem;
  color: var(--text3);
  margin-bottom: 1.25rem;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  text-decoration: none;
}
.back-link:hover { color: var(--text); text-decoration: none; }

.key-reveal {
  background: var(--bg);
  border: 1px solid var(--success);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: var(--mono);
  font-size: .85rem;
  color: var(--success);
  word-break: break-all;
  margin: .75rem 0;
}

.checkbox-group { display: flex; gap: .75rem; flex-wrap: wrap; }
.checkbox-label { display: flex; align-items: center; gap: .4rem; cursor: pointer; font-size: .875rem; color: var(--text2); }
.checkbox-label input[type="checkbox"] { width: auto; accent-color: var(--accent); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    padding: .5rem;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-logo { display: none; }
  .sidebar-nav { flex-direction: row; padding: 0; }
  .sidebar-footer { display: none; }
  .nav-link { padding: .4rem .6rem; font-size: .8rem; }
  .main-content { padding: 1rem; }
  .form-row { grid-template-columns: 1fr; }
}
