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

:root {
  --clr-bg: #f4f5f7;
  --clr-surface: #ffffff;
  --clr-primary: #181c3b;
  --clr-accent: #4e6cf2;
  --clr-accent-fg: #ffffff;
  --clr-text: #1e1e2e;
  --clr-text-dim: #6b7280;
  --clr-border: #e2e5ea;
  /* The sandbox's code face, named once: eight rules across four sheets
     were spelling this stack out in full. */
  --font-mono: 'SF Mono', 'Fira Code', monospace;
  --header-h: 56px;
  --side-w: 260px;
  --radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --transition: 0.2s ease;
}

html {
  height: 100%;
}

body {
  height: 100%;
  font-family:
    Inter,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Roboto,
    sans-serif;
  color: var(--clr-text);
  background: var(--clr-bg);
  display: flex;
  flex-direction: column;
}

/* ── Header ───────────────────────────────────────── */
header {
  height: var(--header-h);
  background: var(--clr-primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  box-shadow: var(--shadow-md);
  z-index: 10;
  flex-shrink: 0;
}

header .logo {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

header .logo span {
  color: var(--clr-accent);
}

header nav {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

header nav a {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition:
    background var(--transition),
    border-color var(--transition),
    transform var(--transition);
}

header nav a:hover {
  background: var(--clr-accent);
  border-color: var(--clr-accent);
}

header nav .nav-cta {
  background: var(--clr-accent);
  border-color: var(--clr-accent);
  font-weight: 600;
  box-shadow: 0 0 0 2px rgba(78, 108, 242, 0.25);
}

header nav .nav-cta:hover {
  background: #3d59d9;
  border-color: #3d59d9;
  transform: translateY(-1px);
}

/* ── Layout beneath header ────────────────────────── */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Side pane ────────────────────────────────────── */
aside {
  width: var(--side-w);
  background: var(--clr-surface);
  border-right: 1px solid var(--clr-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

aside h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--clr-text-dim);
  padding: 20px 20px 8px;
}

aside ul {
  list-style: none;
  padding: 0 8px;
}

aside li button {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--clr-text);
  cursor: pointer;
  transition: background var(--transition);
  display: flex;
  align-items: center;
  gap: 10px;
}

aside li button:hover {
  background: var(--clr-bg);
}

aside li button.selected {
  background: rgba(78, 108, 242, 0.1);
  color: var(--clr-accent);
  font-weight: 600;
}

aside li button .icon {
  width: 20px;
  text-align: center;
  font-size: 16px;
  flex-shrink: 0;
}

aside .side-footer {
  margin-top: auto;
  padding: 16px 20px;
  font-size: 12px;
  color: var(--clr-text-dim);
  border-top: 1px solid var(--clr-border);
}

/* ── Main content ─────────────────────────────────── */
main {
  flex: 1;
  overflow: hidden;
  padding: 0;
  /* Ground for `#page-loading`, which floats over the outgoing page. */
  position: relative;
}

#main-content {
  width: 100%;
  height: 100%;
  overflow-y: auto;
}

.card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: var(--shadow-sm);
  margin: 32px 40px;
}

/* A card that *is* the page: fills the viewport below the header and
   scrolls its own content. Partials that fill `#main-content` use it
   instead of restating the height budget. */
.page-card {
  margin: 0.5rem;
  height: calc(100vh - var(--header-h) - 1rem);
  overflow-y: auto;
}

/* Button that reads as a link — the affordance for `gotoDbItem`, so it
   lives beside the function rather than in each calling partial. */
.db-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--clr-accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.card h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.card p {
  color: var(--clr-text-dim);
  line-height: 1.6;
  margin-bottom: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background var(--transition),
    transform var(--transition);
}

.btn-primary {
  background: var(--clr-accent);
  color: var(--clr-accent-fg);
}

.btn-primary:hover {
  background: #3d59d9;
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--clr-accent);
  border: 1px solid var(--clr-accent);
}

.btn-outline:hover {
  background: rgba(78, 108, 242, 0.08);
}

.btn-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ── Spinner ──────────────────────────────────────── */
/* One ring for the sandbox. The shell's page pill and the deck page's stage
   note are the same affordance, and this is the only sheet both can see —
   `deck-render.css` unmounts with its page, so a spinner defined there could
   never be reached from here. Consumers own `display` (the pill is hidden
   until htmx raises it) and the ring's size, via `--spin-size`. */
.spin {
  align-items: center;
  gap: 10px;
  color: var(--clr-text-dim);
}
.spin::before {
  content: '';
  flex: 0 0 auto;
  width: var(--spin-size, 16px);
  height: var(--spin-size, 16px);
  border: 2px solid var(--clr-border);
  border-top-color: var(--clr-accent);
  border-radius: 50%;
  animation: spin-turn 0.7s linear infinite;
}
@keyframes spin-turn {
  to {
    transform: rotate(1turn);
  }
}
@media (prefers-reduced-motion: reduce) {
  .spin::before {
    animation: spin-pulse 1.2s ease-in-out infinite;
  }
  @keyframes spin-pulse {
    50% {
      opacity: 0.25;
    }
  }
}

/* ── htmx loading indicator ───────────────────────── */
/* The generic contract, nothing more: hidden until htmx marks a request in
   flight, either on an ancestor (the requesting element) or on this element
   itself (an `hx-indicator` target). Appearance belongs to the indicator. */
.htmx-indicator {
  display: none;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-flex;
}

/* The page indicator: one element for every swap into `#main-content`,
   whether the shell's own landing fetch or a nav click. A pill rather than a
   bar across the pane, because a nav click keeps the outgoing page on screen
   until its replacement lands — the page is not gone, it is busy, and the
   pill says so without hiding what is still there. Centred, so on a cold
   start it sits in the middle of an empty pane. */
#page-loading {
  --spin-size: 14px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  padding: 10px 18px;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 13px;
}

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 768px) {
  aside {
    display: none;
  }
  .card {
    margin: 20px 16px;
  }
}
