/*
 * 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; }

.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; }

/* 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; }
}
