/* static/style.css */
:root {
  color-scheme: dark;
  --bg: #05070b;
  --bg-panel: #0b0f14;
  --border: #1a2330;
  --accent: #3ea8ff;
  --accent-soft: rgba(62, 168, 255, 0.18);
  --text: #e3ecff;
  --text-muted: #9bacce;
  --radius: 12px;
  --pad: 10px;
  --transition: 0.14s ease;
  font-size: 14px;

  /* iOS safe-area padding (notch / split view) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top, #09101a 0, #05070b 50%, #020309 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;

  /* ✅ kill any accidental horizontal overflow wobble */
  overflow-x: hidden;
}

/* Prefer clip when supported (prevents creating a scrollable overflow context) */
@supports (overflow-x: clip) {
  html,
  body {
    overflow-x: clip;
  }
}

/* ---------------- Toolbar: search-first ---------------- */

#toolbar {
  position: sticky;
  top: 0;
  z-index: 100;

  padding: calc(6px + var(--safe-top)) calc(10px + var(--safe-right)) 6px
    calc(10px + var(--safe-left));

  background: linear-gradient(
    180deg,
    rgba(9, 14, 24, 0.98),
    rgba(9, 14, 24, 0.96),
    rgba(9, 14, 24, 0.9)
  );
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

#toolbar-top {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#toolbar .row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

/* ✅ Search-only top row: NEVER WRAPS */
.row-top {
  align-items: center !important;
  flex-wrap: nowrap !important;
}

.top-search {
  flex: 1 1 auto;
  min-width: 0; /* critical: stop iOS wrap explosions */
  width: auto;
  border-radius: 999px;
  padding: 8px 14px;
}

.btn.chip {
  border-radius: 999px;
  padding: 8px 10px;
  min-height: 34px;
  line-height: 1;
  opacity: 0.92;
}

.btn.chip.icon {
  width: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

/* ✅ Menu drawer (scroll-capped so it can't eat viewport) */
.menu-drawer {
  margin-top: 2px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 14px;
  background: rgba(6, 9, 19, 0.78);
  box-shadow: inset 0 0 20px rgba(255,255,255,0.03);

  /* hard cap */
  max-height: min(70vh, 640px);
  max-height: min(70svh, 640px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.menu-drawer[hidden] {
  display: none !important;
}

.row-menu-actions {
  align-items: center !important;
  flex-wrap: wrap;
  gap: 8px;
}

/* Controls section (collapsible, inside menu) */
#toolbar-controls {
  margin-top: 10px;

  /* cap + internal scroll so controls never become a wall */
  max-height: min(56vh, 560px);
  max-height: min(56svh, 560px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;

  padding-bottom: 6px;
}

#toolbar-controls[hidden] {
  display: none !important;
}

/* Toolbar drawers (filters area + plugins panel) */
#filters-wrap {
  margin-top: 10px;

  max-height: min(40vh, 340px);
  max-height: min(40svh, 340px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

#filters-wrap[hidden] {
  display: none !important;
}

/* ---------------- Form fields ---------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: min(360px, 100%);
}

.field.smallfield {
  min-width: min(220px, 100%);
}

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

input[type="text"],
input[type="search"],
select {
  min-width: 260px;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #050913;
  color: var(--text);
  outline: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", monospace;
  font-size: 13.5px;
}

input[type="text"]:focus,
input[type="search"]:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

/* ---------------- Buttons ---------------- */

.btn {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #050913;
  color: var(--text);
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  transition: background var(--transition), border-color var(--transition),
    transform var(--transition), box-shadow var(--transition);
  touch-action: manipulation;
}

.btn.primary {
  background: #1b3657;
  border-color: #3ea8ff;
  box-shadow: 0 0 0 1px var(--accent-soft);
}

.btn.subtle {
  opacity: 0.85;
}

.btn:hover {
  background: #0f1925;
  border-color: var(--accent);
}

.btn.primary:hover {
  background: #22446c;
}

.btn:active {
  transform: scale(0.98);
}

#main {
  padding: 18px 14px;
}

.hint {
  margin: 6px 0;
  color: var(--text-muted);
  max-width: 980px;
}

.hint.small {
  font-size: 12px;
  opacity: 0.85;
}

/* ---------------- TAG PILLS ---------------- */

.row-tags {
  align-items: center;
}

.tag-pills {
  display: flex;
  gap: 8px;
  align-items: center;
  overflow: auto;
  padding: 2px 2px;
  min-height: 36px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable both-edges;
}

.tag-pills::-webkit-scrollbar {
  height: 8px;
}
.tag-pills::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.10);
  border-radius: 999px;
}
.tag-pills::-webkit-scrollbar-track {
  background: transparent;
}

.tag-pill {
  flex: none;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: rgba(227,236,255,0.88);
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.tag-pill:hover {
  border-color: rgba(62,168,255,0.45);
  background: rgba(62,168,255,0.10);
}

.tag-pill.active {
  border-color: rgba(62,168,255,0.8);
  background: rgba(62,168,255,0.16);
  box-shadow: 0 0 0 1px rgba(62,168,255,0.10) inset;
  color: #eaf4ff;
}

.tag-pill .count {
  font-size: 11px;
  opacity: 0.85;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(0,0,0,0.18);
}

.tags-menu-btn {
  padding: 10px 12px;
  min-width: 44px;
}

.tags-menu {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 14px;
  background: rgba(6, 9, 19, 0.75);
  box-shadow: inset 0 0 20px rgba(255,255,255,0.03);
}

.tags-menu[hidden] {
  display: none !important;
}

.tags-menu-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---------------- RECENTS ---------------- */

.row-recents {
  align-items: center;
}

.recent-pills {
  display: flex;
  gap: 8px;
  align-items: center;
  overflow: auto;
  padding: 2px 2px;
  min-height: 34px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable both-edges;
}

.recent-pills::-webkit-scrollbar {
  height: 8px;
}
.recent-pills::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.10);
  border-radius: 999px;
}
.recent-pills::-webkit-scrollbar-track {
  background: transparent;
}

.recent-pill {
  flex: none;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: rgba(227,236,255,0.88);
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.recent-pill:hover {
  border-color: rgba(62,168,255,0.45);
  background: rgba(62,168,255,0.10);
}

.recent-pill .server {
  font-size: 11px;
  opacity: 0.8;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(0,0,0,0.18);
}

/* ---------------- HUB ---------------- */

.hub {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(10, 15, 22, 0.5);
  box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.03);
}

.hub-head {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.hub-title {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.hub-empty {
  padding: 12px;
  color: var(--text-muted);
  opacity: 0.9;
}

.hub-errors {
  padding: 10px;
  border: 1px dashed rgba(255, 255, 255, 0.10);
  border-radius: 14px;
  background: rgba(255, 90, 120, 0.06);
  margin-bottom: 10px;
}
.hub-errors .remote-error {
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(0,0,0,0.15);
  border: 1px solid rgba(255,255,255,0.08);
  margin: 6px 0;
}

.remote-group {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(6, 9, 19, 0.6);
  margin-top: 10px;
  overflow: hidden;
}

.remote-head {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(20, 30, 48, 0.35);
}

.remote-left {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.remote-title {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remote-sub {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remote-right {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.remote-error,
.remote-empty {
  padding: 10px;
  color: var(--text-muted);
  opacity: 0.9;
}

.remote-list {
  display: flex;
  flex-direction: column;
}

.proj-row {
  display: grid;

  /* Key change:
     - last column is shrinkable and capped by its own contents’ scroll behavior
     - prevents “auto” actions from expanding the whole row past viewport */
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 520px);

  gap: 10px;
  align-items: center;
  padding: 10px;
  border-top: 1px dashed rgba(255, 255, 255, 0.06);

  /* per-row vars (JS overrides for remotes that are current) */
  --current-accent: var(--accent);
  --current-accent-soft: var(--accent-soft);
  --current-accent-weak: rgba(62, 168, 255, 0.10);
  --current-accent-bar: rgba(62, 168, 255, 0.85);
}

.proj-row:first-child {
  border-top: none;
}

.proj-row.missing {
  opacity: 0.6;
}

/* ✅ Strong-but-elegant “current” signal, color-coded per server */
.proj-row.current {
  box-shadow:
    3px 0 0 0 var(--current-accent-bar) inset,
    0 0 0 1px var(--current-accent-soft) inset,
    0 0 0 4px var(--current-accent-weak) inset,
    0 0 22px var(--current-accent-weak);

  background: linear-gradient(
    90deg,
    var(--current-accent-soft),
    var(--current-accent-weak) 38%,
    rgba(0, 0, 0, 0) 78%
  );
}

.proj-row.current .proj-name {
  color: #eaf4ff;
}

/* Global active selection: distinct from per-server current */
.proj-row.active:not(.current) {
  box-shadow:
    2px 0 0 0 var(--current-accent-bar) inset,
    0 0 0 1px var(--current-accent-soft) inset,
    0 0 14px var(--current-accent-weak);
  background: linear-gradient(
    90deg,
    var(--current-accent-weak),
    rgba(0,0,0,0) 72%
  );
}

.proj-badge.active {
  border-color: var(--current-accent-soft);
  background: var(--current-accent-weak);
  color: #eaf4ff;
}

.proj-left {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.proj-line1 {
  display: flex;
  gap: 8px;
  align-items: baseline;
  min-width: 0;
  flex-wrap: wrap;
}

.proj-name {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.proj-name:hover {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-decoration-color: rgba(62, 168, 255, 0.55);
}

.proj-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(227,236,255,0.85);
  background: rgba(62,168,255,0.08);
}

.proj-badge.current {
  border-color: var(--current-accent-soft);
  background: var(--current-accent-weak);
  color: #eaf4ff;
}

.proj-badge.server {
  border-color: rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: rgba(227,236,255,0.82);
}

.proj-host {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.proj-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", monospace;
  font-size: 12px;
  color: rgba(227, 236, 255, 0.78);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.proj-tagsline {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.proj-tag {
  border-radius: 999px;
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: rgba(227,236,255,0.86);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.proj-tag:hover {
  border-color: rgba(62,168,255,0.45);
  background: rgba(62,168,255,0.10);
}

.proj-tag.active {
  border-color: rgba(62,168,255,0.8);
  background: rgba(62,168,255,0.16);
}

.proj-meta {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.proj-actions {
  display: flex;
  align-items: center;

  /* critical: allow the grid item to shrink */
  min-width: 0;
  justify-self: end;
}

/* ---- Project Action Rail (overflow-safe) ---- */
.proj-actrail{
  display:flex;
  align-items:center;
  gap:8px;
  min-width:0;
  max-width:100%;
}

.proj-actrail-main{
  display:flex;
  align-items:center;
  gap:8px;

  min-width:0;
  max-width:100%;

  /* actions overflow scrolls INSIDE the rail */
  overflow-x:auto;
  overflow-y:hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.proj-actrail-main > *{ flex:0 0 auto; }

/* Small screens: give actions full row width (prevents “squish then overflow”) */
@media (max-width: 680px){
  .proj-row{
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    row-gap: 8px;
  }
  .proj-actions{
    grid-column: 1 / -1;
    justify-self: start;
  }
}

/* star button */
.starbtn {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #050913;
  color: rgba(227, 236, 255, 0.9);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.starbtn:hover {
  border-color: var(--accent);
  background: #0f1925;
}
.starbtn.filled {
  border-color: rgba(255, 220, 0, 0.35);
  box-shadow: 0 0 0 1px rgba(255, 220, 0, 0.12);
  color: #ffe8a6;
}

/* tag edit button */
.tagbtn {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #050913;
  color: rgba(227, 236, 255, 0.9);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tagbtn:hover {
  border-color: rgba(62,168,255,0.75);
  background: rgba(62,168,255,0.10);
}

/* Tighten hub action buttons */
.proj-actions .btn {
  padding: 9px 12px;
}

@media (max-width: 820px) {
  .proj-row {
    grid-template-columns: 1fr;
    gap: 8px;
    align-items: stretch;
  }
  .proj-actions {
    justify-content: flex-start;
  }
  .proj-meta {
    justify-self: start;
  }
}

/* ---------------- Mobile: keep usable but not bulky ---------------- */

@media (max-width: 640px) {
  #toolbar {
    padding: calc(8px + var(--safe-top)) calc(10px + var(--safe-right)) 6px
      calc(10px + var(--safe-left));
  }

  /* ✅ 90% search / 10% menu button (prevents overflow + wobble) */
  .row-top {
    gap: 6px;
  }

  .row-top .top-search {
    flex: 9 1 0;     /* 90% */
    min-width: 0;    /* allow shrink on iOS */
  }

  .row-top #menu-toggle {
    flex: 1 0 0;     /* 10% */
    width: 100%;
    min-width: 44px; /* tap target floor */
  }

  .field {
    min-width: 100%;
  }

  input[type="text"],
  input[type="search"],
  select {
    font-size: 16px; /* critical: no iOS zoom */
    padding: 10px 12px;
    min-width: 100%;
  }

  .btn {
    padding: 10px 12px;
    font-size: 15px;
  }

  .btn.chip {
    padding: 8px 10px;
    min-height: 38px;
  }

  .btn.chip.icon {
    width: 44px;
    font-size: 20px;
  }

  .starbtn,
  .tagbtn {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  #toolbar-controls {
    max-height: min(50vh, 440px);
    max-height: min(50svh, 440px);
  }

  #filters-wrap {
    max-height: min(36vh, 280px);
    max-height: min(36svh, 280px);
  }

  .menu-drawer {
    max-height: min(70vh, 560px);
    max-height: min(70svh, 560px);
  }
}

/* Ultra-short iOS split view (your “3 windows vertically” case) */
@media (max-height: 520px) {
  #toolbar-top {
    gap: 6px;
  }

  #toolbar .row {
    gap: 6px;
  }

  .btn.chip {
    min-height: 34px;
    padding: 7px 9px;
  }

  .menu-drawer {
    max-height: min(72vh, 420px);
    max-height: min(72svh, 420px);
  }

  #toolbar-controls {
    max-height: min(52vh, 320px);
    max-height: min(52svh, 320px);
  }

  #filters-wrap {
    max-height: min(34vh, 220px);
    max-height: min(34svh, 220px);
  }
}

/* ---------------- PLUGIN PANEL ---------------- */

#plugins-panel {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 14px;
  background: rgba(6, 9, 19, 0.75);
  box-shadow: inset 0 0 20px rgba(255,255,255,0.03);

  max-height: min(55vh, 420px);
  max-height: min(55svh, 420px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

#plugins-panel[hidden] { display: none !important; }

.plugin-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 6px;
  border-top: 1px dashed rgba(255,255,255,0.06);
}
.plugin-row:first-child { border-top: none; }

.plugin-row .meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.plugin-row .name {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plugin-row .desc {
  font-size: 12px;
  opacity: 0.85;
  color: rgba(155, 172, 206, 0.95);
}
.plugin-row .hooks {
  font-size: 11px;
  opacity: 0.75;
  color: rgba(155, 172, 206, 0.9);
}

.plugin-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  cursor: pointer;
  opacity: 0.95;
}

.plugin-toggle input {
  width: 18px;
  height: 18px;
}
