/* Central responsive app shell (P0-6.2). Uses tokens.css. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-background);
  color: var(--color-text);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  line-height: 1.5;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  z-index: 100;
  padding: 0.75rem 1rem;
  min-height: 44px;
  min-width: 44px;
  background: var(--color-surface);
  color: var(--color-text);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-default);
  text-decoration: none;
  transform: translateY(-200%);
}

.skip-link:focus,
.skip-link:focus-visible {
  transform: translateY(0);
}

.app-shell {
  display: grid;
  gap: 1rem;
  width: 100%;
  max-width: var(--app-max-width);
  margin-inline: auto;
  padding: 1rem;
  min-width: 0;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-default);
  box-shadow: var(--shadow-default);
  min-width: 0;
}

.app-brand {
  margin: 0;
  min-width: 0;
  max-width: 100%;
  font-size: clamp(1.125rem, 2.5vw, 1.5rem);
  font-weight: 700;
  color: var(--color-text);
  overflow-wrap: anywhere;
}

.app-brand--logo {
  display: flex;
  align-items: center;
  /* Override .app-brand min-width:0 so SVG/img intrinsic size cannot
     collapse to a 0x0 flex item under cyclic max-* sizing. */
  min-width: auto;
  flex: 0 1 auto;
}

.app-brand-logo {
  display: block;
  /* Definite height breaks the flex/intrinsic auto x auto cycle that
     rendered loaded brand SVGs with a 0x0 bounding box. */
  height: 2.5rem;
  width: auto;
  max-width: min(100%, 12rem);
  max-height: 2.5rem;
  object-fit: contain;
  flex: 0 1 auto;
}

.app-sign-out {
  margin: 0;
}

.app-nav {
  min-width: 0;
}

.app-nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.app-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0.5rem 0.75rem;
  color: var(--color-text);
  text-decoration: none;
  border-radius: var(--radius-default);
  border: 1px solid transparent;
  overflow-wrap: anywhere;
}

.app-nav a[aria-current="page"] {
  background: var(--color-selection);
  border-color: var(--color-border);
  font-weight: 600;
}

.app-main {
  min-width: 0;
  padding: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-default);
  box-shadow: var(--shadow-default);
  overflow-wrap: anywhere;
}

.app-main :is(h1, h2, h3, p, label, a, button, input) {
  max-width: 100%;
}

.app-main h1 {
  margin-top: 0;
  font-size: clamp(1.35rem, 4vw, 1.85rem);
  overflow-wrap: anywhere;
}

.app-main form p {
  margin-block: 0.75rem;
}

.app-main label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--color-text-secondary);
}

.app-main input,
.app-main textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-field-border);
  border-radius: var(--radius-default);
  background: var(--color-field-background);
  color: var(--color-text);
}

.app-main textarea {
  min-height: 8rem;
  resize: vertical;
}

.app-main button,
.app-sign-out button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius-default);
  background: var(--color-primary);
  color: var(--color-surface);
  font: inherit;
  cursor: pointer;
}

.app-main button:hover,
.app-sign-out button:hover {
  background: var(--color-primary-hover);
}

.app-main a {
  color: var(--color-primary);
}

.app-main [role="alert"] {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-default);
  background: var(--color-danger-background);
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
}

a:focus,
button:focus,
input:focus,
textarea:focus,
.skip-link:focus,
.app-nav a:focus,
.app-sign-out button:focus {
  /* Double ring: surface gap then primary — readable on primary buttons and
     light surfaces. Native button outline is unreliable in Chromium headless. */
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--color-surface), 0 0 0 5px var(--color-primary);
}

@media (min-width: 768px) {
  .app-shell--authenticated {
    grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr);
    grid-template-areas:
      "header header"
      "nav main";
    align-items: start;
  }

  .app-shell--authenticated .app-header {
    grid-area: header;
  }

  .app-shell--authenticated .app-nav {
    grid-area: nav;
    padding: 0.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-default);
  }

  .app-shell--authenticated .app-main {
    grid-area: main;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    /* Use none — setting only transition-duration implies transition-property:all
       and can leave outline/box-shadow stuck at pre-focus computed values. */
    transition: none !important;
    scroll-behavior: auto !important;
  }

  .skip-link {
    transition: none;
  }
}
