/* Nomios web UI: shell (glass, app shell, icons, loading strip). Design system: docs/design/DESIGN_SYSTEM.md.
   The four stylesheets are linked in this order: tokens, base, shell, components. */

@layer shell {
  /* The glass material. Every panel that floats over the background uses it. */
  .glass,
  #cost-counter {
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-glass);
  }

  /* No blur available: a solid surface, still readable. */
  @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .glass,
    #cost-counter {
      background: var(--glass-solid);
    }
  }

  @media (forced-colors: active) {
    .glass,
    #cost-counter {
      border-color: CanvasText;
    }
  }

  .skip-link {
    position: fixed;
    inset-block-start: var(--space-3);
    inset-inline-start: var(--space-4);
    z-index: var(--z-overlay);
    padding: var(--space-2) var(--space-4);
    font-weight: 600;
    color: var(--color-accent-contrast);
    background: var(--color-accent);
    border-radius: var(--radius-pill);
    text-decoration: none;
    transform: translateY(-200%);
    transition: transform var(--dur-base) var(--ease-spring);
  }

  .skip-link:focus-visible {
    transform: none;
  }

  .shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    gap: var(--shell-gap);
    align-items: start;
    padding: var(--shell-gap);
    max-width: calc(var(--content-max) + var(--sidebar-w) + var(--shell-gap) * 3);
    margin-inline: auto;
  }

  .shell-bare {
    grid-template-columns: minmax(0, 1fr);
    max-width: 48rem;
  }

  .sidebar {
    position: sticky;
    top: var(--shell-gap);
    z-index: var(--z-sticky);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    height: calc(100dvh - var(--shell-gap) * 2);
    padding: var(--space-5) var(--space-3);
  }

  .shell-bare .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-lg);
  }

  .brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-1) var(--space-3);
    color: var(--color-text);
    font-size: var(--text-xl);
    font-weight: 500;
    letter-spacing: 0.01em;
    text-decoration: none;
  }

  .brand-mark {
    width: 1.75rem;
    height: 1.75rem;
    color: var(--color-accent);
    --icon: url("/static/icons/mark.svg");
  }

  .nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
  }

  .nav-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
  }

  .nav-heading {
    margin: 0;
    padding: 0 var(--space-3) var(--space-1);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: var(--tracking-eyebrow);
    text-transform: uppercase;
    color: var(--color-text-muted);
  }

  .nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    color: var(--color-text-muted);
    font-weight: 500;
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    transition:
      transform var(--dur-fast) var(--ease-spring),
      background-color var(--dur-fast) var(--ease-standard),
      color var(--dur-fast) var(--ease-standard);
  }

  .nav-link:hover {
    color: var(--color-text);
    background: var(--color-hover);
    transform: translateX(2px);
  }

  .nav-link:active {
    transform: scale(var(--press-scale));
  }

  .nav-link[aria-current="page"] {
    color: var(--color-text);
    font-weight: 600;
    background: var(--glass-raised-bg);
    border-color: var(--color-border);
    box-shadow: inset 0 1px 0 var(--glass-highlight);
  }

  .nav-link[aria-current="page"] .icon {
    color: var(--color-accent);
  }

  /* "in progress": a quiet word on a link of a page that is not built yet (administrators only) */
  .nav-note {
    margin-inline-start: auto;
    padding: 0 var(--space-2);
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    white-space: nowrap;
  }

  .feedback .nav-note {
    margin-inline-start: 0;
  }

  /* Icons are SVG files used as masks, so they take the text colour and add no markup weight. */
  .icon,
  .brand-mark {
    display: inline-block;
    flex: none;
    background-color: currentcolor;
    -webkit-mask: var(--icon) center / contain no-repeat;
    mask: var(--icon) center / contain no-repeat;
  }

  .icon {
    width: 1.25rem;
    height: 1.25rem;
  }

  .icon-board {
    --icon: url("/static/icons/board.svg");
  }

  .icon-chat {
    --icon: url("/static/icons/chat.svg");
  }

  .icon-planner {
    --icon: url("/static/icons/planner.svg");
  }

  .icon-done {
    --icon: url("/static/icons/done.svg");
  }

  .icon-projects {
    --icon: url("/static/icons/projects.svg");
  }

  .icon-meetings {
    --icon: url("/static/icons/meetings.svg");
  }

  .icon-settings {
    --icon: url("/static/icons/settings.svg");
  }

  .icon-feedback {
    --icon: url("/static/icons/feedback.svg");
  }

  .icon-flag {
    --icon: url("/static/icons/flag.svg");
  }

  .icon-sparkle {
    --icon: url("/static/icons/sparkle.svg");
  }

  .icon-play {
    --icon: url("/static/icons/play.svg");
  }

  .icon-hourglass {
    --icon: url("/static/icons/hourglass.svg");
  }

  .icon-document {
    --icon: url("/static/icons/document.svg");
  }

  .icon-skills {
    --icon: url("/static/icons/skills.svg");
  }

  .icon-plug {
    --icon: url("/static/icons/plug.svg");
  }

  .icon-attachment {
    --icon: url("/static/icons/attachment.svg");
  }

  .icon-subtasks {
    --icon: url("/static/icons/subtasks.svg");
  }

  .icon-arrowup {
    --icon: url("/static/icons/arrowup.svg");
  }

  .icon-arrowdown {
    --icon: url("/static/icons/arrowdown.svg");
  }

  .icon-target {
    --icon: url("/static/icons/target.svg");
  }

  .icon-criteria {
    --icon: url("/static/icons/criteria.svg");
  }

  .icon-plus {
    --icon: url("/static/icons/plus.svg");
  }

  .icon-close {
    --icon: url("/static/icons/close.svg");
  }

  .icon-mic {
    --icon: url("/static/icons/mic.svg");
  }

  .icon-runs {
    --icon: url("/static/icons/runs.svg");
  }

  .icon-server {
    --icon: url("/static/icons/server.svg");
  }

  .icon-tools {
    --icon: url("/static/icons/tools.svg");
  }

  .icon-time {
    --icon: url("/static/icons/time.svg");
  }

  .icon-claude {
    --icon: url("/static/icons/claude.svg");
  }

  /* The foot of the sidebar: user, feedback, spend and the save cue. */
  .sidebar-foot {
    display: grid;
    /* a column that may be narrower than its content: a long name is cut with dots, it does not
       widen the sidebar */
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
    margin-top: auto;
  }

  .sidebar-foot .user-area {
    margin-top: 0;
  }

  .feedback {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    text-decoration: none;
  }

  .feedback[aria-current="page"] {
    border-color: var(--color-accent);
  }

  .sidebar-cost {
    display: grid;
    gap: var(--space-1);
    margin: 0;
    padding: 0 var(--space-3);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
  }

  .sidebar-cost:empty {
    display: none;
  }

  .sidebar-cost-label {
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: var(--tracking-eyebrow);
    text-transform: uppercase;
    color: var(--color-text-muted);
  }

  .sidebar-cost-amount {
    font-weight: 600;
  }

  .save-state {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    padding: 0 var(--space-3);
    font-size: var(--text-xs);
    color: var(--color-text-muted);
  }

  .save-state::before {
    content: "";
    width: 0.4rem;
    height: 0.4rem;
    background: var(--status-succeeded);
    border-radius: 50%;
  }

  .save-state[hidden] {
    display: none;
  }

  /* The signed-in user. Rendered only when the page is given a user, so the local single-user mode
     shows nothing here and no layout depends on there being one. */
  .user-area {
    display: flex;
    flex-wrap: wrap; /* the name gets the row with the avatar, "Sign out" goes below (U48) */
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin-top: auto;
    padding: var(--space-3) var(--space-2) 0;
    border-top: 1px solid var(--color-border);
  }

  .avatar {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 2rem;
    height: 2rem;
    font-size: var(--text-sm);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--color-accent-contrast);
    background: var(--color-accent);
    border-radius: 50%;
  }

  /* A long name (German names and compounds are long) wraps over up to three lines before it is cut; the
     full name is in the title of the area. With "Sign out" beside it, the name had 47 px (U48). */
  .user-name {
    flex: 1 1 6rem;
    min-width: 0;
    overflow: hidden;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    font-size: var(--text-sm);
    font-weight: 600;
  }

  .user-signout {
    margin: 0;
  }

  /* The language of this browser: two small buttons in one pill. The current one is filled. */
  .lang-switch {
    display: inline-flex;
    align-self: start;
    gap: 2px;
    width: fit-content;
    margin: 0;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    background: var(--color-sunken);
  }

  .lang-option {
    min-width: 2.25rem;
    padding: var(--space-1) var(--space-3);
    font: inherit;
    font-size: var(--text-xs);
    font-weight: 650;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    background: transparent;
    border: 0;
    border-radius: var(--radius-pill);
    cursor: pointer;
  }

  .lang-option:hover {
    color: var(--color-text);
    background: var(--color-hover);
  }

  .lang-option.is-current {
    color: var(--color-accent-contrast);
    background: var(--color-accent);
  }

  .user-signout button {
    padding: var(--space-1) var(--space-3);
    color: var(--color-text);
    white-space: nowrap;
    background: var(--glass-raised-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
  }

  .user-signout button:hover {
    background: var(--color-hover);
  }

  .stage {
    display: flex;
    gap: var(--shell-gap);
    align-items: flex-start;
    min-width: 0;
  }

  .page {
    flex: 1;
    min-width: 0;
    max-width: var(--content-max);
    padding: var(--space-8);
    animation: rise var(--dur-slow) var(--ease-out) both;
  }

  /* Loading: a thin strip along the top of the page while a request runs. The quiet 3 s refreshes
     (board, cost, live run) are left out so the page does not flicker. */
  .page {
    position: relative;
  }

  .page::before {
    content: "";
    position: absolute;
    inset: 0 var(--radius-xl) auto;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--color-accent), transparent) 0 0 / 50% 100%
      no-repeat;
    opacity: 0;
    transition: opacity var(--dur-base) var(--ease-standard);
    pointer-events: none;
  }

  body:has(.htmx-request:not(#board-region, #task-board, #cost-counter, #run-live, #sidebar-cost)) .page::before {
    opacity: 1;
  }

  @media (prefers-reduced-motion: no-preference) {
    body:has(.htmx-request:not(#board-region, #task-board, #cost-counter, #run-live, #sidebar-cost)) .page::before {
      animation: slide 1.1s var(--ease-standard) infinite;
    }
  }

  @keyframes slide {
    to {
      background-position: 200% 0;
    }
  }

  .page:focus {
    outline: none; /* the skip link target is not a control */
  }

  #cost-counter {
    width: 16rem;
    flex: none;
    padding: var(--space-5);
    border-radius: var(--radius-lg);
  }

  @keyframes rise {
    from {
      opacity: 0;
      transform: translateY(var(--space-3));
    }
  }

  @media (max-width: 70rem) {
    .stage {
      flex-direction: column;
    }

    .page,
    #cost-counter {
      width: 100%;
      max-width: none;
    }
  }

  /* Phone and narrow windows: the sidebar becomes a top bar with scrolling tabs. */
  @media (max-width: 48rem) {
    .shell {
      grid-template-columns: minmax(0, 1fr);
      padding: var(--space-3);
      gap: var(--space-3);
    }

    .sidebar {
      position: static;
      height: auto;
      flex-direction: row;
      align-items: center;
      gap: var(--space-2);
      padding: var(--space-2) var(--space-3);
      border-radius: var(--radius-lg);
    }

    .nav {
      flex-direction: row;
      overflow-x: auto;
      scrollbar-width: none;
      margin-inline-start: auto;
    }

    .nav-link {
      gap: var(--space-2);
      padding: var(--space-2) var(--space-3);
    }

    .nav-link span {
      white-space: nowrap;
    }

    .brand {
      padding-inline: var(--space-2);
    }

    .sidebar-top {
      flex: none; /* the brand mark and the bell keep their size beside the scrolling tabs */
    }

    .nav-heading,
    .sidebar-cost {
      display: none;
    }

    /* These are not shown on the narrow header (the round initials, the icons and the title are),
       but they stay in the page for assistive technology, which is how the link to the start
       page, the feedback link and the "Saved" cue keep their names and are announced:
       display:none would take them away. */
    .brand-name,
    .save-state,
    .feedback span:not(.icon),
    .user-name {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
    }

    .sidebar-foot .lang-switch {
      display: none; /* on a phone the language is switched on the Settings page */
    }

    .nav-group {
      flex-direction: row;
    }

    .sidebar-foot {
      grid-template-columns: none;
      margin-top: 0;
      margin-inline-start: var(--space-2);
    }

    .user-area {
      flex-wrap: nowrap;
      margin-top: 0;
      padding: 0;
      border-top: 0;
    }

    .page {
      padding: var(--space-5) var(--space-4);
      border-radius: var(--radius-lg);
    }
  }

  /* A short window (a laptop at 125 % scaling is about 600 px high): the sidebar keeps every link in
     sight instead of hiding the tools behind a scroll. Headings and the spend line give way. */
  @media (min-width: 48.01rem) and (max-height: 46rem) {
    .nav-heading,
    .sidebar-cost {
      display: none;
    }

    .sidebar,
    .nav,
    .sidebar-foot {
      gap: var(--space-2);
    }

    .sidebar {
      padding-block: var(--space-3);
    }

    .nav-group {
      gap: 0;
    }

    .nav-link {
      padding-block: var(--space-1);
    }

    .sidebar-foot {
      grid-template-columns: auto minmax(0, 1fr);
    }

    .sidebar-foot .user-area,
    .sidebar-foot .save-state {
      grid-column: 1 / -1;
      padding-top: var(--space-2);
    }

    .sidebar-foot .btn-quiet {
      padding-inline: var(--space-2);
    }

    .sidebar-foot .avatar {
      display: none; /* the initials give way: the name and "Sign out" share one row */
    }
  }
}
