/*
  Saturday - global styles

  Linked by every view. Holds the design tokens, element defaults, the app
  shell (sidebar + top bar) and the shared components (page head, cards,
  rows, facts, buttons, badges, avatars, switches, empty states). Anything
  specific to a single page belongs in that page's own stylesheet.
*/

/* ---------------------------------------------------------------
   Tokens
   --------------------------------------------------------------- */

:root {
  --ink: #20211f;
  --ink-muted: #5f615d;
  --charcoal: #2d2f2c;
  --charcoal-raised: #3b3d39;
  --control-edge: #868882;
  --line: #c7c8c3;
  --avatar: #d9d9d5;
  --fill: #ecece9;
  --canvas: #f4f4f2;
  --paper: #ffffff;
  --danger: #a4262c;
  --danger-fill: #fcf1f1;
  --ok: #2f7d4f;

  --sidebar-ink: #ffffff;
  --sidebar-muted: #d9d9d5;
  --sidebar-label: #8a8c87;

  /* The platform's own font: no download, and it matches the OS the person is on. */
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  --radius-sm: 4px;
  --radius-control: 6px;
  --radius-card: 8px;

  --sidebar-width: 224px;
  --topbar-height: 72px;
}

/* ---------------------------------------------------------------
   Element defaults
   --------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p,
ul,
dl,
dd {
  margin: 0;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

ul {
  padding: 0;
  list-style: none;
}

a {
  color: inherit;
}

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

/* ---------------------------------------------------------------
   Type helpers
   --------------------------------------------------------------- */

.eyebrow {
  display: block;
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.eyebrow a {
  text-decoration: none;
}

.eyebrow a:hover {
  text-decoration: underline;
}

.caption {
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--ink-muted);
}

p.caption:not(.row-main .caption),
.field > span.caption {
  max-inline-size: 58ch;
  overflow-wrap: anywhere;
}

/* Line icons from the /icons.svg sprite: <svg class="icon"><use href="/icons.svg#name" /></svg> */
.icon {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

/* ---------------------------------------------------------------
   App shell: sidebar, top bar, content area
   --------------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 16px;
  background: var(--charcoal);
  color: var(--sidebar-ink);
}

.sidebar :focus-visible {
  outline-color: var(--sidebar-ink);
}

.sidebar .eyebrow {
  color: var(--sidebar-label);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-control);
  background: var(--paper);
  color: var(--charcoal);
}

.brand-mark .icon {
  width: 24px;
  height: 24px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-name {
  font-size: 1.0625rem;
}

.brand-tag {
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-label {
  padding: 0 10px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-control);
  color: var(--sidebar-muted);
  text-decoration: none;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}

.nav-link:hover {
  background: rgb(255 255 255 / 0.06);
  color: var(--sidebar-ink);
}

.nav-link[aria-current='page'] {
  background: var(--ink-muted);
  color: var(--sidebar-ink);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: var(--topbar-height);
  padding: 0 32px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(100%, 360px);
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--canvas);
  color: var(--ink-muted);
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
}

.search input:disabled {
  cursor: not-allowed;
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-help {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-muted);
  font-size: 0.875rem;
  text-decoration: none;
}

.topbar-help:hover {
  color: var(--ink);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 16px;
  border-left: 1px solid var(--line);
  text-decoration: none;
}

.topbar-user-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.topbar-user-name {
  font-size: 0.875rem;
  font-weight: 500;
}

.content {
  flex: 1;
  padding: 32px;
}

/* ---------------------------------------------------------------
   Page structure
   --------------------------------------------------------------- */

/* Vertical rhythm for a page's cards. */
.stack {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Eyebrow, title and subtitle on the left; the page's one action on the right. */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.page-head h1 {
  margin-top: 8px;
}

.page-head p {
  max-width: 64ch;
  margin-top: 4px;
  color: var(--ink-muted);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* ---------------------------------------------------------------
   Cards, rows, facts
   --------------------------------------------------------------- */

.card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

.card-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.card-foot {
  display: flex;
  justify-content: flex-end;
}

/* Inset rows inside a card, on the canvas grey. */
.rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border-radius: var(--radius-control);
  background: var(--canvas);
}

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

.row-title {
  font-weight: 600;
  line-height: 1.4;
}

/* Eyebrow-labelled values: <dl class="facts"><div><dt class="eyebrow"> + <dd>. */
.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 48px;
}

.facts dd {
  margin-top: 2px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.facts-divided {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 24px;
  border: 1px dashed var(--control-edge);
  border-radius: var(--radius-card);
  text-align: center;
  color: var(--ink-muted);
}

.empty-state h2 {
  color: var(--ink);
}

.empty-state .button {
  margin-top: 8px;
}

/* ---------------------------------------------------------------
   Controls
   --------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--ink-muted);
  border-radius: var(--radius-control);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.button:hover {
  background: var(--canvas);
}

.button-primary {
  padding: 10px 16px;
  border-color: var(--charcoal);
  background: var(--charcoal);
  color: var(--paper);
}

.button-primary:hover {
  border-color: var(--charcoal-raised);
  background: var(--charcoal-raised);
}

/* Destructive actions, like deleting something for good. */
.button-danger {
  border-color: var(--danger);
  color: var(--danger);
}

.button-danger:hover {
  background: var(--danger-fill);
}

.button-small {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.button:disabled:hover {
  background: var(--paper);
}

.button-primary:disabled:hover {
  background: var(--charcoal);
}

.button-group {
  display: flex;
  gap: 8px;
}

.dialog {
  width: min(100% - 32px, 440px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--paper);
  color: var(--ink);
}

.dialog::backdrop {
  background: rgb(32 33 31 / 0.5);
}

.dialog-form {
  display: grid;
  gap: 16px;
}

.dialog-actions {
  justify-content: flex-end;
}

/* Grey pill for calm status and labels ("On track", "Coming soon"). */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--ink-muted);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1;
}

/* White pill with an outline, for values like a task's frequency. */
.badge-outline {
  border: 1px solid var(--control-edge);
  background: var(--paper);
  color: var(--ink);
}

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--avatar);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 600;
}

.avatar-lg {
  width: 56px;
  height: 56px;
  font-size: 1rem;
}

/* Switch: a native checkbox, so keyboard and screen readers work as-is. */
.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 40px;
  height: 22px;
  margin: 0;
  border: 1.5px solid var(--control-edge);
  border-radius: 999px;
  background: var(--paper);
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.switch::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--control-edge);
  transform: translateY(-50%);
  transition:
    transform 0.15s ease,
    background-color 0.15s ease;
}

.switch:checked {
  border-color: var(--charcoal);
  background: var(--charcoal);
}

.switch:checked::before {
  background: var(--paper);
  transform: translate(18px, -50%);
}

@media (forced-colors: active) {
  .switch::before {
    background: ButtonText;
  }

  .switch:checked {
    background: Highlight;
  }

  .switch:checked::before {
    background: HighlightText;
  }
}

/* ---------------------------------------------------------------
   Small screens: the sidebar becomes a strip across the top
   --------------------------------------------------------------- */

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

  .sidebar {
    position: static;
    height: auto;
    gap: 12px;
    padding: 12px 16px;
  }

  .brand,
  .nav-link,
  .topbar-help,
  .topbar-user,
  .button {
    min-height: 44px;
  }

  .button {
    min-width: 44px;
  }

  .brand {
    padding: 0;
  }

  .nav-label {
    display: none;
  }

  .nav {
    flex-flow: row wrap;
  }

  .topbar {
    min-height: 60px;
    padding: 0 16px;
  }

  .topbar-user .avatar {
    width: 2rem;
    height: 2rem;
  }

  .topbar-user[aria-current='page'] .avatar {
    background: var(--ink-muted);
    color: var(--paper);
  }

  .content {
    padding: 24px 16px 48px;
  }
}

@media (max-width: 520px) {
  .search,
  .topbar-user-text {
    display: none;
  }

  .topbar {
    justify-content: flex-end;
  }

  h1 {
    font-size: 1.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

/* Form fields: <label class="field">Text <input /></label> */
.field {
  display: grid;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 500;
}

.field input {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--control-edge);
  border-radius: var(--radius-control);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}

.field .caption {
  font-weight: 400;
}

.form-note {
  padding: 10px 12px;
  border-radius: var(--radius-control);
  background: var(--fill);
  color: var(--ink);
}

/* PDF manual drop zone: the appliance page, the new-appliance form and the manual review. */
.manual-upload {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dropzone {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border: 1px dashed var(--control-edge);
  border-radius: var(--radius-card);
  color: var(--ink-muted);
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.dropzone:hover,
.dropzone.is-dragging {
  border-color: var(--ink);
  background: var(--canvas);
}

.dropzone:focus-within {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.dropzone .icon {
  flex: none;
}

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

.dropzone-text .row-title {
  color: var(--ink);
}

.dropzone-chosen {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.dropzone-chosen:empty {
  display: none;
}

/* The file input stays focusable and clickable through its label, just not visible. */
.dropzone input[type='file'] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* A checkbox with its label beside it. */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.manual-section {
  display: grid;
  gap: 12px;
}

/* Upload progress under the drop zone. */
.upload-progress {
  display: grid;
  gap: 6px;
}

.upload-progress progress {
  width: 100%;
  height: 8px;
  accent-color: var(--charcoal);
}

/* Shared form and text helpers, used across pages. */
.form-note-error {
  background: var(--danger-fill);
  color: var(--danger);
}

.field select,
.field textarea {
  padding: 8px 12px;
  border: 1px solid var(--control-edge);
  border-radius: var(--radius-control);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}

.field select {
  height: 38px;
  padding-block: 0;
}

.field textarea {
  resize: vertical;
}

fieldset.field {
  margin: 0;
  padding: 0;
  border: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.caption-warning {
  color: var(--danger);
}

.badge {
  white-space: nowrap;
}

.badge-danger {
  background: var(--danger-fill);
  color: var(--danger);
  text-decoration: none;
}

/* Dialogs keep long words, such as file names, inside their width. */
.dialog,
.dialog * {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Fields shrink with their column; a long option never widens the page. */
.field {
  min-width: 0;
}

.field select,
.field input,
.field textarea {
  max-width: 100%;
  min-width: 0;
}

.upload-progress[hidden] {
  display: none;
}
