/* TRE SPA — shadcn-inspired design system.
   Pure CSS, no framework / no build step. Variables follow shadcn/ui's
   neutral palette so the visual language matches their reference. */

:root {
  /* shadcn neutral palette — light theme */
  --background:        hsl(0 0% 100%);
  --foreground:        hsl(240 10% 3.9%);
  --card:              hsl(0 0% 100%);
  --card-foreground:   hsl(240 10% 3.9%);
  --popover:           hsl(0 0% 100%);
  --popover-foreground:hsl(240 10% 3.9%);
  --primary:           hsl(240 5.9% 10%);
  --primary-foreground:hsl(0 0% 98%);
  --secondary:         hsl(240 4.8% 95.9%);
  --secondary-foreground: hsl(240 5.9% 10%);
  --muted:             hsl(240 4.8% 95.9%);
  --muted-foreground:  hsl(240 3.8% 46.1%);
  --accent:            hsl(240 4.8% 95.9%);
  --accent-foreground: hsl(240 5.9% 10%);
  --destructive:       hsl(0 84.2% 60.2%);
  --destructive-foreground: hsl(0 0% 98%);
  --border:            hsl(240 5.9% 90%);
  --input:             hsl(240 5.9% 90%);
  --ring:              hsl(240 5% 64.9%);
  --radius:            0.5rem;

  /* semantic states */
  --success: hsl(142 71% 45%);
  --success-bg: hsl(142 76% 95%);
  --warning: hsl(38 92% 50%);
  --warning-bg: hsl(48 100% 96%);
  --info:    hsl(217 91% 60%);
  --info-bg: hsl(214 100% 97%);

  --sidebar-bg: hsl(240 5.9% 10%);
  --sidebar-fg: hsl(0 0% 95%);
  --sidebar-muted: hsl(240 5% 60%);
  --sidebar-active-bg: hsl(240 5% 18%);
  --sidebar-active-fg: hsl(0 0% 100%);
  --sidebar-border: hsl(240 5% 18%);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--background);
  color: var(--foreground);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
code, pre, .mono {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.875em;
}
a { color: inherit; }

/* ─── App shell ───────────────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────── */
#sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 4px 10px 22px 10px;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 16px;
}
.brand-mark {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: white;
}
.brand-sub {
  font-size: 11px;
  color: var(--sidebar-muted);
  margin-top: 2px;
  letter-spacing: 0.02em;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-section {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-muted);
  padding: 14px 10px 6px 10px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--sidebar-fg);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.1s ease;
}
.nav-item:hover { background: var(--sidebar-active-bg); }
.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-fg);
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--sidebar-border); }
.region-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 11px;
  color: var(--sidebar-muted);
  background: var(--sidebar-active-bg);
  border-radius: 999px;
}

/* ─── Layout column ───────────────────────────────────────────────────── */
.layout { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 5px; border: 1px solid var(--border);
  border-radius: 999px;
}
.user-avatar {
  width: 24px; height: 24px; border-radius: 999px;
  background: var(--primary); color: var(--primary-foreground);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
}
.user-logout {
  background: none; border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 6px;
  cursor: pointer; font-size: 12px; color: var(--muted-foreground);
}
.user-logout:hover { background: var(--accent); color: var(--foreground); }

main#main { padding: 28px; flex: 1; max-width: 1400px; width: 100%; }
.appfoot {
  padding: 14px 28px;
  font-size: 12px;
  color: var(--muted-foreground);
  border-top: 1px solid var(--border);
}
.appfoot a { color: var(--muted-foreground); text-decoration: none; }
.appfoot a:hover { color: var(--foreground); }

/* ─── Typography ──────────────────────────────────────────────────────── */
h2 {
  font-size: 22px; font-weight: 600; letter-spacing: -0.02em;
  margin: 0 0 18px 0;
}
h3 {
  font-size: 15px; font-weight: 600; letter-spacing: -0.01em;
  margin: 0 0 12px 0;
}
p { margin: 0 0 12px 0; }
.muted { color: var(--muted-foreground); }
.lead { color: var(--muted-foreground); font-size: 14px; margin-bottom: 20px; }

/* ─── Cards ───────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px 0 rgba(0,0,0,0.03);
}
.card > h3:first-child { margin-top: 0; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.col { min-width: 0; }

/* ─── Buttons ─────────────────────────────────────────────────────────── */
button, .btn {
  appearance: none;
  background: var(--primary);
  color: var(--primary-foreground);
  border: 0;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.1s ease, opacity 0.1s ease;
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
button:hover { background: hsl(240 5.9% 18%); }
button:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost, .btn.ghost {
  background: transparent; color: var(--foreground);
  border: 1px solid var(--border);
}
button.ghost:hover { background: var(--accent); }
button.destructive { background: var(--destructive); color: var(--destructive-foreground); }
button.destructive:hover { background: hsl(0 84.2% 50%); }
button.secondary { background: var(--secondary); color: var(--secondary-foreground); }
button.secondary:hover { background: hsl(240 4.8% 90%); }

/* ─── Form inputs ─────────────────────────────────────────────────────── */
input, select, textarea {
  background: var(--background);
  color: var(--foreground);
  border: 1px solid var(--input);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
  width: 100%;
  transition: border-color 0.1s, box-shadow 0.1s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px hsla(240 5% 64.9% / 0.2);
}
input[type=checkbox], input[type=radio] { width: auto; }
textarea { font-family: inherit; resize: vertical; min-height: 60px; }
form .field { margin-bottom: 14px; }
form label {
  display: block; font-size: 12.5px; font-weight: 500;
  color: var(--foreground); margin-bottom: 6px;
}

/* ─── Tables ──────────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:hover { background: hsl(240 4.8% 98%); }
tbody tr:last-child td { border-bottom: 0; }
td.right, th.right { text-align: right; }
td code, .mono { font-size: 12px; background: var(--muted); padding: 2px 6px; border-radius: 4px; }

/* ─── Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  background: var(--secondary);
  color: var(--secondary-foreground);
  border: 1px solid var(--border);
}
.badge.good { background: var(--success-bg); color: hsl(142 71% 28%); border-color: hsl(142 50% 80%); }
.badge.warn { background: var(--warning-bg); color: hsl(38 92% 32%); border-color: hsl(38 80% 80%); }
.badge.bad  { background: hsl(0 100% 97%); color: hsl(0 84.2% 45%); border-color: hsl(0 84% 88%); }
.badge.dim  { background: var(--muted); color: var(--muted-foreground); border-color: var(--border); }
.badge.info { background: var(--info-bg); color: hsl(217 91% 40%); border-color: hsl(217 91% 85%); }

/* ─── Misc ────────────────────────────────────────────────────────────── */
.loading {
  color: var(--muted-foreground); padding: 28px;
  text-align: center; font-size: 13px;
}
.error {
  color: hsl(0 84.2% 45%);
  background: hsl(0 100% 97%);
  border: 1px solid hsl(0 84% 88%);
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 13px;
}
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; font-size: 13px; }
.kv .k { color: var(--muted-foreground); }
.flex { display: flex; gap: 12px; align-items: center; }
.spacer { flex: 1; }
.upload-status { margin-top: 10px; font-size: 12.5px; color: var(--muted-foreground); }
.upload-status.err { color: hsl(0 84.2% 45%); }
.right { text-align: right; }

pre {
  background: var(--muted);
  padding: 12px 14px;
  overflow-x: auto;
  border-radius: 6px;
  font-size: 12px;
}

/* ─── Environment / template tiles ────────────────────────────────────── */
.build-sticky {
  position: sticky; top: 56px; z-index: 8;
  background: var(--card); padding: 12px 0;
  border-bottom: 1px solid var(--border);
  margin: -8px 0 18px 0;
  display: flex; align-items: center; gap: 14px;
}
.env-cat { margin-bottom: 28px; }
.env-cat-title {
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted-foreground);
  margin: 20px 0 12px 0;
  display: flex; align-items: center; gap: 8px;
}
.env-cat-title::after {
  content: ""; flex: 1; border-bottom: 1px solid var(--border);
}
.env-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.env-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 16px 14px 16px;
  cursor: pointer;
  transition: all 0.12s ease;
  display: flex; flex-direction: column; gap: 8px;
  position: relative;
  box-shadow: 0 1px 2px 0 rgba(0,0,0,0.03);
}
.env-tile:hover {
  border-color: hsl(240 5.9% 70%);
  box-shadow: 0 4px 12px 0 rgba(0,0,0,0.06);
}
.env-tile.selected {
  border-color: var(--primary);
  background: hsl(240 4.8% 98%);
  box-shadow: 0 0 0 1px var(--primary), 0 4px 14px 0 rgba(0,0,0,0.08);
}
.env-tile-check {
  position: absolute; top: 14px; left: 14px;
  width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary);
}
.env-tile-icon { font-size: 32px; line-height: 1; margin-left: 22px; }
.env-tile-title { font-weight: 600; font-size: 14px; }
.env-tile-sub { font-size: 12px; color: var(--muted-foreground); }
.env-tile-apps {
  font-size: 11.5px; color: var(--muted-foreground);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.env-tile-gpu {
  position: absolute; top: 12px; right: 12px;
  background: var(--info-bg); color: hsl(217 91% 40%);
  padding: 2px 7px; border-radius: 4px;
  font-size: 10px; font-weight: 600;
  border: 1px solid hsl(217 91% 85%);
}

/* Subtle scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: hsl(240 5% 80%); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: hsl(240 5% 65%); }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  #sidebar {
    position: relative; height: auto;
    flex-direction: row; flex-wrap: wrap; padding: 12px;
  }
  .sidebar-brand { border: 0; padding-bottom: 0; margin: 0 16px 0 0; }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
  .nav-section { display: none; }
  main#main { padding: 18px; }
}
