/* Dashboard page. */

/* ---------- page grid: main column + right aside ---------- */
.page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20rem;
  grid-template-areas:
    'head aside'
    'main aside'
    'foot aside';
  grid-template-rows: auto 1fr auto;
  column-gap: 2rem;
  row-gap: 1.5rem;
  align-items: start;
  width: 100%;
  max-width: 80rem;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 2rem 2rem 2.5rem;
}

.page-head {
  grid-area: head;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

.page-aside {
  grid-area: aside;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

.page-main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

@media (max-width: 1023px) {
  .page {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      'head'
      'main'
      'aside'
      'foot';
    grid-template-rows: auto;
    padding: 1.5rem 1rem 2rem;
  }
}

/* ---------- header ---------- */
.head-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  min-width: 0;
}

.brand-logo {
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
}

.brand-text {
  min-width: 0;
}

.greeting {
  min-height: 1.3125rem;
  font-size: 0.875rem;
  color: var(--fg-muted);
}

.brand-text h1 {
  margin-top: 0.25rem;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}

.subtitle {
  margin-top: 0.5rem;
  max-width: 28rem;
  color: var(--fg-muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.clock {
  flex: none;
  text-align: right;
}

.clock-time {
  display: block;
  font-size: clamp(1.5rem, 3vw, 1.875rem);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.clock-date {
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--fg-muted);
}

/* ---------- search trigger and the add button ---------- */
.head-actions {
  display: flex;
  align-items: stretch;
  gap: 0.75rem;
}

.btn-add {
  flex: none;
  min-height: 3.25rem;
  padding-inline: 1.25rem;
  font-size: 0.9375rem;
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
  min-height: 3.25rem;
  padding: 0.75rem 1rem;
  color: var(--fg-muted);
  text-align: left;
  font-size: 1rem;
  cursor: text;
}

.search-trigger:hover {
  background: var(--surface-hi);
  border-color: var(--border-hi);
}

.search-trigger-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (hover: none) {
  .search-trigger kbd {
    display: none;
  }
}

/* ---------- aside widgets ---------- */
.widget {
  padding: 1rem 1.125rem;
}

.widget-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.widget > .eyebrow {
  margin-bottom: 0.75rem;
}

.stats-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sys {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.sys-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
}

.sys-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8125rem;
  font-weight: 500;
}

.sys-meta {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.6875rem;
  color: var(--fg-muted);
}

.bookmarks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.small {
  font-size: 0.8125rem;
}

.bookmark {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-width: 0;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: 0.875rem;
  text-decoration: none;
}

a.bookmark:hover {
  background: var(--surface-hi);
  border-color: var(--border-hi);
}

.bookmark-invalid {
  opacity: 0.7;
}

.bookmark-dot {
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  background: var(--dot, var(--accent));
}

.bookmark-name {
  min-width: 0;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bookmark-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.875rem;
  padding-top: 0.875rem;
  border-top: 1px solid var(--border);
}

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

/* ---------- services ---------- */
.skeletons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1.5rem;
}

.skeleton-card {
  height: 5.75rem;
}

.skeleton-wide {
  grid-column: 1 / -1;
}

.groups-wrap {
  container-type: inline-size;
  container-name: groups;
}

/* Column counts come from features/services.js (layout()), which balances the
   rows: --group-cols for the groups with few services, --cols inside big groups. */
.groups {
  display: grid;
  grid-template-columns: repeat(var(--group-cols, 1), minmax(0, 1fr));
  gap: 2rem 1.5rem;
  align-items: start;
}

/* Groups with 4+ services span the full row as a multi-column grid; smaller
   groups sit side by side with their services listed vertically. */
.group {
  min-width: 0;
  /* content-visibility paints inside the box only; the slack keeps the last card's
     bottom border and shadow from being clipped at fractional pixel heights. */
  padding: 0 0.375rem 0.5rem;
  margin: 0 -0.375rem -0.5rem;
}

/* Only long dashboards skip painting off-screen groups: the size estimate is
   wrong at first, so using it on short pages makes content jump while it loads. */
.groups-long .group {
  content-visibility: auto;
  contain-intrinsic-size: auto 15rem;
}

.group-big {
  grid-column: 1 / -1;
}

.group-count {
  font-weight: 400;
  opacity: 1;
}

.group-grid {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.5rem;
  grid-template-columns: minmax(0, 1fr);
}

.group-big .group-grid {
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
}

/* ---------- service card ---------- */
.card {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.75rem;
  align-items: start;
  min-height: 4.75rem;
  padding: 0.75rem 0.75rem 0.75rem 1rem;
  overflow: hidden;
  contain: layout style;
}

.card:hover {
  background: var(--surface-hi);
  border-color: var(--border-hi);
}

.card:focus-within {
  border-color: var(--border-hi);
}

.accent-bar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(180deg, var(--accent), transparent);
  box-shadow: 0 0 12px var(--accent-glow);
  opacity: 0.7;
}

.card-icon svg.icon {
  width: 1.5rem;
  height: 1.5rem;
  margin-top: 0.125rem;
  stroke-width: 1.6;
}

.card-body {
  min-width: 0;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.card-link {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg);
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
}

/* The whole card is the click target without nesting buttons inside the link. */
.card-link::after {
  content: '';
  position: absolute;
  inset: 0;
}

.card-link:focus-visible {
  outline: none;
}

.card:has(.card-link:focus-visible) {
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
}

.card-link-invalid {
  color: var(--fg-muted);
}

.card-link-invalid::after {
  display: none;
}

.card-desc,
.card-host {
  margin-top: 0.125rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-desc {
  font-size: 0.8125rem;
  color: var(--fg-muted);
}

.card-host {
  font-size: 0.6875rem;
  color: var(--fg-muted);
}

/* Bottom corner: the actions cover the host line, never the service name. */
.card-actions {
  position: absolute;
  right: 0.375rem;
  bottom: 0.375rem;
  z-index: 1;
  display: flex;
  gap: 0.125rem;
  padding: 0.125rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-hi);
  opacity: 0;
  transition: opacity var(--t) var(--ease);
}

.card:hover .card-actions,
.card:focus-within .card-actions {
  opacity: 1;
}

.card-action {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--fg-muted);
  transition: color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}

.card-action svg.icon {
  width: 1rem;
  height: 1rem;
}

.card-action:hover {
  background: var(--surface-hi);
  color: var(--fg);
}

.card-action-danger:hover {
  color: var(--red-text);
}

/* Discovered from Docker: the state label may drop under the name when the card is narrow. */
.card-docker .card-title {
  flex-wrap: wrap;
  row-gap: 0.125rem;
}

.docker-mark {
  display: inline-flex;
  margin-right: 0.3125rem;
  vertical-align: -0.125em;
}

.docker-mark svg.icon {
  width: 0.8125rem;
  height: 0.8125rem;
}

/* Containers that are not fine read as such on the accent bar too (the tag carries the text). */
.card-bad .accent-bar {
  background: linear-gradient(180deg, var(--red), transparent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--red) 40%, transparent);
}

.card-warn .accent-bar {
  background: linear-gradient(180deg, var(--amber), transparent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--amber) 40%, transparent);
}

.card-neutral .accent-bar {
  background: linear-gradient(180deg, var(--fg-muted), transparent);
  box-shadow: none;
}

/* Admin-only line above the grid when Docker cannot be read. */
.docker-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.5rem;
  margin: 0 0 1rem;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg-muted);
  font-size: 0.8125rem;
}

.docker-notice svg.icon {
  width: 1rem;
  height: 1rem;
}

.docker-notice a {
  margin-left: auto;
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (pointer: coarse), (max-width: 768px) {
  .docker-notice a {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
  }
}

/* Touch and small screens: compact two-column cards whose actions are always
   visible in a full-width row of 44px targets. */
@media (hover: none), (pointer: coarse), (max-width: 768px) {
  .group-grid,
  .group-big .group-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.625rem;
    grid-auto-rows: 1fr;
  }

  .card {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      'icon body'
      'actions actions';
    gap: 0.5rem 0.625rem;
    align-content: space-between;
    min-height: 0;
    padding: 0.625rem 0.625rem 0.25rem 0.875rem;
    border-radius: 14px;
  }

  .card-icon {
    grid-area: icon;
  }

  .card-body {
    grid-area: body;
  }

  .card-icon svg.icon {
    width: 1.25rem;
    height: 1.25rem;
  }

  .card-actions {
    position: relative;
    right: auto;
    bottom: auto;
    grid-area: actions;
    opacity: 1;
    justify-content: flex-end;
    gap: 0;
    margin: 0 -0.25rem;
    padding: 0;
    border: 0;
    border-top: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
  }

  .card-action {
    width: 2.75rem;
    height: 2.75rem;
  }

  .card-host {
    font-size: 0.625rem;
  }

  /* No override for .card-link: a two-line clamp with `overflow-wrap: anywhere` split a long
     single word mid-word ("Audiobooksh / elf"). The name keeps its one-line ellipsis, like the
     description and host lines; the full name is the tooltip. */
}

@media (max-width: 320px) {
  .group-grid,
  .group-big .group-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- empty / error ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 3rem 1.5rem;
  text-align: center;
}

.empty h3 {
  font-size: 1.125rem;
  font-weight: 600;
}

.icon-xl {
  width: 2.5rem;
  height: 2.5rem;
  color: var(--fg-muted);
}

.banner-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.page-foot {
  grid-area: foot;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.75rem;
  color: var(--fg-muted);
}

/* ---------- search palette ---------- */
dialog.dlg-palette {
  width: min(94vw, 40rem);
  margin-top: min(12vh, 6rem);
}

.palette {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.palette-field {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.25rem 0.5rem;
  color: var(--fg-muted);
}

.palette-input {
  flex: 1;
  min-width: 0;
  padding: 0.75rem 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  font-size: 1.25rem;
}

.palette-input:focus-visible {
  outline: none;
}

.palette-field:focus-within {
  color: var(--accent-text);
}

.palette-list {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  max-height: 20rem;
  margin: 0;
  padding: 0.5rem 0 0;
  border-top: 1px solid var(--border);
  list-style: none;
  overflow-y: auto;
}

.palette-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.palette-option.is-active {
  background: var(--surface-hi);
  border-color: var(--accent-text);
}

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

.palette-meta {
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.6875rem;
  color: var(--fg-muted);
}

.palette-empty {
  padding: 1rem 0.75rem;
  color: var(--fg-muted);
  font-size: 0.875rem;
}

.palette-hint {
  padding: 0.5rem 0.75rem 0;
  font-size: 0.75rem;
  color: var(--fg-muted);
}

.palette-hint kbd {
  margin-right: 0.25rem;
}

/* ---------- service dialogs ---------- */
.dlg-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field-set {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.field-set legend {
  padding: 0;
  margin-bottom: 0.375rem;
}

.icon-picker {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.icon-picker legend {
  padding: 0;
  margin-bottom: 0.375rem;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.75rem, 1fr));
  gap: 0.375rem;
  max-height: 9.25rem;
  overflow-y: auto;
  padding: 0.125rem;
}

.icon-opt {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 2.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}

.icon-opt:hover {
  color: var(--fg);
  border-color: var(--border-hi);
}

.icon-opt:has(input:checked) {
  color: var(--accent-text);
  border-color: var(--accent-text);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.icon-opt:has(input:focus-visible) {
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
}

.dlg-footer-split {
  justify-content: space-between;
}

.dlg-footer-end {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-left: auto;
}

/* Narrow screens: the add button keeps only its icon so the search field stays readable. */
@media (max-width: 480px) {
  .head-actions:has(.search-trigger:not([hidden])) .btn-add {
    width: 3.25rem;
    padding-inline: 0;
  }

  .head-actions:has(.search-trigger:not([hidden])) .btn-add span {
    display: none;
  }
}

@media (pointer: coarse), (max-width: 768px) {
  .bookmark {
    min-height: 2.75rem;
  }
}

/* ---------- phones ----------
   Everything below applies up to 640px only; wider layouts are unaffected.
   The header becomes a compact app bar, each category a grouped list. */
@media (max-width: 640px) {
  .page {
    row-gap: 1.25rem;
    padding: 1rem 1rem 1.5rem;
  }

  .page-head {
    gap: 1rem;
  }

  /* Logo, greeting/title and clock on one row; subtitle and chips below. */
  .head-top {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      'logo greet clock'
      'logo title clock'
      'sub sub sub'
      'chips chips chips';
    column-gap: 0.75rem;
    align-items: center;
  }

  .brand,
  .brand-text {
    display: contents;
  }

  .brand-logo {
    grid-area: logo;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.625rem;
  }

  .greeting {
    grid-area: greet;
    min-height: 0;
    overflow: hidden;
    font-size: 0.75rem;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand-text h1 {
    grid-area: title;
    margin-top: 0;
    font-size: 1.375rem;
    line-height: 1.2;
  }

  .clock {
    grid-area: clock;
    align-self: center;
    text-align: right;
  }

  .clock-time {
    font-size: 1.125rem;
  }

  .clock-date {
    margin-top: 0.125rem;
    font-size: 0.6875rem;
    white-space: nowrap;
  }

  .subtitle {
    grid-area: sub;
    max-width: none;
    margin-top: 0.75rem;
    font-size: 0.875rem;
  }

  /* The signed-in user on the left, icon-only actions on the right. */
  .chips {
    grid-area: chips;
    flex-wrap: nowrap;
    margin-top: 0.875rem;
  }

  .chip-user {
    min-width: 0;
    overflow: hidden;
  }

  .chip-act {
    flex: none;
    justify-content: center;
    width: 2.75rem;
    padding-inline: 0;
  }

  .chip-act svg.icon {
    width: 1.125rem;
    height: 1.125rem;
  }

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

  #theme-btn {
    order: 1;
    margin-left: auto;
  }

  #settings-link {
    order: 2;
  }

  #logout-btn {
    order: 3;
  }

  /* Services: one full-width grouped list per category. */
  .groups {
    gap: 1.5rem;
  }

  .skeletons {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.5rem;
  }

  .skeleton-card {
    height: 4rem;
  }

  .group-grid,
  .group-big .group-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: auto;
    gap: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
  }

  .card,
  html.has-wallpaper .card {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: 'icon body actions';
    align-items: center;
    gap: 0 0.75rem;
    min-height: 4rem;
    padding: 0.625rem 0.25rem 0.625rem 0.875rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  /* Separators start at the text, past the icon tile. */
  .card + .card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 3.875rem;
    border-top: 1px solid var(--border);
  }

  .card:has(.card-link:focus-visible) {
    outline-offset: -2px;
  }

  /* The accent stripe only marks containers that need attention. */
  .card:not(.card-bad, .card-warn) .accent-bar {
    display: none;
  }

  .card-icon {
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border: 1px solid var(--border);
    border-radius: 0.625rem;
    background: var(--surface-hi);
  }

  .card-icon svg.icon {
    width: 1.125rem;
    height: 1.125rem;
    margin-top: 0;
  }

  .card-host {
    font-size: 0.6875rem;
  }

  .card-actions {
    position: static;
    grid-area: actions;
    gap: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    opacity: 1;
  }

  .card-action {
    width: 2.5rem;
    height: 2.75rem;
  }

  /* Bookmarks: an even two-column grid instead of ragged rows. */
  .bookmarks {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bookmark {
    justify-content: flex-start;
  }

  .widget {
    padding: 1rem;
  }
}

/* Very narrow phones: the date gives its room to the title. */
@media (max-width: 359px) {
  .clock-date {
    display: none;
  }
}
