/*
 * Layout and margin polish layer (styling only). Loaded last.
 *
 * Why this exists: spacing was set separately in five stylesheets, so the header, the cards and the
 * page edge each used a different gutter (24px header, 4px page padding, 12px cards on tablet,
 * 338px side margins on the project picker). This layer defines ONE spacing scale and applies it
 * everywhere. It hides nothing and removes nothing: every panel, governance display and advanced
 * control keeps its markup, ids and behavior.
 *
 * The desktop Insights workspace is a fixed-aspect canvas (pixel-perfect-ui.css); it is only given
 * the shared frame gutter and calmer inner spacing, not re-laid-out.
 */

:root {
  --vi-gutter: clamp(16px, 2vw, 28px); /* page edge, header and content share this */
  --vi-gap: 16px;                      /* space between sibling cards */
  --vi-gap-sm: 8px;                    /* space between chips, buttons, controls */
  --vi-card-pad: 20px;                 /* inner padding of every card */
  --vi-content-max: 1560px;            /* readable max width on very wide screens */
}

/* ── Header: same left/right gutter as the content below it ── */
.vi-header {
  padding-inline: var(--vi-gutter);
  box-sizing: border-box;
}

/* ── Left rail (desktop/tablet): the last item (Settings) is never clipped. The rail scrolls if the
   window is too short, and items tighten on shorter windows so everything fits at 900px tall. ── */
@media (min-width: 821px) {
  html .vi-shell .vi-rail {
    box-sizing: border-box;
    height: 100dvh;
    max-height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
  }
  html .vi-shell .vi-rail::-webkit-scrollbar { display: none; }
  html .vi-shell .vi-rail-spacer { flex: 1 1 8px; min-height: 8px; max-height: 24px; }
}
@media (min-width: 821px) and (max-height: 1000px) {
  html .vi-shell .vi-rail { gap: 2px; }
  html .vi-shell .vi-rail-item { min-height: 48px; padding-block: 5px; gap: 3px; }
}
@media (min-width: 821px) and (max-height: 820px) {
  html .vi-shell .vi-rail-item { min-height: 42px; }
}

/* ── All non-Insights screens: one gutter, one gap, centered max width ── */
html:not([data-vi-active-screen="workspace"]) .vi-content {
  box-sizing: border-box;
  width: 100%;
  max-width: var(--vi-content-max);
  margin-inline: auto;
  padding: var(--vi-gutter);
  display: block;
}
html:not([data-vi-active-screen="workspace"]) .vi-screen--active {
  gap: var(--vi-gap);
}
html:not([data-vi-active-screen="workspace"]) .vi-screen--active > * + * {
  /* Stacked blocks get the shared gap even where a screen did not use grid/flex. */
  margin-top: 0;
}
html:not([data-vi-active-screen="workspace"]) .vi-screen--active:not([data-vi-screen="settings"]) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
}

/* ── Cards: equal padding, equal radius, equal rhythm inside ── */
.vi-screen .vi-settings-card,
.vi-screen .card,
.vi-screen section.panel {
  box-sizing: border-box;
  padding: var(--vi-card-pad);
  margin: 0;
}
.vi-screen .vi-settings-card > :first-child { margin-top: 0; }
.vi-screen .vi-settings-card > :last-child { margin-bottom: 0; }

/* Settings: two even columns with the shared gap in both directions. */
@media (min-width: 1000px) {
  [data-vi-screen="settings"].vi-screen--active {
    gap: var(--vi-gap);
    align-items: start;
  }
}

/* ── Project picker: sits inside the same gutter instead of floating with 338px side margins ── */
html:not([data-vi-active-screen="workspace"]) .project-picker {
  box-sizing: border-box;
  width: auto;
  max-width: var(--vi-content-max);
  margin: var(--vi-gutter) var(--vi-gutter) 0;
  padding: var(--vi-card-pad) calc(var(--vi-card-pad) + 4px);
}
@media (min-width: 1700px) {
  html:not([data-vi-active-screen="workspace"]) .project-picker {
    margin-inline: auto;
    width: min(calc(100% - 2 * var(--vi-gutter)), var(--vi-content-max));
  }
}
.vi-sign-in-options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vi-gap-sm) 12px;
}

/* ── Controls: one gap between buttons, chips and action rows ── */
.vi-screen .byok-form-actions,
.vi-screen .vi-actions,
.vi-screen .button-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vi-gap-sm);
}

/* ── Insights (desktop canvas): inner spacing only ── */
html[data-vi-active-screen="workspace"] .conversation-card {
  box-sizing: border-box;
}
html[data-vi-active-screen="workspace"] .vi-context-strip { gap: var(--vi-gap-sm); margin-bottom: var(--vi-gap-sm); }
html[data-vi-active-screen="workspace"] .vi-generate-row { margin-bottom: var(--vi-gap-sm); }
html[data-vi-active-screen="workspace"] .conversation-feed { margin-bottom: 12px; }
html[data-vi-active-screen="workspace"] .composer-footer { gap: var(--vi-gap-sm); }

/* ── Tablet and phone: same 16px gutter for header, picker, cards and tab bar clearance ── */
@media (max-width: 820px) {
  :root { --vi-gutter: 16px; --vi-card-pad: 16px; --vi-gap: 12px; }
  .vi-header { padding-inline: var(--vi-gutter); }
  html:not([data-vi-active-screen="workspace"]) .vi-content {
    padding: var(--vi-gutter);
    /* leave room for the bottom tab bar so the last card is never hidden behind it */
    padding-bottom: calc(var(--vi-gutter) + 76px + env(safe-area-inset-bottom, 0px));
  }
  html:not([data-vi-active-screen="workspace"]):not(#vi-x) .project-picker {
    margin: var(--vi-gutter) var(--vi-gutter) 0;
    padding: var(--vi-card-pad);
  }
}
@media (max-width: 600px) {
  .vi-sign-in-options .button { flex: 1 1 100%; justify-content: center; }
}
