/* Troubadour web UI - the shell: layout, sidebar, header and tabs,
   content frame, page heads, auth card, buttons, form fields, chips. */

/* ---------------- Layout ---------------- */

.app-shell { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar__head { padding: var(--s4) var(--s4) var(--s3); }

.sidebar__new {
  margin: 0 var(--s3) var(--s3);
  display: flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--primary);
  color: var(--primary-ink);
  cursor: pointer;
  font-weight: 600;
  box-shadow: var(--shadow-1);
}
.sidebar__new:hover { background: var(--primary-hover); }

.sidebar__list { flex: 1 1 auto; overflow-y: auto; padding: 0 var(--s2) var(--s2); }

.thread {
  position: relative;
  display: flex; align-items: center; gap: 2px;
  padding: 0 var(--s1) 0 0; /* gh #29: the title button carries the row pad */
  border-radius: var(--radius-sm);
  width: 100%; /* buttons shrink-to-fit; without this the hover icons
                  sat in the row's centre strip and stole the click */
}
.thread__title {
  flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  /* gh #29: a real button - inherits the text look, keeps the pad */
  background: none; border: none; color: var(--text); font: inherit;
  font-size: var(--fs-md); text-align: left; padding: 9px 12px;
  cursor: pointer; border-radius: var(--radius-sm);
}
.thread:hover { background: var(--surface-2); }
.thread.is-active { background: var(--primary-soft); }
.thread.is-active::before {
  content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--primary);
}
.thread.is-active .thread__title { font-weight: 600; }
.thread--unread .thread__title { font-weight: 650; }
.thread__unread {
  flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary); margin-right: 6px;
}
.hamburger { position: relative; }
.hamburger.has-unread::after {
  content: ""; position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--primary);
  box-shadow: 0 0 0 2px var(--bg);
}
.tab { position: relative; }
.tab.has-unread::after {
  content: ""; position: absolute; top: 6px; right: 6px;
  width: 7px; height: 7px; border-radius: 50%; background: var(--primary);
}
.thread__del {
  opacity: 0; pointer-events: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; border-radius: var(--radius-xs);
}
/* reveal on hover or keyboard focus - a focused invisible icon is no
   affordance at all (gh #29); always shown on touch */
.thread:hover .thread__del,
.thread__del:focus-visible { opacity: 1; pointer-events: auto; }
.thread__del:hover { color: var(--text); background: var(--surface); }
.thread__del[aria-label="Delete chat"]:hover { color: var(--danger); }
@media (hover: none) { .thread__del { opacity: 1; pointer-events: auto; } }

/* gh #48: sidebar section labels */
.thread-group {
  display: flex; align-items: center; gap: 6px;
  width: 100%; border: none; background: none;
  padding: var(--s4) 12px 6px;
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em; text-align: left;
  cursor: pointer;
}
.thread-group.is-static { cursor: default; }
.thread-group:hover:not(.is-static) { color: var(--text); }
.thread-group:not(.is-static)::after {
  content: ""; width: 7px; height: 7px; margin-left: auto;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform 0.15s;
}
.thread-group.is-open::after { transform: rotate(45deg); }

.sidebar__foot {
  padding: var(--s2) var(--s3) var(--s3);
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: var(--s1);
}
.sidebar__foot button {
  display: flex; align-items: center; gap: 10px;
  min-height: 36px; padding: 6px 10px;
  border-radius: var(--radius-sm); border: none; background: transparent;
  color: var(--muted); cursor: pointer; text-align: left;
  font-size: var(--fs-md); font-weight: 500;
}
.sidebar__foot button:hover { color: var(--text); background: var(--surface-2); }
.sidebar__toggle { font-size: var(--fs-sm) !important; }
.sidebar__toggle[aria-pressed="true"] { color: var(--text); }
.sidebar__row { display: flex; gap: var(--s1); }
.sidebar__row > button { flex: 1 1 0; }
.sidebar__row > .sidebar__icon { flex: 0 0 auto; width: 38px; justify-content: center;
  padding: 6px; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column;
  min-height: 0; background: var(--bg); }

/* ---------------- Header ---------------- */

.header {
  display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--s4);
  /* fixed: the header used to grow and shrink with its avatar text, so
     the tab strip jumped between 30 and 47 px as the view changed */
  height: var(--header-h); min-height: var(--header-h); flex: 0 0 var(--header-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.header__tabs {
  flex: 1 1 auto; min-width: 0; display: flex; gap: 2px;
  overflow-x: auto; scrollbar-width: none; align-items: center;
}
.header__tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 12px;
  border: none; background: transparent; color: var(--muted);
  border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap;
  font-weight: 550; font-size: var(--fs-md);
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab.is-active { background: var(--primary-soft); color: var(--primary); }
html.dark .tab.is-active { color: #9db8ff; }
.tab .icon { opacity: 0.9; }
/* gh #32: pending-approval count rides the Approvals tab button */
.tab__badge {
  min-width: 18px; padding: 0 5px; margin-left: 1px;
  border-radius: var(--pill); background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px;
  display: inline-block; text-align: center;
}
html.dark .tab__badge { background: #e5484d; }

.hamburger {
  display: none; align-items: center; justify-content: center;
  width: 38px; height: 38px; border: none; background: transparent;
  color: var(--text); border-radius: var(--radius-sm); cursor: pointer;
}
.hamburger:hover { background: var(--surface-2); }

/* the agent's identity slot: circle + two quiet lines, one fixed height */
.avatar {
  display: flex; align-items: center; gap: 9px; flex: 0 0 auto;
  height: 40px; padding: 0 10px 0 4px; max-width: 220px;
  border: none; background: transparent; color: inherit;
  border-radius: var(--pill); cursor: pointer; text-align: left;
}
.avatar:hover { background: var(--surface); }
.avatar__circle {
  width: 32px; height: 32px; border-radius: 50%; flex: 0 0 auto; overflow: hidden;
  background: linear-gradient(135deg, #5b86ff, #2554e8);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.avatar__circle--img { background: var(--surface-2); border: 1px solid var(--border); }
.avatar__img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 50%; }
.avatar__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.avatar__name { font-size: var(--fs-sm); font-weight: 650; max-width: 130px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar__status { font-size: 11.5px; color: var(--muted); max-width: 130px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.header__toggle {
  display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto;
  height: 36px; padding: 0 12px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: var(--radius-sm); cursor: pointer; font-weight: 550;
  font-size: var(--fs-md);
}
.header__toggle:hover { background: var(--surface); border-color: var(--border-strong); }
.header__toggle[aria-pressed="true"] { background: var(--primary-soft);
  border-color: var(--primary); color: var(--primary); }
html.dark .header__toggle[aria-pressed="true"] { color: #9db8ff; }

/* gh #59: the desktop-control state has to read with the drawer shut */
.header__takeover { flex: 0 0 auto; white-space: nowrap; }
.header__takeover__short { display: none; }

/* the sandbox pane takes 392 px: inactive tabs fall back to their icon
   (the name is on the tooltip and the active tab keeps its label) rather
   than scrolling half out of view */
@media (min-width: 768px) {
  .app-shell.has-pane .tab:not(.is-active) .tab__label { display: none; }
  .app-shell.has-pane .tab { padding: 0 10px; }
}

/* ---------------- Content ---------------- */

.content { flex: 1 1 auto; overflow-y: auto; padding: var(--s6) var(--s6) var(--s8); min-height: 0; }
.content__inner { max-width: var(--content-w); margin: 0 auto; }

/* gh #21: with a chat open the composer stays pinned at the scroller
   bottom while history scrolls beneath it. */
.content.content--chat { padding-bottom: 0; }
.content--chat .content__inner { min-height: 100%; display: flex;
  flex-direction: column; max-width: calc(var(--chat-w) + 2 * var(--s6)); }
.content--chat .chat { flex: 1 1 auto; min-height: 0; height: auto; }
.content--chat .composer { position: sticky; bottom: 0; z-index: 5; }

/* page head: every tab opens the same way - a title, one line of what it
   is for, and the primary action on the right. The title keeps the
   .section__title class the suites read. */
.page-head { display: flex; align-items: flex-end; gap: var(--s4); flex-wrap: wrap;
  margin: 0 0 var(--s5); }
.page-head__text { flex: 1 1 260px; min-width: 0; }
h2.section__title { font-size: var(--fs-lg); font-weight: 650; letter-spacing: -0.015em;
  margin: 0 0 var(--s3); display: block; }
.page-head h2.section__title { font-size: var(--fs-xl); font-weight: 700;
  letter-spacing: -0.02em; margin: 0; }
.page-sub { color: var(--muted); font-size: var(--fs-md); margin: 3px 0 0; max-width: 60ch; }
.page-head__actions { display: flex; gap: var(--s2); align-items: center; }

.section { margin-bottom: var(--s8); }
.section > .section { margin-top: var(--s8); margin-bottom: 0; }
.header__title { display: none; font-weight: 700; font-size: var(--fs-lg); letter-spacing: -0.015em;
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
div.section__title, .section__title--sub {
  display: flex; align-items: center; gap: var(--s2);
  font-size: var(--fs-xs); font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em; margin: var(--s2) 0 var(--s3);
}

/* empty states: icon, one sentence of why, the action that fixes it */
.empty { text-align: center; color: var(--muted); padding: var(--s10) var(--s5); }
.empty__icon { display: inline-flex; width: 52px; height: 52px; align-items: center;
  justify-content: center; border-radius: 16px; background: var(--surface-2);
  color: var(--muted); margin-bottom: var(--s3); }
.empty__title { font-size: var(--fs-lg); font-weight: 650; color: var(--text);
  margin-bottom: 6px; }
.empty p { max-width: 44ch; margin: 0 auto var(--s4); }
.empty--section {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s5); border: 1px dashed var(--border-strong);
  border-radius: var(--radius); color: var(--muted); font-size: var(--fs-md);
  background: var(--surface);
}

/* ---------------- Auth ---------------- */

.auth {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: var(--s6);
  background:
    radial-gradient(1100px 520px at 12% -8%, rgba(37, 84, 232, 0.10), transparent 60%),
    radial-gradient(900px 480px at 100% 110%, rgba(37, 84, 232, 0.08), transparent 55%),
    var(--surface);
}
.auth__card {
  width: 100%; max-width: 400px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; padding: var(--s8) var(--s8) var(--s6);
  box-shadow: var(--shadow-2);
}
.auth__head { text-align: center; margin-bottom: var(--s6); }
.auth__head .brand { justify-content: center; margin-bottom: var(--s4); }
.auth__head h1 { font-size: var(--fs-2xl); margin: 0 0 4px; letter-spacing: -0.025em; }
.auth__sub { color: var(--muted); font-size: var(--fs-md); margin: 0; }
.auth__group { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s4); }
.auth__group label { font-size: var(--fs-sm); color: var(--text); font-weight: 600; }
.auth__group input {
  height: 44px; padding: 0 var(--s3);
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text);
}
.auth__group input:focus { outline: var(--focus); outline-offset: 0; border-color: var(--primary); }
.auth__card .btn--primary { width: 100%; height: 44px; font-size: var(--fs-base); margin-top: var(--s1); }
.auth__error {
  display: flex; gap: var(--s2); align-items: flex-start;
  margin: 0 0 var(--s4); padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger); font-size: var(--fs-md);
}
.auth__error--info { background: var(--primary-soft); color: var(--text); }
.auth__toggle { margin: var(--s5) 0 0; text-align: center; color: var(--muted); font-size: var(--fs-md); }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 var(--s4);
  border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; font-weight: 600; font-size: var(--fs-md); white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--primary); color: var(--primary-ink); box-shadow: var(--shadow-1); }
.btn--primary:not(:disabled):hover { background: var(--primary-hover); }
.btn--ghost { background: var(--bg); border-color: var(--border-strong); color: var(--text); }
.btn--ghost:not(:disabled):hover { background: var(--surface); }
.btn--danger-ghost { background: var(--bg); border-color: var(--border-strong); color: var(--muted); }
.btn--danger-ghost:not(:disabled):hover { color: var(--danger); border-color: var(--danger);
  background: var(--danger-soft); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--sm { height: 30px; padding: 0 11px; font-size: var(--fs-sm); border-radius: 9px; }
.btn--icon { width: 34px; padding: 0; }
.btn--sm.btn--icon { width: 30px; }

/* link-styled button (gh #5 keyboard-reachable auth toggle) */
.linkbtn { border: none; background: transparent; color: var(--primary); cursor: pointer;
  font-weight: 600; font-size: inherit; padding: 0; }
.linkbtn:hover { text-decoration: underline; }

/* ---------------- Fields ---------------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s4); }
.field label { font-size: var(--fs-sm); color: var(--text); font-weight: 600; }
.field input, .field select, .field textarea,
.create-row input[type="text"], .modal__card input {
  min-height: 40px; padding: 9px var(--s3);
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text); width: 100%;
}
.field textarea { line-height: 1.5; }
/* a select is drawn, not the platform's: same box as the inputs, our chevron */
.field select { appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 38px;
  background: var(--bg) var(--chev) no-repeat right 12px center / 16px; }
/* an input with a button beside it (the API key and its Show) */
.field__row { display: flex; gap: var(--s2); align-items: stretch; }
.field__row input { flex: 1 1 auto; min-width: 0; }
.field .field__row .btn { flex: 0 0 auto; align-self: stretch; height: auto; padding: 0 var(--s4); font-size: var(--fs-md); }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--s4); }
.field input:focus, .field select:focus, .field textarea:focus,
.create-row input[type="text"]:focus, .modal__card input:focus {
  outline: var(--focus); outline-offset: 0; border-color: var(--primary);
}
.field input::placeholder, .create-row input::placeholder, textarea::placeholder {
  color: var(--muted-2); }
.field__hint { font-size: var(--fs-xs); color: var(--muted); }
.field__note { font-size: var(--fs-xs); color: var(--muted); line-height: 1.5; margin: var(--s2) 0; }
.field .btn { width: auto; align-self: flex-start; }
.field--error input { border-color: var(--danger); }
.field__error { color: var(--danger); font-size: var(--fs-xs); }

/* ---------------- Chips and dots ---------------- */

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--pill);
  font-size: var(--fs-xs); font-weight: 650; line-height: 1.5;
  background: var(--surface-2); color: var(--muted);
}
.chip--pending { background: var(--warn-soft); color: var(--warn); }
.chip--allow { background: var(--success-soft); color: var(--success); }
.chip--deny { background: var(--danger-soft); color: var(--danger); }
.chip--always { background: var(--primary-soft); color: var(--primary); }
.chip--expired { background: var(--surface-2); color: var(--muted); }
.chip--takeover { background: var(--warn-soft); color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); }
html.dark .chip--always { color: #9db8ff; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.dot--ok { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.dot--off { background: var(--muted-2); }

/* Opt-in Feed headlines. The strip is absent when disabled or empty. */
.feed-ticker { display: flex; align-items: center; min-width: 0;
  padding: 0 var(--s3); gap: var(--s2); border-bottom: 1px solid var(--border);
  background: var(--surface); }
.feed-ticker__scroll { flex: 1 1 auto; min-width: 0; overflow-x: auto;
  scrollbar-width: none; }
.feed-ticker__list { display: flex; width: max-content; align-items: center; padding: 0;
  margin: 0; list-style: none; gap: var(--s2); }
.feed-ticker__item, .feed-ticker__pause { font: inherit; font-size: var(--fs-sm);
  background: transparent; color: var(--text); border: 0; padding: 0 var(--s2);
  min-height: 36px; cursor: pointer; }
.feed-ticker__item { display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap; text-align: start; }
.feed-ticker__glyph { --tone: var(--primary); display: inline-flex; align-items: center;
  justify-content: center; flex: 0 0 auto; color: var(--tone); }
.feed-ticker__glyph[data-tone="violet"] { --tone: var(--violet); }
.feed-ticker__glyph[data-tone="success"] { --tone: var(--success); }
html.dark .feed-ticker__glyph[data-tone="primary"] { color: #8fb0ff; }
html.dark .feed-ticker__glyph[data-tone="violet"] { color: #c4b5fd; }
html.dark .feed-ticker__glyph[data-tone="success"] { color: #6ee7b7; }
.feed-ticker__title { min-width: 0; }
.feed-ticker__list li + li::before { content: "\00b7"; color: var(--muted-2); margin-right: var(--s2); }
.feed-ticker__pause { color: var(--muted); }
.feed-ticker__item:focus-visible { outline-offset: -2px; }
.feed-ticker-target { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .feed-ticker__pause { display: none; } }

/* Isolated project desktop session selector (#79) */
.pane__sessions { display: flex; flex-direction: column; gap: 4px; padding: 8px 14px;
  border-top: 1px solid var(--border); background: var(--surface-2); }
.pane__session-select { width: 100%; font-size: var(--fs-xs); padding: 6px 8px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); }
.pane__session-meta { font-size: var(--fs-xs); color: var(--muted); line-height: 1.35; }
