/**
 * base.css — Design tokens, reset, typography, grid
 * GPO-Prozesserhebungstool · Pro_ZSGPM_2026
 *
 * Token authority: Spec §9.3 (GL-003 not yet populated for this project)
 * Approach: mobile-first, CSS custom properties, no framework
 */

/* ─────────────────────────────────────────────
   1. Design Tokens
   ───────────────────────────────────────────── */

:root {
  /* Brand colours (spec §9.3) */
  --blue-deep:      #003B6F;
  --blue-mid:       #1A6FAD;
  --blue-light:     #E8F1F9;
  --green-confirm:  #1E7D4F;
  --amber-warn:     #B45309;
  --red-err:        #C0392B;
  --sand:           #F5F1EB;
  --grey-ui:        #6B7280;
  --white:          #FFFFFF;

  /* Derived surface tokens */
  --surface-bg:         #F4F6F9;   /* page background */
  --surface-card:       var(--white);
  --surface-chat-ai:    #EEF4FB;   /* AI bubble background */
  --surface-border:     #D1D9E3;

  /* Typography */
  --font-ui:      'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-prose:   'Lora', Georgia, 'Times New Roman', serif;
  --font-mono:    'JetBrains Mono', 'Consolas', monospace;

  /* Type scale (base 16px) */
  --text-display:  2rem;        /* 32px */
  --text-h1:       1.625rem;    /* 26px */
  --text-h2:       1.25rem;     /* 20px */
  --text-h3:       1.0625rem;   /* 17px */
  --text-body:     1rem;        /* 16px */
  --text-sm:       0.9375rem;   /* 15px */
  --text-caption:  0.875rem;    /* 14px */

  /* Spacing scale (base 4px) */
  --space-1:  0.25rem;   /* 4px */
  --space-2:  0.5rem;    /* 8px */
  --space-3:  0.75rem;   /* 12px */
  --space-4:  1rem;      /* 16px */
  --space-5:  1.25rem;   /* 20px */
  --space-6:  1.5rem;    /* 24px */
  --space-8:  2rem;      /* 32px */
  --space-10: 2.5rem;    /* 40px */
  --space-12: 3rem;      /* 48px */
  --space-16: 4rem;      /* 64px */

  /* Component tokens */
  --radius-card:   8px;
  --radius-btn:    6px;
  --radius-input:  4px;
  --radius-bubble: 12px;

  --shadow-card:   0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-modal:  0 8px 32px rgba(0, 0, 0, 0.18);
  --shadow-toast:  0 4px 16px rgba(0, 0, 0, 0.14);

  --transition-fast:   0.15s ease;
  --transition-medium: 0.25s ease;
  --transition-score:  0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);

  /* Focus ring */
  --focus-ring: 0 0 0 3px rgba(26, 111, 173, 0.45);

  /* Z-index layers */
  --z-sticky:  10;
  --z-drawer:  100;
  --z-modal:   200;
  --z-toast:   300;
  --z-tooltip: 400;
}

/* Reduced-motion override: collapse all transitions */
@media (prefers-reduced-motion: reduce) {
  :root {
    --transition-fast:   0ms;
    --transition-medium: 0ms;
    --transition-score:  0ms;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─────────────────────────────────────────────
   2. Reset
   ───────────────────────────────────────────── */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-ui);
  font-size: var(--text-body);
  line-height: 1.5;
  color: var(--blue-deep);
  background-color: var(--surface-bg);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

ul,
ol {
  list-style: none;
}

a {
  color: var(--blue-mid);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--blue-deep);
}

button {
  cursor: pointer;
  border: none;
  background: transparent;
}

/* ─────────────────────────────────────────────
   3. Focus Styles (WCAG 2.1 AA — visible everywhere)
   ───────────────────────────────────────────── */

:focus-visible {
  outline: 2px solid var(--blue-mid);
  outline-offset: 3px;
  border-radius: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ─────────────────────────────────────────────
   4. Typography Scale
   ───────────────────────────────────────────── */

h1 {
  font-size: var(--text-h1);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

h2 {
  font-size: var(--text-h2);
  font-weight: 600;
  line-height: 1.3;
}

h3 {
  font-size: var(--text-h3);
  font-weight: 500;
  line-height: 1.4;
}

p {
  line-height: 1.6;
}

/* Prose class: switches to Lora serif */
.prose,
.chat-ai .bubble-text {
  font-family: var(--font-prose);
  line-height: 1.7;
}

.caption,
.text-sm {
  font-size: var(--text-caption);
  color: var(--grey-ui);
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

/* ─────────────────────────────────────────────
   5. Layout Primitives
   ───────────────────────────────────────────── */

/* Outer wrapper: full-width fluid layout with moderate padding.
   The tool is content-dense (3-column editor, card grids) and benefits from
   the full viewport. A generous cap keeps line lengths sane on very wide
   screens without the old 1280px gutter waste. */
.container {
  width: 100%;
  max-width: 1600px;
  margin-inline: auto;
  padding-inline: var(--space-4);
}

@media (min-width: 640px) {
  .container {
    padding-inline: var(--space-6);
  }
}

@media (min-width: 1024px) {
  .container {
    padding-inline: var(--space-8);
  }
}

@media (min-width: 1440px) {
  .container {
    padding-inline: var(--space-10);
  }
}

/* Narrow reading-width variant for form-heavy / prose views
   (settings, task picker). Replaces the old inline max-width:800px. */
.container--narrow {
  max-width: 880px;
}

/* Stack: vertical flex with gap */
.stack {
  display: flex;
  flex-direction: column;
}

.stack--sm  { gap: var(--space-2); }
.stack--md  { gap: var(--space-4); }
.stack--lg  { gap: var(--space-6); }
.stack--xl  { gap: var(--space-8); }

/* Cluster: horizontal flex that wraps */
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.cluster--sm  { gap: var(--space-2); }
.cluster--md  { gap: var(--space-4); }

/* ─────────────────────────────────────────────
   6. Application Shell
   ───────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Three-zone application shell ──────────────────────────────────────────────
   The #app-nav header hosts the whole shell so it stays sticky as one unit.
   Zone 1: top bar (brand + global search + civitasai link + user)
   Zone 2: main nav (Bibliothek · Neue Erhebung · Überprüfung · Einstellungen)
   Zone 3: breadcrumb (per-view trail, hidden when empty)                       */

.app-nav {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background-color: var(--blue-deep);
  color: var(--white);
  display: block;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.shell {
  display: flex;
  flex-direction: column;
}

/* Zone 1 ─ Top bar */
.shell-topbar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
}

.shell-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--white);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.shell-brand:hover { color: var(--blue-light); }

.shell-brand__name { letter-spacing: -0.01em; }

/* Global search sits in the middle and grows */
.shell-search {
  position: relative;
  flex: 1 1 auto;
  max-width: 560px;
  margin-inline: auto;
}

.shell-search__icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--grey-ui);
  pointer-events: none;
  font-size: 1rem;
}

.shell-search__input {
  width: 100%;
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-10);
  border: 1px solid transparent;
  border-radius: var(--radius-btn);
  background-color: rgba(255, 255, 255, 0.14);
  color: var(--white);
  font-size: var(--text-caption);
  transition: background-color var(--transition-fast), box-shadow var(--transition-fast);
}

.shell-search__input::placeholder { color: rgba(255, 255, 255, 0.7); }

.shell-search__input:focus {
  outline: none;
  background-color: var(--white);
  color: var(--blue-deep);
  box-shadow: 0 0 0 3px rgba(232, 241, 249, 0.5);
}

.shell-search__input:focus::placeholder { color: var(--grey-ui); }

/* Search results dropdown */
.shell-search__results {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 0;
  right: 0;
  background-color: var(--white);
  color: var(--blue-deep);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-modal);
  max-height: 60vh;
  overflow-y: auto;
  padding: var(--space-2);
  z-index: var(--z-drawer);
}

.shell-search__group + .shell-search__group {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--surface-border);
}

.shell-search__group-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--grey-ui);
  padding: var(--space-1) var(--space-3);
}

.shell-search__hit {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--blue-deep);
  transition: background-color var(--transition-fast);
}

.shell-search__hit:hover,
.shell-search__hit.is-active {
  background-color: var(--blue-light);
}

.shell-search__hit-icon {
  flex-shrink: 0;
  color: var(--blue-mid);
  font-size: 1.05rem;
}

.shell-search__hit-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.shell-search__hit-label {
  font-size: var(--text-sm);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shell-search__hit-meta {
  font-size: var(--text-caption);
  color: var(--grey-ui);
}

.shell-search__empty {
  padding: var(--space-3);
  font-size: var(--text-sm);
  color: var(--grey-ui);
}

/* Top-bar right cluster */
.shell-topbar__right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.shell-back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-caption);
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-btn);
  border: 1px solid rgba(255, 255, 255, 0.25);
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.shell-back-link:hover {
  background-color: rgba(255, 255, 255, 0.12);
  color: var(--white);
}

.shell-user {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-caption);
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
}

.shell-user .ph { font-size: 1.15rem; }

.shell-logout {
  font-size: var(--text-caption);
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-btn);
  background: transparent;
  border: none;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.shell-logout:hover {
  background-color: rgba(255, 255, 255, 0.12);
  color: var(--white);
}

/* Zone 2 ─ Main navigation */
.shell-nav {
  display: flex;
  align-items: stretch;
  gap: var(--space-1);
  padding: 0 var(--space-4);
  background-color: rgba(0, 0, 0, 0.12);
  overflow-x: auto;
  scrollbar-width: none;
}

.shell-nav::-webkit-scrollbar { display: none; }

.shell-nav__link {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-caption);
  font-weight: 500;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: color var(--transition-fast), border-color var(--transition-fast), background-color var(--transition-fast);
}

.shell-nav__link:hover {
  color: var(--white);
  background-color: rgba(255, 255, 255, 0.08);
}

.shell-nav__link.is-active {
  color: var(--white);
  font-weight: 600;
  border-bottom-color: var(--white);
}

/* Zone 3 ─ Breadcrumb */
.shell-breadcrumb {
  background-color: var(--white);
  border-bottom: 1px solid var(--surface-border);
  padding: var(--space-2) var(--space-4);
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-caption);
}

.breadcrumb__item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
}

.breadcrumb__sep {
  color: var(--surface-border);
  margin-inline: var(--space-1);
}

.breadcrumb__link {
  color: var(--blue-mid);
  text-decoration: none;
  font-weight: 500;
}

.breadcrumb__link:hover {
  color: var(--blue-deep);
  text-decoration: underline;
}

.breadcrumb__current {
  color: var(--grey-ui);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 50vw;
}

/* Responsive: tighten the shell on small screens */
@media (max-width: 767px) {
  .shell-topbar {
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  .shell-brand__name { display: none; }
  .shell-search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
    margin: 0;
  }
  .shell-back-link span { display: none; }
  .shell-user__name { display: none; }
}

/* Main content area */
.app-main {
  flex: 1;
  padding-block: var(--space-6);
}

/* ─────────────────────────────────────────────
   7. Page Loading State
   ───────────────────────────────────────────── */

.page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  color: var(--grey-ui);
  font-size: var(--text-sm);
  gap: var(--space-2);
}

/* ─────────────────────────────────────────────
   8. Offline Banner
   ───────────────────────────────────────────── */

.offline-banner {
  background-color: var(--amber-warn);
  color: var(--white);
  text-align: center;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-caption);
  font-weight: 500;
  display: none;
}

.offline-banner.is-visible {
  display: block;
}

/* ─────────────────────────────────────────────
   9. Utility Classes
   ───────────────────────────────────────────── */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-right   { text-align: right; }
.text-center  { text-align: center; }

.font-semibold { font-weight: 600; }
.font-medium   { font-weight: 500; }

.color-muted   { color: var(--grey-ui); }
.color-success { color: var(--green-confirm); }
.color-warn    { color: var(--amber-warn); }
.color-err     { color: var(--red-err); }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.divider {
  border: none;
  border-top: 1px solid var(--surface-border);
  margin-block: var(--space-4);
}

/* ─────────────────────────────────────────────
   10. Scrollbar Styling (Chromium / WebKit)
   ───────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--surface-border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--grey-ui);
}
