/* base.css – Reset, Typografie, App-Shell-Layout (Sidebar, Topbar, Content),
   Breakpoints 1100 px (Icon-Rail) und 760 px (Drawer), Barrierefreiheit.
   Schriftschnitte nur 400/500/600, keine Versalien (einzige Uppercase-Regel
   steht in components.css). */

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-14);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

html {
  overflow-x: hidden;
}

body {
  overflow-x: hidden;
}

body.nav-open,
body.drawer-open {
  overflow: hidden;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 600;
  line-height: 1.3;
}

h1 {
  font-size: var(--fs-20);
}

h2 {
  font-size: var(--fs-16);
}

h3 {
  font-size: var(--fs-14);
}

p {
  margin: 0;
}

a {
  color: var(--accent);
}

a:hover {
  color: var(--accent-hover);
}

code,
kbd,
pre,
.mono {
  font-family: var(--mono);
  font-size: 0.92em;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-12);
}

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

img {
  max-width: 100%;
}

table {
  border-collapse: collapse;
}

.num,
.kpi-value,
.versand-stock-cell,
.nav-badge {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

[hidden] {
  display: none !important;
}

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

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.skip-link {
  position: absolute;
  top: -100px;
  left: var(--s-4);
  z-index: 100;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: var(--s-3);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

/* ── App-Shell ─────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
}

.app-shell.sidebar-collapsed {
  --sidebar-w: var(--sidebar-rail-w);
}

.app-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-3);
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 30;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-1) var(--s-2) var(--s-4);
  min-width: 0;
}

.sidebar .logo {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: var(--weight-semibold);
  font-size: var(--fs-16);
}

.sidebar .titles {
  min-width: 0;
}

.sidebar .titles h1 {
  font-size: var(--fs-16);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.sidebar .titles h1 span {
  color: var(--accent);
}

.sidebar .subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: var(--fs-12);
  white-space: nowrap;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-toggle {
  margin-top: auto;
  justify-content: flex-start;
  color: var(--muted);
}

/* Eingeklappt: Icon-Rail (64 px) */
.app-shell.sidebar-collapsed .sidebar {
  padding-left: var(--s-2);
  padding-right: var(--s-2);
}

.app-shell.sidebar-collapsed .sidebar-brand .titles,
.app-shell.sidebar-collapsed .nav-label,
.app-shell.sidebar-collapsed .sidebar-toggle .nav-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.app-shell.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.app-shell.sidebar-collapsed .nav-link,
.app-shell.sidebar-collapsed .sidebar-toggle {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.app-shell.sidebar-collapsed .nav-badge {
  position: absolute;
  top: 2px;
  right: 4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: var(--fs-12);
}

.app-shell.sidebar-collapsed .sidebar-toggle .nav-icon {
  transform: rotate(180deg);
}

.topbar-chip-short {
  display: none;
}

/* Topbar – eine Zeile; auf 375 px höchstens 64 px hoch (Status wird
   verkürzt, nie umgebrochen). */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar .right {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex: 0 0 auto;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  min-width: 0;
  flex: 1 1 auto;
}

.topbar-status-line {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
  font-size: var(--fs-13);
  color: var(--text);
}

.topbar-status-line .topbar-status-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-drawer-toggle {
  flex: 0 0 auto;
}

.toggle {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--muted);
  font-weight: var(--weight-medium);
  font-size: var(--fs-13);
  cursor: pointer;
}

.toggle input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  margin: 0;
}

/* Content */
.content {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-6);
  display: grid;
  gap: var(--space-content);
  min-width: 0;
}

.content:focus {
  outline: none;
  box-shadow: none;
}

.footer {
  text-align: center;
  color: var(--muted);
  padding: var(--s-6) 0 var(--s-8);
  font-size: var(--fs-12);
  margin-top: auto;
}

/* Debug-Banner (view-übergreifend) */
.debug-banner {
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--warn);
  background: var(--surface-2);
  color: var(--warn-text);
  border-radius: var(--r);
  padding: var(--s-3) var(--s-4);
  font-weight: var(--weight-medium);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

/* Overlay für Navigation (mobil) und Detail-Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(2, 6, 23, 0.55);
  opacity: 0;
  transition: opacity var(--motion);
}

.drawer-backdrop.is-open,
.nav-backdrop:not([hidden]) {
  opacity: 1;
}

/* ── Breakpoints ───────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .app-shell {
    --sidebar-w: var(--sidebar-rail-w);
  }

  .sidebar {
    padding-left: var(--s-2);
    padding-right: var(--s-2);
  }

  .sidebar-brand .titles,
  .nav-label,
  .sidebar-toggle .nav-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .sidebar-brand,
  .nav-link,
  .sidebar-toggle {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }

  .nav-badge {
    position: absolute;
    top: 2px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: var(--fs-12);
  }

  .sidebar-toggle {
    display: none;
  }

  .content {
    padding: var(--s-5);
    gap: var(--s-5);
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-shell,
  .app-shell.sidebar-collapsed {
    --sidebar-w: 240px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    max-width: 85vw;
    height: 100vh;
    padding: var(--s-4) var(--s-3);
    transform: translateX(-100%);
    transition: transform var(--motion);
    z-index: 50;
    box-shadow: var(--shadow-2);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-brand .titles,
  .nav-label,
  .sidebar-toggle .nav-label {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }

  .sidebar-brand,
  .nav-link {
    justify-content: flex-start;
    padding-left: var(--s-3);
    padding-right: var(--s-3);
  }

  .nav-badge {
    position: static;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: var(--fs-12);
  }

  .topbar {
    padding: var(--s-2) var(--s-3);
    gap: var(--s-2);
    max-height: 64px;
    overflow: hidden;
  }

  .topbar .right {
    gap: var(--s-2);
  }

  .topbar-status {
    flex-wrap: nowrap;
    overflow: hidden;
  }

  .topbar-status .cron-status {
    display: none;
  }

  .topbar-status .topbar-chip {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
  }

  .topbar-chip-short {
    display: inline;
  }

  .topbar-chip .topbar-chip-text {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar .toggle span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .content {
    padding: var(--s-3);
    gap: var(--s-4);
  }
}
