/* Tags choose the order. The two rails keep their existing window boundaries. */
.tag-desktop .desktop-rail-heading,
.tag-desktop .tag-toolbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  height: auto;
  min-height: 36px;
  padding: 5px 6px;
  border-bottom: 1px solid #ffffff20;
  background: #10221c85;
}

.tag-desktop :is(.tag-favorites, .rail-tabs) {
  display: flex;
  flex: 1 1 0;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
  min-width: 0;
}

.tag-desktop :is(.tag-favorites, .rail-tabs) > button {
  flex: 1 1 60px;
  min-width: 60px;
  min-height: 25px;
  padding: 4px 5px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 4px;
  color: #bfceb6;
  background: transparent;
  font: 500 11px/1.3 "Segoe UI", Arial, sans-serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-desktop :is(.tag-chip, .tag-favorites > button, .rail-tabs > button)[aria-pressed="true"] {
  border-color: #b4c79488;
  background: #b4c79429;
  color: #edf4df;
}

.tag-desktop :is(.tag-chip, .tag-favorites > button, .rail-tabs > button):hover {
  border-color: #b4c79465;
  background: #ffffff12;
  color: #edf4df;
}

.tag-desktop :is(.tag-chip, .tag-pin, .tag-options, .tag-clear, .tag-favorites > button, .rail-tabs > button):focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

.tag-desktop .tag-options {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 25px;
  padding: 4px 6px;
  border: 1px solid #ffffff2d;
  border-radius: 4px;
  background: #ffffff05;
  color: #bdcbb4;
  font-size: 11px;
  line-height: 1.3;
}

.tag-desktop .tag-options[aria-expanded="true"] {
  border-color: #b4c79480;
  background: #b4c7941c;
  color: #e2ecd4;
}

.tag-desktop .tag-palette {
  flex: 0 0 auto;
  min-width: 0;
  max-height: min(260px, 38dvh);
  padding: 7px;
  overflow: auto;
  border-bottom: 1px solid #ffffff24;
  background: #14271fea;
  scrollbar-width: thin;
  scrollbar-color: #9aac8b70 transparent;
  overscroll-behavior: contain;
}

.tag-desktop .tag-palette-list {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 5px;
}

.tag-desktop .tag-chip-group {
  display: inline-flex;
  align-items: stretch;
  max-width: 100%;
}

.tag-desktop .tag-chip-group > .tag-chip {
  min-width: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.tag-desktop .tag-pin {
  display: inline-flex;
  flex: 0 0 23px;
  align-items: center;
  justify-content: center;
  width: 23px;
  min-height: 25px;
  padding: 2px;
  border: 1px solid #ffffff26;
  border-left: 0;
  border-radius: 0 4px 4px 0;
  background: #ffffff04;
  color: #92a187;
  font-size: 13px;
  line-height: 1;
}

.tag-desktop .tag-pin[aria-pressed="true"] {
  background: #b4c79418;
  color: #e0eab6;
}

.tag-desktop .tag-pin:hover {
  background: #ffffff16;
  color: #edf4df;
}

.tag-desktop .tag-filter {
  display: block;
  width: 100%;
  min-width: 0;
  margin: 0 0 7px;
  padding: 7px 8px;
  border: 1px solid #ffffff30;
  border-radius: 4px;
  background: #10221c;
  color: #e3ebdb;
  font-size: 11px;
  line-height: 1.3;
}

.tag-desktop .tag-filter::placeholder {
  color: #a2b398;
}

.tag-desktop .tag-filter:focus-visible {
  border-color: var(--accent);
  outline-offset: 1px;
}

.tag-desktop .tag-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 25px;
  max-width: 100%;
  padding: 4px 7px;
  border: 1px solid #ffffff26;
  border-radius: 4px;
  background: #ffffff04;
  color: #bdcbb4;
  font-size: 11px;
  line-height: 1.3;
  text-align: left;
  overflow-wrap: anywhere;
}

.tag-desktop .tag-chip small {
  color: #a1b294;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.tag-desktop .tag-selection {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
  max-height: 96px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 5px 7px;
  border-bottom: 1px solid #ffffff17;
  background: #10221c50;
  color: #b3c2aa;
  font-size: 10px;
  line-height: 1.3;
}

.tag-desktop .tag-selection .tag-chip {
  min-height: 22px;
  padding: 2px 5px;
  border-color: #b4c79470;
  background: #b4c79416;
  font-size: 10px;
}

.tag-desktop .tag-clear {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 4px;
  color: #b9c7af;
  font-size: 10px;
  line-height: 1.3;
  text-decoration: underline;
  text-decoration-color: #ffffff38;
  text-underline-offset: 2px;
}

.tag-desktop .tag-clear:hover {
  color: #eff4e4;
  text-decoration-color: currentColor;
}

.tag-desktop .tag-rail-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-left: auto;
}

.tag-desktop .tag-rail-actions > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 23px;
  height: 22px;
  padding: 3px;
  border: 1px solid #ffffff26;
  border-radius: 3px;
  background: #ffffff05;
  color: #c6d5bd;
  font-size: 13px;
  line-height: 1;
}

.tag-desktop .tag-rail-actions > button:hover:not(:disabled) {
  border-color: #bdcea872;
  background: #bdd1a526;
  color: #e4eedb;
}

.tag-desktop .tag-rail-actions > button:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

.tag-desktop .tag-rail-actions > button:disabled {
  border-color: transparent;
  background: transparent;
  opacity: .35;
}

.tag-desktop .tag-rail-actions svg {
  display: block;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tag-desktop .rail-panels {
  gap: 10px;
  padding: 7px 8px 10px;
}

.tag-desktop .tag-frame.desktop-frame {
  width: 314px;
  max-width: 100%;
  padding: 3px;
  border: 1px solid #b8caaa65;
  border-radius: 5px;
  background: #14291f80;
  box-shadow: 0 1px 4px #0002;
}

.tag-desktop .tag-frame:focus-within {
  border-color: #c0d3a7b0;
}

.tag-desktop .tag-frame.is-collapsed {
  height: auto;
  min-height: 29px;
}

.tag-desktop .tag-frame .frame-heading {
  position: static;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  min-height: 23px;
  padding: 0 3px;
  pointer-events: auto;
}

.tag-desktop .tag-frame .frame-heading h2 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 0;
  background: transparent;
  color: #d0ddc5;
  font-size: 11px;
  font-weight: 500;
  line-height: 21px;
}

.tag-desktop .tag-frame .frame-title {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  min-width: 0;
  min-height: 23px;
  padding: 1px 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  pointer-events: auto;
}

.tag-desktop .tag-frame .frame-title:hover {
  color: #f0f5e8;
}

.tag-desktop .tag-frame .frame-title > span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.tag-desktop .tag-frame .frame-title:focus-visible {
  outline-offset: 1px;
}

.tag-desktop .tag-frame :is(.tag-frame-count, .frame-count) {
  flex: 0 0 auto;
  min-width: 16px;
  color: #9dae92;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.tag-desktop .tag-frame .frame-icons,
.tag-desktop .tag-frame.is-expanded .frame-icons {
  display: grid;
  grid-auto-flow: row;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: none;
  grid-auto-columns: auto;
  grid-auto-rows: 84px;
  gap: 2px 6px;
  min-width: 0;
  max-height: none;
  padding: 2px 0;
  overflow: visible;
  scroll-snap-type: none;
}

.tag-desktop .tag-frame .frame-icons .desktop-icon {
  width: 100%;
  min-width: 0;
  height: 84px;
  padding: 4px 2px;
  border-radius: 5px;
  font-size: 11px;
  line-height: 1.3;
  overflow: hidden;
}

.tag-desktop .tag-frame .frame-icons .glyph {
  width: 50px;
  height: 40px;
  margin: 0 auto 4px;
}

.tag-desktop .tag-frame .desktop-icon > span:last-child:not(.glyph) {
  display: block;
  max-height: 30px;
  overflow: hidden;
}

.tag-desktop .tag-empty {
  margin: 4px 2px;
  color: #bdcbb4;
  font-size: 11px;
  line-height: 1.5;
}

/* Hidden always wins over the legacy grid and flex declarations. */
.tag-desktop :is(.tag-palette, .tag-selection, .tag-frame, .frame-icons)[hidden] {
  display: none !important;
}

@media (max-width: 740px) {
  .tag-desktop .tag-palette {
    max-height: 220px;
  }

  .tag-desktop .rail-panels {
    padding-bottom: 8px;
  }
}

@media (max-width: 360px) {
  .tag-desktop .desktop-rail-heading,
  .tag-desktop .tag-toolbar {
    gap: 3px;
    padding-inline: 4px;
  }

  .tag-desktop :is(.tag-favorites, .rail-tabs) {
    gap: 1px;
  }

  .tag-desktop :is(.tag-favorites, .rail-tabs) > button {
    padding-inline: 3px;
    font-size: 10.5px;
  }

  .tag-desktop .tag-options {
    padding-inline: 4px;
    font-size: 10.5px;
  }

  .tag-desktop .tag-frame .frame-icons {
    gap: 2px 3px;
  }

  .tag-desktop .tag-frame .frame-icons .desktop-icon {
    font-size: 10.5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tag-desktop .tag-chip,
  .tag-desktop .tag-options,
  .tag-desktop .tag-clear {
    transition: none;
  }
}
