/* AFFiNE Gantt — farveroller følger den validerede referencepalet.
   Lys er standard; mørk defineres både under prefers-color-scheme og under
   [data-theme="dark"], så et eksplicit valg vinder begge veje. */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.04);
  --wash-strong: rgba(11, 11, 11, 0.08);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --series-other: #898781;

  --critical: #d03b3b;
  --good: #0ca30c;

  --name-w: 300px;
  --row-h: 30px;
  --bar-h: 14px;
  --head-h: 52px;

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.04);
    --wash-strong: rgba(255, 255, 255, 0.09);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.04);
  --wash-strong: rgba(255, 255, 255, 0.09);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

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

/* --- topbar ------------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.topbar__title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.pill::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.pill[data-state="ok"]::before { background: var(--good); }
.pill[data-state="error"]::before { background: var(--critical); }
.pill[data-state="readonly"]::before { background: var(--series-4); }

/* --- filtre ------------------------------------------------------------ */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field--search { flex: 1 1 220px; max-width: 320px; }

.field__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

input[type="search"], select {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--axis);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
}

input[type="search"] { width: 100%; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.spacer { flex: 1 1 auto; }

.btn {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--axis);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.btn:hover { background: var(--wash); }
.btn--ghost { border-color: var(--border); }
.btn[disabled] { opacity: 0.5; cursor: default; }

.segmented {
  display: inline-flex;
  border: 1px solid var(--axis);
  border-radius: 6px;
  overflow: hidden;
}

.segmented__btn {
  height: 30px;
  padding: 0 12px;
  border: 0;
  background: var(--surface-1);
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.segmented__btn + .segmented__btn { border-left: 1px solid var(--axis); }
.segmented__btn.is-active { background: var(--wash-strong); color: var(--text-primary); }

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

/* --- signaturforklaring ------------------------------------------------ */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 10px 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend__swatch {
  width: 12px;
  height: 8px;
  border-radius: 2px;
  background: var(--c, var(--series-1));
}

/* --- indhold ----------------------------------------------------------- */

.content {
  flex: 1 1 auto;
  min-height: 0;
  padding: 16px 20px;
}

.panel {
  height: 100%;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.gantt { height: 100%; }

.gantt__scroll {
  height: 100%;
  overflow: auto;
  position: relative;
}

.gantt__head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  height: var(--head-h);
  background: var(--surface-1);
  border-bottom: 1px solid var(--axis);
}

.gantt__corner {
  position: sticky;
  left: 0;
  z-index: 4;
  flex: 0 0 var(--name-w);
  width: var(--name-w);
  display: flex;
  align-items: flex-end;
  padding: 0 12px 6px;
  background: var(--surface-1);
  border-right: 1px solid var(--axis);
  font-size: 12px;
  color: var(--text-muted);
}

.gantt__axis {
  position: relative;
  flex: 0 0 auto;
  height: 100%;
}

.axis__major, .axis__minor {
  position: absolute;
  top: 0;
  height: 26px;
  display: flex;
  align-items: center;
  padding-left: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  border-left: 1px solid var(--grid);
}

.axis__minor {
  top: 26px;
  height: 25px;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.axis__minor.is-weekend { color: var(--text-muted); opacity: 0.7; }

.gantt__body {
  display: flex;
  align-items: flex-start;
}

.gantt__names {
  position: sticky;
  left: 0;
  z-index: 2;
  flex: 0 0 var(--name-w);
  width: var(--name-w);
  background: var(--surface-1);
  border-right: 1px solid var(--axis);
}

.gantt__canvas {
  position: relative;
  flex: 0 0 auto;
}

.gantt__rows { position: relative; }

.gantt__links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

/* rækker ---------------------------------------------------------------- */

.row, .name {
  height: var(--row-h);
  display: flex;
  align-items: center;
}

.name {
  gap: 6px;
  padding: 0 12px;
  font-size: 13px;
  color: var(--text-primary);
  border-bottom: 1px solid transparent;
}

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

.name--group, .row--group {
  height: 34px;
  background: var(--wash);
}

.name--group {
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.name--group .name__count {
  color: var(--text-muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.group__toggle {
  border: 0;
  background: none;
  padding: 0;
  width: 16px;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  line-height: 1;
}

.name.is-hovered, .row.is-hovered { background: var(--wash); }

.name__dot {
  flex: 0 0 auto;
  width: 8px; height: 8px;
  border-radius: 2px;
  background: var(--c, var(--series-1));
}

.name__flag {
  flex: 0 0 auto;
  font-size: 11px;
  line-height: 1;
  color: var(--critical);
}

.name__done { color: var(--good); }

/* bjælker --------------------------------------------------------------- */

.row { position: relative; }

.bar {
  position: absolute;
  height: var(--bar-h);
  top: calc((var(--row-h) - var(--bar-h)) / 2);
  border-radius: 4px;
  background: color-mix(in oklab, var(--c, var(--series-1)) 22%, var(--surface-1));
  cursor: default;
  z-index: 2;
}

.bar__fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 4px;
  background: var(--c);
}

.bar.is-draggable { cursor: grab; }
.bar.is-dragging { cursor: grabbing; }

.bar__handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  z-index: 3;
}

.bar__handle--start { left: -2px; }
.bar__handle--end { right: -2px; }

.bar.is-overdue::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -2px;
  bottom: -2px;
  width: 3px;
  border-radius: 2px;
  background: var(--critical);
}

.milestone {
  position: absolute;
  width: 12px; height: 12px;
  top: calc((var(--row-h) - 12px) / 2);
  transform: rotate(45deg);
  border-radius: 2px;
  background: var(--c);
  z-index: 2;
}

/* usynlig, men stor nok, ramme at ramme med musen */
.hit {
  position: absolute;
  top: 0;
  height: var(--row-h);
  z-index: 4;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.gantt__today {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--text-secondary);
  z-index: 5;
  pointer-events: none;
}

.gantt__today-label {
  position: absolute;
  top: 3px;
  z-index: 6;
  transform: translateX(-50%);
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--text-secondary);
  color: var(--surface-1);
  font-size: 10px;
  line-height: 1.5;
  white-space: nowrap;
  pointer-events: none;
}

/* --- tooltip ----------------------------------------------------------- */

.tooltip {
  position: fixed;
  z-index: 50;
  max-width: 300px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-size: 13px;
  pointer-events: none;
}

.tooltip__value {
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.tooltip__name {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 4px;
  color: var(--text-secondary);
}

.tooltip__key {
  flex: 0 0 auto;
  width: 14px;
  height: 2px;
  border-radius: 1px;
  background: var(--c, var(--series-1));
}

.tooltip__meta {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 12px;
}

.tooltip__alert {
  margin-top: 6px;
  color: var(--critical);
  font-size: 12px;
  font-weight: 600;
}

/* --- tabel ------------------------------------------------------------- */

#tableView { overflow: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table caption { text-align: left; }

.table th, .table td {
  padding: 7px 12px;
  text-align: left;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

.table th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  border-bottom: 1px solid var(--axis);
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}

.table td.num { font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: var(--wash); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip__dot {
  width: 8px; height: 8px;
  border-radius: 2px;
  background: var(--c, var(--series-1));
}

.flag-late {
  color: var(--critical);
  font-weight: 600;
}

/* --- fod og kilder ----------------------------------------------------- */

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-1);
  font-size: 12px;
  color: var(--text-muted);
}

.link {
  color: var(--text-secondary);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.sources {
  padding: 12px 20px 16px;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  max-height: 40vh;
  overflow: auto;
}

.sources table { border-collapse: collapse; width: 100%; }
.sources th, .sources td { padding: 5px 10px; text-align: left; border-bottom: 1px solid var(--grid); }

.empty {
  margin: 0;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

/* --- toast ------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: 480px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  font-size: 13px;
}

.toast[data-kind="error"] { border-color: var(--critical); color: var(--critical); }

/* Genindlæsning holder billedet i stedet for at blinke */
.is-refreshing .content { opacity: 0.55; transition: opacity 120ms ease; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* --- backlog: opgaver uden datoer -------------------------------------- */

/* Ligger uden for .content, som en stribe over footeren, så gantt-panelets
   højdeberegning ikke røres. */
.backlog {
  flex: 0 0 auto;
  max-height: 32vh;
  display: flex;
  flex-direction: column;
  margin: 0 20px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.backlog-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.backlog-head:hover { background: var(--surface-2, rgba(127, 127, 127, 0.06)); }

.backlog-caret {
  width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 120ms ease;
}

.backlog[data-open="true"] .backlog-caret { transform: rotate(90deg); }

.backlog-list {
  margin: 0;
  padding: 4px 0;
  list-style: none;
  overflow-y: auto;
}

.backlog-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  min-height: 34px;
}

.backlog-item + .backlog-item { border-top: 1px solid var(--border); }

.backlog-dot {
  flex: 0 0 auto;
  width: 8px; height: 8px;
  border-radius: 50%;
}

.backlog-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.backlog-project {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 12px;
}

.backlog-action,
.backlog-save,
.backlog-cancel {
  flex: 0 0 auto;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  color: var(--text-primary);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.backlog-action:hover:not(:disabled),
.backlog-save:hover,
.backlog-cancel:hover { background: var(--surface-2, rgba(127, 127, 127, 0.08)); }

.backlog-action:disabled { opacity: 0.45; cursor: not-allowed; }

.backlog-form {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.backlog-form input[type="date"] {
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--page);
  color: var(--text-primary);
  font: inherit;
  font-size: 12px;
}

.backlog-dash { color: var(--text-muted); }

/* --- login ------------------------------------------------------------- */

.login {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--page);
}

/* Skjuler diagrammet bag login, så ingen data blinker forbi inden
   serveren har svaret på hvem man er. */
body.is-locked .content,
body.is-locked .topbar,
body.is-locked .footer,
body.is-locked .backlog { visibility: hidden; }

.login-card {
  display: flex;
  flex-direction: column;
  width: min(360px, 100%);
  padding: 28px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.login-title {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 650;
}

.login-lead {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.login-label {
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 600;
}

.login-input {
  margin-bottom: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
  font: inherit;
}

.login-input:focus-visible {
  outline: 2px solid var(--series-1, #4c7cf3);
  outline-offset: 1px;
}

.login-error {
  margin: 0 0 12px;
  color: #d2453c;
  font-size: 13px;
}

.login-submit {
  padding: 9px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--text-primary);
  color: var(--page);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.login-submit:disabled { opacity: 0.6; cursor: progress; }

.user-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: var(--text-muted);
}

.user-bar .link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

/* Anker stylet som knappen ved siden af — bruges når login ikke kan
   huskes, og eneste vej frem er at åbne i en rigtig fane. */
a.login-submit {
  display: block;
  text-align: center;
  text-decoration: none;
}
