/*
 * The whole product's styling, owned by the app layer. Modules ship markup and
 * lean on these classes; they do not ship stylesheets of their own, so that a
 * customer instance can restyle everything from one place.
 */

:root {
  --ink: #1c1e21;
  --ink-muted: #5f6672;
  --line: #dfe3e8;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --accent: #2f5d8a;
  --accent-ink: #ffffff;
  --danger: #a8322d;
  --radius: 6px;
  --gap: 1rem;
  --sidebar-width: 15rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;

  /* A fixed-width sidebar beside a fluid content column. The skip-link is
     positioned out of flow, so the grid sees only the sidebar and main. */
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

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

.skip-link {
  position: absolute;
  left: -9999px;
}
.skip-link:focus {
  left: 1rem;
  top: 0.5rem;
  background: var(--surface);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  z-index: 10;
}

.sidebar {
  /* Stays put while the content column scrolls. */
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;

  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.25rem 0.9rem;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.brand {
  font-weight: 650;
  font-size: 1.15rem;
  color: var(--ink);
  text-decoration: none;
  padding: 0.25rem 0.6rem;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius);
  color: var(--ink-muted);
  text-decoration: none;
}
.sidebar-nav a:hover {
  color: var(--ink);
  background: var(--bg);
}

/* Who is signed in, and the way out. Pushed to the foot of the sidebar so it
   sits apart from the navigation above it. */
.sidebar-account {
  margin-top: auto;
  display: grid;
  gap: 0.5rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}
.sidebar-user {
  padding: 0 0.6rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}
.sidebar-account form { margin: 0; }
.sidebar-account button { width: 100%; }

/* Inline SVG icon. Sized in em so it tracks the text it sits beside, and
   coloured by currentColor so it inherits link and hover states for free. */
.icon {
  width: 1.35em;
  height: 1.35em;
  flex: none;
}

main {
  padding: 1.5rem;
}
.content {
  max-width: 60rem;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 1.25rem;
}
.page-header h1 { margin: 0; font-size: 1.5rem; }

.breadcrumb { margin: 0 0 0.25rem; font-size: 0.875rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }

/* Buttons and links styled as buttons must look identical. */
button,
.button {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  line-height: 1.4;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
button:hover,
.button:hover { filter: brightness(1.08); }

.button.secondary,
button.secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.search {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.search input { flex: 1; }

/* An inline filter toggle sitting in a .search row, e.g. "show former staff".
   Opt the checkbox out of the full-width input sizing the row otherwise gives. */
.search .toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  font-size: 0.9rem;
  color: var(--ink-muted);
}
.search .toggle input {
  width: auto;
  flex: none;
}

input, textarea, select {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
}
textarea { resize: vertical; }

.form { display: grid; gap: var(--gap); }
.form label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}
.form label input,
.form label textarea { color: var(--ink); font-size: 1rem; }

/* A checkbox and its label read as one line, not a stacked field: lay the box
   beside its text and stop the global full-width input rule from stretching it. */
.form label.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
}
.form label.checkbox input {
  width: auto;
  flex: none;
}

.form .actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.table th, .table td {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); }
.table tr:last-child td { border-bottom: none; }

.fields {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1.25rem;
  margin: 0;
}
.fields dt { color: var(--ink-muted); font-size: 0.9rem; }
.fields dd { margin: 0; }

.note { margin: 1rem 0 0; white-space: pre-wrap; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.9rem; }
.timeline li { border-left: 2px solid var(--line); padding-left: 0.9rem; }
.timeline-meta { margin: 0; font-size: 0.85rem; }
.timeline-body { margin: 0.15rem 0 0; }

.section-actions { margin: 0 0 1rem; }

.muted { color: var(--ink-muted); }
.empty { color: var(--ink-muted); font-style: italic; }

/* Text only a screen reader needs — the name of a control whose meaning is
   carried visually, e.g. a disclosure arrow. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* A destructive action. Quiet in a row of controls, solid once it is the
   confirmation itself. */
button.danger,
.button.danger {
  background: var(--danger);
  color: #ffffff;
  border-color: transparent;
}
button.secondary.danger,
.button.secondary.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--line);
}
button.secondary.danger:hover,
.button.secondary.danger:hover { border-color: var(--danger); }

.error {
  background: #fdeceb;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  margin-bottom: var(--gap);
}

/* Permissions: a grant reads as a card of rules, each rule a short stack of
   the conditions that must hold, with its delete control alongside. */
.grant-list { list-style: none; margin: 0.5rem 0 0; padding: 0; display: grid; gap: 0.75rem; }
.grant-list > li {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  background: var(--bg);
}
.grant-note { margin: 0 0 0.4rem; font-weight: 600; }
.condition-list { margin: 0 0 0.5rem; padding-left: 1.1rem; }
.condition-list li { margin: 0.1rem 0; }
.grant-list form.inline { display: inline; }
.grant-actions { display: flex; gap: 0.5rem; align-items: center; }

/* The builder groups conditions under a heading; each condition is a checkbox
   with its parameter inputs indented beneath it. */
.form fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  display: grid;
  gap: 0.6rem;
}
.form fieldset legend { padding: 0 0.4rem; font-size: 0.9rem; color: var(--ink-muted); }
.condition-row { display: grid; gap: 0.3rem; }
.condition-row .condition-arg { margin-left: 1.6rem; }

/* An inline caution, e.g. a grant left behind by a removed feature. Unlike the
   block .error alert, this sits within a line. */
.flag-warn { color: var(--danger); font-size: 0.85rem; }

/* Organisation: the Einrichtung → Abteilung → Team tree, edited in place.
   The indentation and the hairline spine down each level are the structure
   itself, so the page needs no other decoration to be read at a glance. Weight
   falls off with depth for the same reason. */
.org-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.org-search {
  width: auto;
  flex: 1 1 12rem;
  max-width: 20rem;
}
.org-summary {
  margin: 0 auto 0 0;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.org-level {
  list-style: none;
  margin: 0;
  padding: 0;
}
.org-root {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
}
/* An empty list would otherwise leave a bare box above the empty state. */
.org-root:empty { display: none; }

/* Every level below the first hangs off a spine, with a tick reaching out to
   each of its rows. */
.org-level .org-level {
  margin-left: 0.7rem;
  padding-left: 1.15rem;
  border-left: 1px solid var(--line);
}
.org-level .org-level > .org-item > .org-row::before {
  content: "";
  position: absolute;
  left: -1.15rem;
  top: 1.05em;
  width: 0.8rem;
  height: 1px;
  background: var(--line);
}

.org-row {
  position: relative;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 2.2rem;
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius);
}
.org-row:hover { background: var(--bg); }

.org-name { color: var(--ink); }
.org-einrichtung > .org-row > .org-name { font-size: 1.05rem; font-weight: 600; }
.org-abteilung > .org-row > .org-name { font-weight: 500; }
.org-team > .org-row > .org-name { font-size: 0.95rem; }

.org-meta {
  font-size: 0.8rem;
  color: var(--ink-muted);
  white-space: nowrap;
}

/* The disclosure control, and the same width as a spacer on a row that has
   nothing to disclose, so every name on a level starts at one edge. */
.org-twisty {
  flex: none;
  width: 1.4rem;
  height: 1.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: none;
  color: var(--ink-muted);
  font-size: 0.85rem;
}
button.org-twisty:hover {
  background: var(--line);
  color: var(--ink);
  filter: none;
}

/* What can be done to a row. The labels stay readable — on a page visited a few
   times a year, controls that only exist on hover are controls nobody finds —
   but they carry no frame until the row is actually under the pointer or holds
   focus, so a long structure reads as names rather than as rows of buttons. */
.org-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.org-actions .button {
  padding: 0.2rem 0.6rem;
  font-size: 0.82rem;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.org-actions .button.secondary {
  background: none;
  border-color: transparent;
  color: var(--ink-muted);
}
.org-row:hover .org-actions .button.secondary,
.org-row:focus-within .org-actions .button.secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}
.org-actions .button.secondary.danger,
.org-row:hover .org-actions .button.secondary.danger,
.org-row:focus-within .org-actions .button.secondary.danger { color: var(--danger); }

/* Once it is the confirmation itself, the pair speaks up whether or not the
   pointer is still there. */
.org-confirm .button.secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}
.org-confirm-text {
  font-size: 0.85rem;
  color: var(--danger);
}

/* Renaming and adding both put an input exactly where the name sits, so
   nothing on the page moves while it is open. */
.org-edit {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1 1 14rem;
}
.org-input {
  width: auto;
  flex: 1 1 8rem;
  max-width: 22rem;
  padding: 0.25rem 0.5rem;
}
.org-edit .button,
.org-adding .button {
  padding: 0.25rem 0.7rem;
  font-size: 0.85rem;
}
.org-field-error {
  margin: 0.2rem 0 0.3rem 1.9rem;
  font-size: 0.85rem;
  color: var(--danger);
}
.org-none {
  margin: 0.1rem 0 0.2rem 1.9rem;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--ink-muted);
}

/* Sorted into place, a new unit seldom appears where it was typed — the tint
   fading out of its row is how the eye follows it there. */
@keyframes org-flash {
  from { background: #e8eff7; }
  to { background: transparent; }
}
.org-flash > .org-row { animation: org-flash 1.6s ease-out; }

.org mark {
  background: #fbeec2;
  color: inherit;
  border-radius: 2px;
}

/* The structure without JavaScript: readable, not editable. */
.org-plain, .org-plain ul { margin: 0.2rem 0; }

@media (prefers-reduced-motion: reduce) {
  .org-flash > .org-row { animation: none; }
  .org-actions .button { transition: none; }
}

/* The signed-out pages — login and setup — have no sidebar. The body drops to
   a single column and the card is centred near the top of the viewport. */
.auth-page {
  grid-template-columns: 1fr;
}
.auth-page main {
  display: flex;
  justify-content: center;
}
.auth-card {
  width: 100%;
  max-width: 22rem;
  margin-top: 3rem;
}
.auth-card h1 {
  margin: 0 0 1rem;
  font-size: 1.4rem;
}

/* Below this the sidebar would crowd the content, so it folds up into a top
   bar with the navigation laid out horizontally. */
@media (max-width: 48rem) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 1rem 1.25rem;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.25rem 0.5rem;
  }
}

@media (max-width: 40rem) {
  .page-header { flex-direction: column; align-items: stretch; }
  .fields { grid-template-columns: 1fr; }
}
