/* Application styles.
 *
 * Loaded after w3.css. Everything W3.CSS already provides is used as a class in
 * the markup -- this file is only for the semantic colours w3.css leaves out
 * and the handful of components the framework has no equivalent for (the
 * combobox, toasts, the CSS bar chart, pagy's pagination, the native <dialog>
 * modal) plus the theme from the starter template.
 *
 * Values are literals or W3's own --w3-* custom properties, so there is no
 * build step: Propshaft serves this file as-is.
 */

/* Semantic colour
/* ---------------------------------------------------------------------------
 * w3.css here is the official 5.01 release with its colour section removed,
 * so the theme stays monochrome: only black, white and the greys survive,
 * driven by --w3-* custom properties.
 *
 * Four semantic colours are still needed -- destructive buttons, the flash and
 * validation panels, and the +/- figures on the dashboard. They use GitHub
 * Primer's light-theme values rather than W3's Material palette, and reuse
 * W3's class names so the framework reference still describes the markup.
 * -------------------------------------------------------------------------- */

:root {
  --w3-danger: #cf222e;
  --w3-danger-hover: #a40e26;
  --w3-danger-on: #fff;
  --w3-danger-subtle: #ffebe9;

  --w3-success: #1a7f37;
  --w3-success-subtle: #dafbe1;

  --w3-attention: #9a6700;
  --w3-attention-subtle: #fff8c5;

  --w3-accent: #0969da;
  --w3-accent-subtle: #ddf4ff;

  /* Neutrals retuned from W3's defaults to Primer's. These are w3.css's own
     theme hooks, so borders, hairlines, stripes and muted text follow across
     the whole app, not just the tables below. --w3-ui-hover-bg is left at
     W3's #ccc on purpose: it also paints .w3-dropdown-click:hover, which sits
     on the black navbar. */
  --w3-ui-border: #d1d9e0;
  --w3-ui-line: #d1d9e0;
  --w3-ui-hr: #d1d9e0;
  --w3-ui-stripe: #f6f8fa;
  --w3-ui-surface-on: #1f2328;
  --w3-ui-hover-on: #1f2328;
  --w3-text-grey: #59636e;

  /* Top navigation, matching GitHub's profile UnderlineNav. */
  --w3-nav-bg: #f6f8fa;
  --w3-nav-hover-bg: rgba(129, 139, 152, 0.12);
  --w3-nav-underline: #fd8c73;
}

.w3-red {
  color: var(--w3-danger-on) !important;
  background-color: var(--w3-danger) !important;
}

/* .w3-button:hover is !important and outranks .w3-red, so a destructive button
/* would otherwise go grey on hover instead of darker red. */
.w3-button.w3-red:hover {
  color: var(--w3-danger-on) !important;
  background-color: var(--w3-danger-hover) !important;
}

.w3-pale-red,
.w3-pale-green,
.w3-pale-yellow,
.w3-pale-blue {
  color: var(--w3-ui-surface-on) !important;
}

.w3-pale-red {
  background-color: var(--w3-danger-subtle) !important;
}
.w3-pale-green {
  background-color: var(--w3-success-subtle) !important;
}
.w3-pale-yellow {
  background-color: var(--w3-attention-subtle) !important;
}
.w3-pale-blue {
  background-color: var(--w3-accent-subtle) !important;
}

.w3-text-red {
  color: var(--w3-danger) !important;
}
.w3-text-green {
  color: var(--w3-success) !important;
}
.w3-text-blue {
  color: var(--w3-accent) !important;
}

.w3-border-red {
  border-color: var(--w3-danger) !important;
}
.w3-border-green {
  border-color: var(--w3-success) !important;
}
.w3-border-amber {
  border-color: var(--w3-attention) !important;
}
.w3-border-blue {
  border-color: var(--w3-accent) !important;
}

/* Template theme
/* -------------------------------------------------------------------------- */

body,
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: "Inter", sans-serif;
}

body,
html {
  height: 100%;
}

body {
  color: var(--w3-ui-surface-on);
}

/* Collapsed mobile menu overlays the page instead of pushing it down */
header {
  position: relative;
}

#navDemo {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
}

/* Top navigation
/* ---------------------------------------------------------------------------
 * GitHub's profile nav: a light grey bar, each item a rounded translucent pill
 * on hover, and the current page marked by a 2px orange rule sitting flush
 * with the bar's bottom border.
 *
 * W3 has neither a "current page" state nor a hover that is not a solid block,
 * so the pill goes on an inner .nav-item span (as GitHub's own markup does)
 * while the underline goes on the bar item itself. The items keep
 * w3-hover-none, which is what stops .w3-button:hover painting them #ccc.
 * -------------------------------------------------------------------------- */

.nav-bar {
  background-color: var(--w3-nav-bg);
  border-bottom: 1px solid var(--w3-ui-border);
}

.nav-bar .w3-bar-item {
  border-bottom: 2px solid transparent;
  color: var(--w3-ui-surface-on);
  padding: 6px 8px;
}

.nav-bar .w3-bar-item.active {
  border-bottom-color: var(--w3-nav-underline);
  font-weight: 600;
}

/* The pill. Inset from the bar's bottom edge so the underline clears it. */
.nav-item {
  align-items: center;
  border-radius: 6px;
  display: inline-flex;
  gap: 8px;
  padding: 6px 10px;
}

@media (any-hover: hover) {
  .nav-bar a:hover .nav-item,
  .nav-bar button:hover .nav-item {
    background-color: var(--w3-nav-hover-bg);
  }
}

/* The hamburger is a <button>, which does not inherit the page font the way
/* the anchors beside it do, and which UAs give their own metrics. w3-button
/* resets colour, border and background but not type, so do that here. */
.nav-bar button.w3-bar-item {
  font: inherit;
  line-height: inherit;
}

/* On small screens the labels are hidden and the bar items are icon-only, so
/* the icons carry the whole target -- size them up. 600px is W3's own small
/* breakpoint, the one w3-hide-small uses to drop the labels. The account
/* caret is in a button rather than a bar item, so it keeps its size. */
@media (max-width: 600px) {
  .nav-bar .w3-bar-item .nav-item .icon:not(.icon--logo) {
    --icon-size: 20px;
  }
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* The account control is an icon on its own. Font Awesome icons are text, so
/* without an explicit size it would inherit the body's 15px and sit far smaller
/* than the avatar it replaced. Sized to balance the 24px logo opposite it. */
.nav-account {
  margin-right: 8px;
}

/* Icon-only nav items -- account, vault, and the notes items -- share one
   size, so the bar reads as one row. At 1em an icon without a label sits
   small and high in its pill. */
.nav-account .icon,
.nav-action .icon {
  --icon-size: 26px;
}

/* Writebook's search glyph is solid and fills its box edge to edge, where
   the outlined Tabler ones leave a margin; at the same size it looks bigger.
   Shrink the glyph, not the box, so its pill matches its neighbours -- and
   as a percentage, so it holds at the small-screen size too. */
.nav-action .icon--search {
  mask-size: 80%;
}

/* W3 paints the whole dropdown container on hover; not on a bar like this. */
.nav-bar .w3-dropdown-click:hover {
  background-color: transparent;
}

/* Small-screen menu: no room for an underline, so mark the current page with
/* a left rule instead. */
#navDemo {
  background-color: var(--w3-ui-surface);
  border-bottom: 1px solid var(--w3-ui-border);
}

#navDemo .w3-bar-item.active {
  box-shadow: inset 2px 0 0 var(--w3-nav-underline);
  font-weight: 600;
}

/* Keep the menu's icons in step with the enlarged ones in the bar above it,
/* though a little smaller since these sit beside a label. */
#navDemo .nav-item .icon {
  --icon-size: 18px;
}

/* Settings sidebar
/* ---------------------------------------------------------------------------
 * GitHub's settings nav: a plain column, no card, each item an icon and label,
 * the current one on a light fill with a blue left rule.
 *
 * The items are w3-bar-item WITHOUT w3-button, so .w3-button:hover (which is
 * !important) cannot paint over the hover fill. That costs the text-decoration
 * reset w3-button would have brought, so it is set here.
 *
 * The accent is blue, not the navbar's orange -- GitHub uses the two
 * differently: orange for the profile tab strip, blue for settings.
 * -------------------------------------------------------------------------- */

.settings-nav .w3-bar-item {
  border-radius: 6px;
  color: var(--w3-ui-surface-on);
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  text-decoration: none;
}

.settings-nav .w3-bar-item.active {
  background-color: var(--w3-ui-stripe);
  box-shadow: inset 2px 0 0 var(--w3-accent);
  font-weight: 600;
}

/* Tabler's outline icons are drawn for a 24px box with a 2px stroke and carry
/* their own padding, so at the body's 1em they read smaller and thinner than
/* the Font Awesome glyphs they replaced. 20px restores the weight. */
.settings-nav .icon {
  --icon-size: 20px;
  color: var(--w3-text-grey);
}

@media (any-hover: hover) {
  .settings-nav .w3-bar-item:hover {
    background-color: var(--w3-nav-hover-bg);
  }
}

/* Hotwire's version of data-disable-with: swap the label while submitting. */
button .when-disabled,
input .when-disabled {
  display: none;
}
button[disabled] .when-disabled {
  display: initial;
}
button .when-enabled {
  display: initial;
}
button[disabled] .when-enabled {
  display: none;
}

/* Forms
/* -------------------------------------------------------------------------- */

/* W3 leaves labels unstyled; fields are w3-input/w3-select in the markup. */
label {
  display: inline-block;
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 600;
}

/* W3 gives the select no inline padding (padding: 9px 0), so its text and
 * caret sit on the box edge. Match .w3-input's 8px box. */
.w3-select {
  padding: 8px;
}

/* Tables
/* ---------------------------------------------------------------------------
 * GitHub's compact list chrome: a bordered, rounded box with a filled header
 * strip, hairline rules between rows and no zebra striping.
 *
 * w3-table still lays the table out and w3-responsive still handles the
 * horizontal scroll (and clips the rounded corners). This is only the part W3
 * has no class for: a styled thead, tighter cells, and a row hover that is not
 * W3's #ccc.
 * -------------------------------------------------------------------------- */

.table-list {
  background-color: var(--w3-ui-surface);
  border: 1px solid var(--w3-ui-border);
  border-radius: 6px;
  /* font-size: 14px; */
}

.table-list thead th {
  background-color: var(--w3-ui-stripe);
  border-bottom: 1px solid var(--w3-ui-border);
  color: var(--w3-text-grey);
  /* font-size: 12px; */
  font-weight: 600;
  padding: 8px 16px;
  vertical-align: middle;
  white-space: nowrap;
}

.table-list tbody td,
.table-list tbody th {
  padding: 8px 16px;
  vertical-align: middle;
}

/* Row header cells, e.g. the field names on an audit. */
.table-list tbody th {
  color: var(--w3-text-grey);
  font-weight: 600;
  white-space: nowrap;
}

/* A hairline between rows only -- thead already draws the first one. */
.table-list tbody tr:not(:first-child) td,
.table-list tbody tr:not(:first-child) th {
  border-top: 1px solid var(--w3-ui-border);
}

@media (any-hover: hover) {
  .table-list tbody tr:hover td {
    background-color: var(--w3-ui-stripe);
  }
}

/* Combobox
/* ---------------------------------------------------------------------------
 * Styles for app/javascript/combobox.js (the tom-select replacement). W3.CSS
 * has no autocomplete/combobox component, so this is carried over wholesale.
 * -------------------------------------------------------------------------- */

.combobox {
  --combobox-border-radius: 4px;
  --combobox-caret-size: 16px;
  --combobox-caret-inset: 10px;
  --combobox-font-size: 15px;
  --combobox-line-height: 22px;
  --combobox-list-max-block-size: 15rem;
  --combobox-z-list: 20;

  display: block;
  inline-size: 100%;
  position: relative;
}

/* The original field. It still carries the name and the submitted value, so it
/* stays in the DOM and out of the tab order rather than being removed. */
.combobox__value {
  block-size: 1px;
  /* The field also carries .w3-border, which is !important, so beat it here or
     the hidden original shows as a 1px bordered dot. */
  border: 0 !important;
  clip-path: inset(50%);
  inline-size: 1px;
  inset-block-start: 0;
  inset-inline-start: 0;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
}

.combobox__input {
  background-color: var(--w3-ui-surface);
  border: 1px solid var(--w3-ui-border);
  color: var(--w3-ui-surface-on);
  display: block;
  font-size: var(--combobox-font-size);
  font-weight: 400;
  inline-size: 100%;
  line-height: var(--combobox-line-height);
  padding: 8px;
  padding-inline-end: calc(
    var(--combobox-caret-size) + var(--combobox-caret-inset) * 2
  );

  &::placeholder {
    color: var(--w3-text-grey);
  }

  &:focus,
  &:focus-visible {
    border-color: var(--w3-dark-grey);
    outline: none;
  }

  &[disabled],
  &[readonly] {
    background: var(--w3-light-grey);
    color: var(--w3-text-grey);
    cursor: not-allowed;
  }
}

.combobox--error .combobox__input {
  background: var(--w3-danger-subtle);
  border-color: var(--w3-danger);
}

/* Caret / spinner
/* -------------------------------------------------------------------------- */

.combobox__caret {
  align-items: center;
  block-size: var(--combobox-caret-size);
  color: var(--w3-text-grey);
  cursor: pointer;
  display: flex;
  inline-size: var(--combobox-caret-size);
  inset-block-start: calc(50% - var(--combobox-caret-size) / 2);
  inset-inline-end: var(--combobox-caret-inset);
  justify-content: center;
  position: absolute;

  &::before {
    background-color: currentColor;
    block-size: 100%;
    content: "";
    display: block;
    inline-size: 100%;
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath stroke='black' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.75' d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
    mask-position: center;
    mask-repeat: no-repeat;
    mask-size: contain;
    transition: transform 150ms ease-out;
  }
}

.combobox--open .combobox__caret::before {
  transform: rotate(180deg);
}

.combobox--loading .combobox__caret::before {
  animation: combobox-spin 700ms linear infinite;
  mask-image: none;
  background-color: transparent;
  border: 2px solid var(--w3-ui-border);
  border-block-start-color: var(--w3-dark-grey);
  border-radius: 50%;
  transform: none;
}

@keyframes combobox-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .combobox__caret::before {
    transition: none;
  }

  .combobox--loading .combobox__caret::before {
    animation-duration: 2s;
  }
}

/* Listbox
/* -------------------------------------------------------------------------- */

.combobox__list {
  background: var(--w3-ui-surface);
  border: 1px solid var(--w3-ui-border);
  border-radius: var(--combobox-border-radius);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.16);
  inline-size: 100%;
  inset-block-start: calc(100% + 4px);
  inset-inline-start: 0;
  list-style: none;
  margin: 0;
  max-block-size: var(--combobox-list-max-block-size);
  overflow-y: auto;
  padding: 0;
  position: absolute;
  z-index: var(--combobox-z-list);
}

.combobox__option,
.combobox__empty {
  font-size: var(--combobox-font-size);
  line-height: var(--combobox-line-height);
  overflow: hidden;
  padding: 8px 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.combobox__option {
  color: var(--w3-ui-surface-on);
  cursor: pointer;
  user-select: none;
}

.combobox__option--active {
  background-color: var(--w3-ui-hover-bg);
  color: var(--w3-ui-hover-on);
}

@media (any-hover: hover) {
  .combobox__option:hover {
    background-color: var(--w3-ui-hover-bg);
    color: var(--w3-ui-hover-on);
  }
}

.combobox__option--create {
  font-style: italic;
}

.combobox__empty {
  color: var(--w3-text-grey);
  cursor: default;
}

/* Toasts
/* ---------------------------------------------------------------------------
 * Driven by the Alert stimulus controller. W3.CSS has panels but no stacked,
 * auto-dismissing notification region.
 * -------------------------------------------------------------------------- */

#toasts {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  position: fixed;
  right: 16px;
  top: 48px;
  z-index: 30;
  width: 100%;
  max-width: 384px;

  > * + * {
    margin-top: 16px;
  }
}

@media (max-width: 600px) {
  #toasts {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
}

.toast {
  background: var(--w3-ui-surface);
  color: var(--w3-ui-surface-on);
  display: flex;
  justify-content: space-between;
  padding: 16px;
  width: 100%;

  section:has(> header > svg) p {
    margin-left: 28px;
  }

  section header {
    align-items: center;
    display: flex;
    flex-grow: 1;
    gap: 8px;

    h2 {
      font-size: 15px;
      font-weight: 600;
      margin: 0;
    }
  }

  p {
    font-size: 15px;
    margin: 4px 0 0;
  }

  > div {
    align-items: flex-start;
    display: flex;
    gap: 16px;

    button {
      background: none;
      border: 0;
      cursor: pointer;
      padding: 0;
    }
  }
}

/* Bar chart
/* ---------------------------------------------------------------------------
 * Pure-CSS chart rendered by app/views/dashboard/_bar_chart.html.erb.
 * -------------------------------------------------------------------------- */

.bar-chart {
  --bar-chart-height: 16rem;

  display: flex;
  flex-direction: column;
  margin: 0;
  width: 100%;
}

.bar-chart__body {
  display: flex;
  gap: 6px;
}

.bar-chart__axis {
  flex: none;
  height: var(--bar-chart-height);
  position: relative;
  width: 3rem;
}

.bar-chart__tick {
  color: var(--w3-text-grey);
  font-size: 11px;
  line-height: 1;
  position: absolute;
  right: 0;
  transform: translateY(50%);
  white-space: nowrap;
}

.bar-chart__area {
  flex: 1;
  min-width: 0;
}

.bar-chart__plot {
  align-items: flex-end;
  border-bottom: 1px solid var(--w3-ui-border);
  border-left: 1px solid var(--w3-ui-border);
  display: flex;
  gap: 2px;
  height: var(--bar-chart-height);
  position: relative;
}

.bar-chart__gridline {
  border-top: 1px dashed var(--w3-ui-border);
  left: 0;
  opacity: 0.6;
  position: absolute;
  right: 0;
}

.bar-chart__col {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
  position: relative;

  &:hover .bar-chart__bar {
    opacity: 0.75;
  }
}

.bar-chart__bar {
  background: var(--w3-accent);
  border-radius: 2px 2px 0 0;
  min-height: 1px;

  &.bar-chart__bar--negative {
    background: var(--w3-danger);
  }
}

.bar-chart__labels {
  display: flex;
  gap: 2px;
  margin-top: 4px;
}

.bar-chart__label {
  color: var(--w3-text-grey);
  flex: 1;
  font-size: 11px;
  min-width: 0;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Pagination
/* ---------------------------------------------------------------------------
 * Markup comes from pagy's series_nav helper, so it cannot carry w3- classes.
 * -------------------------------------------------------------------------- */

nav.pagy {
  display: inline-flex;
  align-items: center;
  justify-content: start;

  a {
    background: var(--w3-ui-surface);
    border: 1px solid var(--w3-ui-border);
    color: var(--w3-ui-surface-on);
    display: block;
    font-variant-numeric: tabular-nums;
    margin-left: -1px;
    padding: 8px 12px;
    position: relative;
    text-decoration: none;

    &:hover {
      background: var(--w3-ui-hover-bg);
      color: var(--w3-ui-hover-on);
    }

    &:not([href]) {
      color: var(--w3-text-grey);
    }

    &[aria-current="page"] {
      background: var(--w3-black);
      border-color: var(--w3-black);
      color: var(--w3-black-on);
    }
  }
}

/* Modal
/* ---------------------------------------------------------------------------
 * The remote modal is a native <dialog> driven by the Modal stimulus
 * controller (showModal/close), not W3's JS-toggled .w3-modal div, so it needs
 * its own sizing and backdrop. The card inside it uses w3- classes.
 * -------------------------------------------------------------------------- */

dialog.modal {
  border: 0;
  margin: auto;
  max-height: 100vh;
  padding: 0;
  width: 100%;

  &.modal-sm {
    max-width: 384px;
  }

  &.modal-md {
    max-width: 448px;
  }

  &.modal-lg {
    max-width: 512px;
  }

  &::backdrop {
    background: #000;
    opacity: 0.5;
  }

  .modal-close {
    background: none;
    border: 0;
    color: var(--w3-text-grey);
    cursor: pointer;
    position: absolute;
    right: 16px;
    top: 16px;

    &:hover {
      color: var(--w3-ui-surface-on);
    }
  }
}

/* Hub launcher
/* ---------------------------------------------------------------------------
 * Home is a page of space cards, not a bar: each space owns the whole window
 * once you are inside it, and the card is the way in. Layout follows
 * docs/hub-launcher-mockups (greeting, card grid, verb link at the card's
 * foot); the colours and type are this app's, driven by the same --w3-* hooks
 * as everything else, so the launcher does not read as a second design.
 *
 * The grid itself is w3-row-padding/w3-col in the markup. This is only the
 * card, its icon chip and the dashed placeholder.
 * -------------------------------------------------------------------------- */

.launcher {
  margin: 0 auto;
  max-width: 1000px;
}

.launcher-head {
  align-items: flex-end;
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
  padding: 0 8px;
}

.launcher-greeting {
  font-size: 32px;
  font-weight: 600;
  line-height: 1.15;
  margin: 0 0 4px;
}

.launcher-date {
  color: var(--w3-text-grey);
  font-size: 14px;
  margin: 0;
}

/* w3-col floats, so columns would only be as tall as their own contents and
/* the cards in a row would not line up. Flex keeps the percentage widths the
/* w3-col classes set while stretching every column to the tallest. */
.launcher-grid {
  display: flex;
  flex-wrap: wrap;
}

/* The card is a link plus a second, separate link for the verb, so the whole
/* card stays clickable without nesting anchors. */
.space-card {
  background: var(--w3-ui-surface);
  border: 1px solid var(--w3-ui-border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 168px;
  padding: 20px;
}

.space-card__body {
  color: inherit;
  display: block;
  flex-grow: 1;
  text-decoration: none;
  text-align: center;
}

.space-card__name {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
}

@media (any-hover: hover) {
  .space-card:hover {
    border-color: var(--w3-text-grey);
  }
}

.space-chip {
  --icon-size: 32px;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 10px;
  background: var(--w3-ui-stripe);
  color: var(--w3-text-grey);
}

/* Closes the grid. Not a link until there is somewhere to send it. */
.space-card--empty {
  align-items: center;
  background: none;
  border-style: dashed;
  color: var(--w3-text-grey);
  gap: 10px;
  justify-content: center;
}

.space-card--empty .icon {
  --icon-size: 20px;
}

/* Search result highlighting
/* ---------------------------------------------------------------------------
 * SQLite FTS5 marks the matched terms; Notes::SearchIndex returns them wrapped
 * in control characters and NotesHelper#notes_highlight promotes those to
 * <mark> after escaping. W3.CSS has no <mark> style of its own.
 * -------------------------------------------------------------------------- */

mark {
  background: var(--w3-attention-subtle);
  color: inherit;
  border-radius: 2px;
  padding-inline: 1px;
}

/* The notes search dialog, after Writebook's: a roomy rounded panel near
   the top of the window, a big input with the icon inside its border, and a
   round black go button. Pinned high so it does not jump about as results
   come and go. */
.search-dialog {
  background: none;
  border: 0;
  inline-size: min(80ch, calc(100% - 2rem));
  margin: 12vh auto auto;
  max-block-size: 80vh;
  max-inline-size: none;
  overflow-y: auto;
  padding: 0;

  &::backdrop {
    background: rgb(0 0 0 / 0.45);
  }
}

.search-dialog__panel {
  background: #fff;
  border-radius: 1rem;
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.25);
  padding: 2rem;
  position: relative;
}

.search-dialog__close {
  --icon-size: 18px;

  background: none;
  border: 0;
  color: var(--w3-ui-surface-on);
  cursor: pointer;
  display: inline-flex;
  inset: 0.6rem 0.6rem auto auto;
  padding: 0.4rem;
  position: absolute;
}

.search-dialog__form {
  align-items: center;
  display: flex;
  gap: 1rem;
}

.search-dialog__field {
  --icon-size: 24px;

  align-items: center;
  border: 1px solid var(--w3-ui-border);
  border-radius: 0.5rem;
  display: flex;
  flex: 1;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  transition:
    box-shadow 150ms ease,
    border-color 150ms ease;

  &:focus-within {
    border-color: #6ea8fe;
    box-shadow: 0 0 0 3px rgb(110 168 254 / 0.45);
  }

  input {
    background: none;
    border: 0;
    flex: 1;
    font-size: 1.5rem;
    /* w3.css bolds label text, and this input sits inside one. */
    font-weight: normal;
    min-inline-size: 0;
    outline: none;
    padding: 0;
  }

  /* Escape closes the dialog, and the arrow button sits right beside this;
     the browser's own clear button is one control too many. */
  input::-webkit-search-cancel-button {
    display: none;
  }
}

.search-dialog__submit {
  --icon-size: 24px;

  align-items: center;
  background: var(--w3-ui-surface-on);
  block-size: 3rem;
  border: 0;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  flex-shrink: 0;
  inline-size: 3rem;
  justify-content: center;
}

.search-dialog__hint {
  color: var(--w3-text-grey);
  font-size: 0.8rem;
  margin: 0.75rem 0 0;
}

#search_results .search__list {
  margin-block-start: 1rem;
}

/* The title picker's results: one line per note, no excerpt -- a list to
   jump from, not to read. */
.picker__list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}

.picker__result {
  border-radius: 0.5rem;
  color: var(--w3-ui-surface-on);
  display: block;
  font-size: 1.1rem;
  overflow: hidden;
  padding: 0.5rem 0.75rem;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;

  &:hover,
  &:focus-visible {
    background: var(--w3-accent-subtle);
    outline: none;
  }
}

/* The vault dialog: the search dialog's panel, narrower, holding a
   passphrase form or the lock and change-passphrase buttons. */
.vault-dialog {
  inline-size: min(44ch, calc(100% - 2rem));
}

.vault-dialog__title {
  align-items: center;
  display: flex;
  gap: 0.5rem;
  margin-block-start: 0;
}

.vault-dialog__actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;

  input[type="password"] {
    flex: 1;
    min-inline-size: 12rem;
  }

  form {
    display: inline-block;
  }
}

/* A note opened from search says what it is highlighting, with a way out. */
.search__banner {
  align-items: center;
  background: var(--w3-attention-subtle);
  border-radius: 1.5em;
  display: flex;
  gap: 0.5em;
  inline-size: fit-content;
  margin: 0 auto 1rem;
  padding: 0.3em 0.6em 0.3em 1em;

  a {
    color: inherit;
    display: inline-flex;
  }
}

/* Search results
 * ---------------------------------------------------------------------------
 * Modelled on Fizzy's searches/_result: the whole result is the link, with an
 * underlined title, a two-line excerpt and a translucent meta line. The
 * hairline outline drops away on hover so the block reads as one target.
 * -------------------------------------------------------------------------- */

.search__list {
  display: grid;
  gap: 1rem;
  list-style: none;
  margin: 0 auto;
  max-inline-size: min(80ch, 100%);
  padding: 0;
}

.search__result {
  color: var(--w3-accent);
  display: block;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  text-decoration: none;
}

.search__result:not(:hover) {
  box-shadow: 0 0 0 1px var(--w3-ui-border);
}

.search__result:hover {
  background-color: var(--w3-ui-stripe);
}

/* The arrow keys move real focus rather than a rendered highlight, so this is
   the keyboard's selected result. It has to read at least as strongly as
   hover, and it drops the hairline because the ring has replaced it. */
.search__result:focus-visible {
  background-color: var(--w3-ui-stripe);
  box-shadow: none;
  outline: 2px solid var(--w3-accent);
  outline-offset: 2px;
}

.search__title {
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.3;
  margin: 0;
  text-decoration: underline;
}

.search__lock {
  --icon-size: 15px;
  margin-inline-start: 0.35rem;
  vertical-align: baseline;
}

.search__excerpt {
  color: var(--w3-ui-surface-on);
  font-size: 0.9rem;
  margin-block-start: 0.25rem;

  /* -webkit-box is still the only cross-browser line clamp. */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}

/* The notes index, after writebook: a grid of thumbnails -- each note's
   opening rendered small -- or a list of titles with their dates. The header's
   radios pick one, and :has() does the switching, so there is no JavaScript
   in it; the remember controller only keeps the choice in a cookie. */
.toc {
  display: grid;
  gap: 1.5rem 1rem;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc__note {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  text-align: center;
}

/* A portrait page. Its text scales with the card, as writebook's does.
   .notes-body sizes headings and code in rem, which would not shrink with
   it, so they are restated in em -- with both classes, to outrank the
   .notes-body rules later in the file. */
.notes-body.toc__thumbnail {
  aspect-ratio: 6 / 9;
  border: 1px solid var(--w3-ui-border);
  border-radius: 0.3em;
  color: var(--w3-ui-surface-on);
  display: block;
  font-size: clamp(0.5rem, 5cqi, 0.8rem);
  line-height: 1.4;
  margin-block-end: 0.5rem;
  overflow: hidden;
  padding: 10cqi;
  text-align: start;
  text-decoration: none;

  &:hover {
    border-color: var(--w3-accent);
  }

  h1 {
    font-size: 1.7em;
  }
  h2 {
    font-size: 1.4em;
  }
  h3 {
    font-size: 1.2em;
  }
  h4 {
    font-size: 1.05em;
  }
  pre {
    padding: 0.5em 0.75em;
  }
  pre code {
    font-size: 0.85em;
  }
  :is(th, td) {
    padding: 0.25em 0.5em;
  }
  .anchor::after {
    content: none;
  }
}

.toc__private {
  --icon-size: 2rem;
  align-items: center;
  block-size: 100%;
  color: var(--w3-text-grey);
  display: flex;
  justify-content: center;
}

.toc__title {
  color: inherit;
  display: flex;
  font-weight: 700;
  line-height: 1.2;
  min-inline-size: 0;
  text-decoration: none;
}

.toc__title-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc__updated {
  color: var(--w3-text-grey);
  white-space: nowrap;
}

.toc__updated {
  display: none;
}

/* List view: one row per note, title then dotted leader then date. */
.toc__container:has(#toc-list:checked) {
  .toc {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .toc__note {
    align-items: baseline;
    column-gap: 1ch;
    flex-direction: row;
    text-align: start;
  }

  .toc__thumbnail {
    display: none;
  }

  .toc__updated {
    display: inline;
  }

  .toc__title {
    flex: 1;
    font-weight: 400;

    &:hover {
      text-decoration: underline;
    }

    &::after {
      border-block-end: 1px dotted var(--w3-ui-border);
      content: "";
      flex: 1;
      margin-block-end: 0.25em;
      margin-inline-start: 1ch;
    }
  }

  .toc__title-text {
    flex: 0 1 auto;
  }
}

/* The toggle: round icon buttons, the chosen one filled. The radio is
   hidden visually but stays focusable, so the arrow keys still switch. */
.toc__views {
  display: flex;
  gap: 0.25rem;
}

.toc__view {
  --icon-size: 18px;
  align-items: center;
  border: 1px solid var(--w3-ui-border);
  border-radius: 50%;
  block-size: 2.25rem;
  cursor: pointer;
  display: inline-flex;
  inline-size: 2.25rem;
  justify-content: center;
  position: relative;

  input {
    inset: 0;
    margin: 0;
    opacity: 0;
    position: absolute;
  }

  &:has(input:checked) {
    background-color: var(--w3-ui-surface-on);
    color: #fff;
  }

  &:has(input:focus-visible) {
    outline: 2px solid var(--w3-accent);
    outline-offset: 2px;
  }
}

.search__private {
  color: var(--w3-text-grey);
  font-style: italic;
}

.search__meta {
  color: var(--w3-ui-surface-on);
  font-size: 0.85rem;
  margin-block-start: 0.35rem;
  opacity: 0.66;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The Markdown editor: a plain textarea, borderless under the toolbar's
   hairline as in flatnotes. Monospace because what is typed is Markdown, and
   the alignment of a list or a table matters while writing it. */
.notes-editor {
  background: none;
  border: 0;
  color: inherit;
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  inline-size: 100%;
  line-height: 1.7;
  max-block-size: 60vh;
  outline: none;
  overflow-y: auto;
  padding: 0;

  /* The controller sizes it to the window; dragging it by the corner would
     only fight that on the next resize. */
  resize: none;
  tab-size: 2;

  &::placeholder {
    color: var(--note-very-muted);
  }

  /* display: block above would otherwise beat the hidden attribute, which
     is how the Preview tab puts the textarea away. */
  &[hidden] {
    display: none;
  }
}

/* The note page, after flatnotes: its light palette on a white page. Not a
   tinted background -- what makes it easy on the eyes is slate text rather
   than black, muted grey chrome, and pale code and borders. Values are
   flatnotes' own theme variables. */
.note-page {
  --note-text: #2c3139;
  --note-muted: #8891a1;
  --note-very-muted: #c1c7d0;
  --note-elevated: #f3f4f5;
  --note-border: #eceef0;
  --note-accent: #f8a66b;

  color: var(--note-text);
}

/* Title on the left; Delete, Save and the Edit switch on the right. */
.note-bar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  justify-content: space-between;
  margin-block-end: 1rem;
}

.note-bar__title {
  background: none;
  border: 0;
  color: inherit;
  flex: 1 1 20rem;
  font-size: 2.25rem;
  font-weight: 400;
  line-height: 1.25;
  margin: 0;
  min-inline-size: 0;
  outline: none;
  padding: 0;
}

.note-bar__title::placeholder {
  color: var(--note-very-muted);
}

.note-bar__private {
  --icon-size: 0.9rem;

  color: var(--note-muted);
  font-size: 0.9rem;
  vertical-align: middle;
  white-space: nowrap;
}

.note-bar__actions {
  align-items: center;
  display: flex;
  gap: 1.5rem;
}

.note-bar__form {
  display: contents;
}

.note-bar__action,
.note-bar__mode {
  --icon-size: 20px;

  align-items: center;
  background: none;
  border: 0;
  color: var(--note-muted);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-size: 1.1rem;
  gap: 0.4rem;
  padding: 0;
  text-decoration: none;

  &:hover,
  &:focus-visible {
    color: var(--note-text);
  }
}

/* The Edit switch: a track with a sliding knob, flatnotes orange when on.
   It is decoration inside the .note-bar__mode link, which takes the click. */
.switch {
  background: var(--note-very-muted, #c1c7d0);
  block-size: 1.3rem;
  border-radius: 2rem;
  display: inline-block;
  inline-size: 2.4rem;
  position: relative;
  transition: background-color 150ms ease;

  &.switch--on {
    background: var(--note-accent, #f8a66b);
  }
}

.switch__btn::before {
  background: #fff;
  block-size: 0.95rem;
  border-radius: 50%;
  content: "";
  inline-size: 0.95rem;
  inset-block-start: 0.175rem;
  inset-inline-start: 0.2rem;
  position: absolute;
  transition: transform 150ms ease;
}

/* Written out, not nested: & cannot stand for a pseudo-element, so
   `.switch--on &` inside the ::before rule is dropped by the browser. */
.switch--on .switch__btn::before,
.switch__input:checked + .switch .switch__btn::before {
  transform: translateX(1.05rem);
}

/* A real checkbox behind the drawn switch -- the new note's Encrypt. It
   stays in the page for the form and the keyboard, out of sight; :checked
   turns the drawn switch on the way .switch--on does for the links. */
.switch__input {
  opacity: 0;
  pointer-events: none;
  position: absolute;

  &:checked + .switch {
    background: var(--note-accent, #f8a66b);
  }

  &:focus-visible + .switch {
    outline: 2px solid var(--note-muted, #8891a1);
    outline-offset: 2px;
  }
}

/* Encrypt with the vault locked: shown, so the option is discoverable, but
   not usable; the title says why. */
.note-bar__mode.is-disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

/* The formatting bar: thin grey icons in groups, a rule between groups,
   and a hairline under the whole row, as in flatnotes. */
.md-toolbar {
  align-items: center;
  border-block-end: 1px solid var(--note-border);
  display: flex;
  gap: 0.25rem;
  margin-block-end: 0.75rem;
  overflow-x: auto;
  padding-block: 0.25rem 0.5rem;
  scrollbar-width: none;

  button {
    --icon-size: 22px;

    align-items: center;
    background: none;
    border: 0;
    border-radius: 0.375rem;
    color: var(--note-muted);
    cursor: pointer;
    display: inline-flex;
    flex-shrink: 0;
    padding: 0.35rem 0.45rem;

    &:hover,
    &:focus-visible {
      background: var(--note-elevated);
      color: var(--note-text);
    }
  }
}

.md-toolbar__buttons {
  align-items: center;
  display: flex;
  gap: 0.25rem;
  margin-inline-start: 1rem;

  /* Formatting has nothing to act on while previewing. */
  .is-previewing & {
    visibility: hidden;
  }
}

/* Write / Preview, as flatnotes draws them: small bordered tabs, the
   current one white, the other on the pale grey. */
.md-toolbar__tabs {
  display: flex;
  flex-shrink: 0;

  button {
    background: var(--note-elevated);
    border: 1px solid var(--note-border);
    color: var(--note-muted);
    cursor: pointer;
    font: inherit;
    font-size: 0.85rem;
    padding: 0.35rem 1.1rem;

    &:first-child {
      border-radius: 0.25rem 0 0 0.25rem;
    }

    &:last-child {
      border-inline-start: 0;
      border-radius: 0 0.25rem 0.25rem 0;
    }

    &[aria-selected="true"] {
      background: #fff;
      color: var(--note-text);
    }

    &:focus-visible {
      outline: 2px solid var(--note-muted);
      outline-offset: -2px;
    }
  }
}

.md-preview {
  overflow-y: auto;
}

.md-preview__status {
  color: var(--note-muted);
}

.md-toolbar__rule {
  background: var(--note-very-muted);
  block-size: 1.4rem;
  flex-shrink: 0;
  inline-size: 1px;
  margin-inline: 0.5rem;
}

/* A rendered note. The Markdown renderer emits plain semantic HTML, so this
   is ordinary prose styling -- nothing here knows it came from Markdown. */
.notes-body :is(h1, h2, h3, h4, h5, h6) {
  font-weight: 600;
  line-height: 1.25;
  margin-block: 1.4em 0.5em;
}

.notes-body > :first-child {
  margin-block-start: 0;
}

.notes-body h1 {
  font-size: 1.7rem;
}
.notes-body h2 {
  font-size: 1.4rem;
}
.notes-body h3 {
  font-size: 1.2rem;
}
.notes-body h4 {
  font-size: 1.05rem;
}

.notes-body p,
.notes-body ul,
.notes-body ol,
.notes-body blockquote,
.notes-body pre,
.notes-body table {
  margin-block: 0 1em;
}

.notes-body :is(ul, ol) {
  padding-inline-start: 1.5rem;
}

.notes-body li {
  margin-block: 0.15em;
}

/* Task lists: the checkbox replaces the bullet rather than sitting beside it. */
.notes-body li:has(> input[type="checkbox"]) {
  list-style: none;
  margin-inline-start: -1.2rem;
}

.notes-body input[type="checkbox"] {
  margin-inline-end: 0.4rem;
}

.notes-body blockquote {
  border-inline-start: 3px solid var(--note-very-muted, #ccc);
  color: var(--note-muted, var(--w3-text-grey));
  padding-inline-start: 1rem;
}

.notes-body code {
  background: var(--note-elevated, #f2f2f2);
  border-radius: 3px;
  font-size: 0.9em;
  padding: 0.1em 0.3em;
}

/* Fenced blocks carry their own colours inline, from the renderer's
   highlighter, so only the box is ours. */
/* flatnotes' pale grey block, no border. !important because the highlighter
   writes its theme's white background inline on every <pre>; its token
   colours read the same on this grey. */
.notes-body pre {
  background: var(--note-elevated, #f3f4f5) !important;
  border-radius: 4px;
  overflow-x: auto;
  padding: 0.75rem 1rem;
}

.notes-body pre code {
  background: none;
  font-size: 0.85rem;
  padding: 0;
}

.notes-body table {
  border-collapse: collapse;
}

.notes-body :is(th, td) {
  border: 1px solid var(--note-border, var(--w3-ui-border));
  padding: 0.35rem 0.7rem;
  text-align: start;
}

.notes-body img {
  max-inline-size: 100%;
}

/* The renderer links every heading to itself. Keep the anchor out of the way
   until the heading is hovered. */
.notes-body :is(h1, h2, h3, h4, h5, h6) .anchor::after {
  color: var(--w3-text-grey);
  content: "#";
  font-weight: 400;
  margin-inline-start: 0.35rem;
  opacity: 0;
}

.notes-body :is(h1, h2, h3, h4, h5, h6):hover .anchor::after {
  opacity: 0.5;
}

.toc__filter {
  inline-size: 14rem;
  padding-block: 0.4rem;
}
