/* ---------------------------------------------------------------------- */
/* Design tokens                                                          */
/* ---------------------------------------------------------------------- */
:root {
  --bg: #0a0b0f;
  --bg-elevated: #101218;
  --sidebar-bg: #0c0d12;
  --panel: #14161d;
  --panel-hover: #181b23;
  --border: #23262f;
  --border-strong: #2f333e;

  --text: #eceef1;
  --text-dim: #aab0bd;
  --muted: #7d8492;
  --subtle: #565c68;

  --accent: #6f6bf2;
  --accent-hover: #7f7bff;
  --accent-dim: rgba(111, 107, 242, 0.14);
  --accent-text: #b9b7ff;

  --good: #2fbf71;
  --good-bg: rgba(47, 191, 113, 0.14);
  --bad: #f0546b;
  --bad-bg: rgba(240, 84, 107, 0.14);
  --warn: #e8a53d;
  --warn-bg: rgba(232, 165, 61, 0.14);

  --radius-sm: 7px;
  --radius: 11px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.38);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  --sidebar-width: 232px;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  background:
    radial-gradient(1100px 500px at 12% -10%, rgba(111, 107, 242, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  margin: 0;
  line-height: 1.55;
  font-size: 14.5px;
}

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }
h2 { font-size: 1.375rem; font-weight: 650; margin: 0 0 1.1rem; }
h3 { font-size: 1.05rem; font-weight: 600; margin: 0 0 0.75rem; }

a { color: var(--accent-text); }

code {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.85em;
}

/* ---------------------------------------------------------------------- */
/* App shell: sidebar + main                                              */
/* ---------------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.9rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.6rem 1.4rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}
.sidebar-brand .brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #b06bf2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.sidebar-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--subtle);
  padding: 0.9rem 0.7rem 0.35rem;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: var(--panel-hover); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent-text); }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
  margin-top: 0.5rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius-sm);
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  background: var(--panel-hover);
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-dim);
  flex-shrink: 0;
  text-transform: uppercase;
}
.user-meta { min-width: 0; flex: 1; }
.user-email {
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role { font-size: 0.68rem; color: var(--subtle); text-transform: capitalize; }

.logout-form { margin: 0.5rem 0 0; }
.logout-form button {
  width: 100%;
  margin-top: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.82rem;
  padding: 0.45rem 0.7rem;
}
.logout-form button:hover { background: var(--panel-hover); color: var(--text); border-color: var(--border-strong); }

.main { flex: 1; min-width: 0; }

.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 2.25rem 2rem 4rem;
}

.bare-nav {
  display: flex;
  align-items: center;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
}

@media (max-width: 640px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; align-items: center; padding: 0.7rem 1rem; overflow-x: auto; }
  .sidebar-brand { padding: 0 1rem 0 0; }
  .sidebar-nav { flex-direction: row; }
  .sidebar-section-label { display: none; }
  .sidebar-footer { border-top: none; border-left: 1px solid var(--border); margin: 0 0 0 0.5rem; padding: 0 0 0 0.75rem; }
  .user-email { max-width: 120px; }
  .container { padding: 1.5rem 1.1rem 3rem; }
}

/* ---------------------------------------------------------------------- */
/* Primitives                                                             */
/* ---------------------------------------------------------------------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow-sm);
}

.grid { display: grid; gap: 1.1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.row { display: flex; align-items: center; gap: 0.75rem; }
.row button, .row .btn, .row form { margin-top: 0; }
.row-wrap { flex-wrap: wrap; }
.row-end { align-items: flex-end; }
.space-between { justify-content: space-between; }

/* Stat cards (dashboards) */
.stat-card .stat-label { font-size: 0.8rem; color: var(--muted); margin: 0 0 0.4rem; }
.stat-card .stat-value { font-size: 2.1rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.stat-card a, .stat-card form { margin-top: 0.65rem; display: inline-block; }

label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.3rem; margin-top: 0.85rem; font-weight: 500; }
label:first-child { margin-top: 0; }

input, select, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 120ms var(--ease), box-shadow 120ms var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--subtle); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
input[type="file"] { padding: 0.45rem; font-size: 0.85rem; color: var(--text-dim); }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--accent);
  color: white;
  border: 1px solid transparent;
  padding: 0.55rem 1.05rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.87rem;
  font-weight: 600;
  text-decoration: none;
  margin-top: 0.85rem;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease), transform 80ms var(--ease), opacity 120ms var(--ease);
}
button:hover, .btn:hover { background: var(--accent-hover); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; }

button.secondary, .btn.secondary {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
}
button.secondary:hover, .btn.secondary:hover { background: var(--panel-hover); border-color: var(--subtle); }

button.danger, .btn.danger { background: var(--bad); }
button.danger:hover, .btn.danger:hover { background: #f76a7e; }

button.ghost, .btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); padding-left: 0.4rem; padding-right: 0.4rem; }
button.ghost:hover, .btn.ghost:hover { color: var(--text); background: var(--panel-hover); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--border); font-size: 0.87rem; }
th { color: var(--subtle); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr { transition: background-color 100ms var(--ease); }
tbody tr:hover { background: var(--panel-hover); }
tbody tr:last-child td { border-bottom: none; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.65rem;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--border);
  color: var(--text-dim);
  white-space: nowrap;
}
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

.muted { color: var(--muted); }
.subtle { color: var(--subtle); }
.error { color: var(--bad); margin-top: 0.5rem; }

.flash { padding: 0.7rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.1rem; font-size: 0.87rem; }
.flash.error { background: var(--bad-bg); border: 1px solid rgba(240, 84, 107, 0.35); color: #ffb3bf; }

.diff-add { background: var(--good-bg); color: var(--good); padding: 0.1rem 0.4rem; border-radius: 4px; }
.diff-del { background: var(--bad-bg); color: var(--bad); text-decoration: line-through; padding: 0.1rem 0.4rem; border-radius: 4px; }

.divider { height: 1px; background: var(--border); border: none; margin: 1.1rem 0; }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

.center-card { max-width: 400px; margin: 4rem auto 0; }
.center-card h2 { text-align: center; }
.mt-1 { margin-top: 1rem; }
.flex-1 { flex: 1; min-width: 160px; }
.link-plain { color: inherit; text-decoration: none; }
.link-plain:hover { color: var(--accent-text); }

.listing-card { transition: border-color 120ms var(--ease), transform 120ms var(--ease); }
.listing-card:hover { border-color: var(--border-strong); }
.listing-title { font-size: 1rem; font-weight: 650; margin: 0 0 0.15rem; }
.listing-meta { color: var(--muted); font-size: 0.85rem; margin: 0 0 0.75rem; }
.listing-badges { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.9rem; }
.match-score {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--good);
  white-space: nowrap;
}

.detail-table { margin-bottom: 1.1rem; }
.detail-table th { width: 150px; text-transform: none; font-size: 0.82rem; color: var(--muted); }
.pre-wrap { white-space: pre-wrap; color: var(--text-dim); line-height: 1.65; }
.inline-block { display: inline-block; }
.mt-lg { margin-top: 1.5rem; }
.surface-inset { background: var(--bg-elevated); border-color: var(--border); }
.tag-list { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.4rem 0 0; }

.diff-text { line-height: 1.7; }
.diff-line { white-space: pre-wrap; }
.change-block {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  margin: 0.6rem 0;
  background: rgba(111, 107, 242, 0.04);
}
.change-block-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-text);
  cursor: pointer;
}
.change-block-toggle input { width: auto; margin: 0; }
.change-block:has(input:not(:checked)) { background: transparent; opacity: 0.6; }
.change-block:has(input:not(:checked)) .change-block-toggle { color: var(--muted); }

::selection { background: var(--accent-dim); color: var(--text); }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.htmx-request.htmx-indicator { display: inline; }
