/* Azure-DevOps-inspired theme */

:root {
  --azure: #0078d4;
  --azure-dark: #106ebe;
  --ink: #201f1e;
  --ink-soft: #605e5c;
  --line: #edebe9;
  --rail: #f3f2f1;
  --hover: #f3f2f1;
  /* ADO work item type colors */
  --t-epic: #ff7b00;
  --t-feature: #773b93;
  --t-story: #009ccc;
  --t-bug: #cc293d;
  --t-issue: #b4009e;
  --t-task: #f2cb1d;
  /* ADO state colors */
  --s-new: #b2b2b2;
  --s-active: #007acc;
  --s-resolved: #ff9d00;
  --s-closed: #339933;
}

* { box-sizing: border-box; }

/* Font-size preference: every font-size in this file is in rem, so scaling
   the root scales the whole app's text. Toggled from the sidebar Preferences
   panel and remembered via localStorage (see layout.js). */
html { font-size: 17px; }
html.text-sm { font-size: 15px; }
html.text-lg { font-size: 19px; }

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
  font-size: 0.875rem;
  color: var(--ink);
  background: #fff;
}

a { color: var(--azure); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 48px;
  padding: 0 1rem;
  background: var(--azure);
  color: #fff;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.topbar .brand { font-size: 1rem; font-weight: 600; color: #fff; white-space: nowrap; flex-shrink: 0; }
.topbar .brand:hover { text-decoration: none; }

.nav-toggle {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.nav-toggle:hover { background: rgba(255, 255, 255, 0.28); }
.nav-toggle .bar { position: relative; width: 21px; height: 2.5px; background: #fff; border-radius: 1px; }
.nav-toggle .bar::before, .nav-toggle .bar::after {
  content: ""; position: absolute; left: 0; width: 21px; height: 2.5px; background: #fff; border-radius: 1px;
}
.nav-toggle .bar::before { top: -7px; }
.nav-toggle .bar::after { top: 7px; }

/* Search collapses to an icon; the panel opens as a floating dropdown so it
   never changes the topbar's width or pushes other items around. */
.topbar-search { position: relative; flex-shrink: 0; }
.search-toggle {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
}
.search-toggle svg { width: 24px; height: 24px; stroke-width: 2; }
.search-toggle:hover,
.topbar-search.open .search-toggle { background: rgba(255, 255, 255, 0.22); }

.search-panel {
  /* position: fixed with top/left set by layout.js — .topbar needs overflow-x:auto as a
     small-screen safety net, and an absolutely-positioned child would get clipped by that. */
  display: none;
  position: fixed;
  z-index: 90;
  width: 340px;
  max-width: 85vw;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}
.topbar-search.open .search-panel { display: block; }
.search-panel form { margin: 0; padding: 10px; }
.search-panel input {
  width: 100%;
  height: 36px;
  border: 1px solid #8a8886;
  border-radius: 3px;
  padding: 0 10px;
  font-size: 0.875rem;
  background: #fff;
}
.search-suggestion-list { list-style: none; margin: 0; padding: 2px 0; max-height: 320px; overflow-y: auto; border-top: 1px solid var(--line); }
.search-suggestion {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--ink);
}
.search-suggestion:hover { background: var(--hover); text-decoration: none; }
.search-suggestion .ss-title { flex: 1; font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-suggestion .ss-id { font-size: 0.6875rem; color: var(--ink-soft); flex-shrink: 0; }
.search-suggestion-empty { margin: 0; padding: 12px; font-size: 0.8125rem; color: var(--ink-soft); border-top: 1px solid var(--line); }
.search-suggestion-more {
  display: block;
  padding: 9px 12px;
  font-size: 0.75rem;
  text-align: center;
  border-top: 1px solid var(--line);
  background: var(--rail);
  color: var(--azure);
}
.search-suggestion-more:hover { background: #e1dfdd; text-decoration: none; }

.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.topbar-user form { margin: 0; display: inline; }
.topbar-user button {
  background: transparent; border: 1px solid rgba(255,255,255,0.6); color: #fff;
  border-radius: 3px; padding: 5px 12px; font-size: 0.8125rem; cursor: pointer; white-space: nowrap;
}
.topbar-user button:hover { background: rgba(255,255,255,0.15); }

/* ---------- Shell: sidebar + content ---------- */
.shell { display: flex; min-height: calc(100vh - 48px); }
.sidenav-backdrop { display: none; }
.sidenav {
  width: 210px;
  flex-shrink: 0;
  background: var(--rail);
  border-right: 1px solid var(--line);
  padding-top: 0.5rem;
  overflow-x: hidden;
  transition: width 0.15s ease;
}
.sidenav a, .sidenav .pref-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.6rem 1rem;
  color: var(--ink);
  font-size: 0.875rem;
  font-family: inherit;
  white-space: nowrap;
  border-left: 3px solid transparent;
  background: transparent;
  border-top: none;
  border-right: none;
  border-bottom: none;
  text-align: left;
  cursor: pointer;
}
.sidenav a:hover, .sidenav .pref-toggle:hover { background: #e1dfdd; text-decoration: none; }
.sidenav a.active {
  border-left-color: var(--azure);
  background: #fff;
  font-weight: 600;
  color: var(--azure);
}
.sidenav .pref-toggle.open { background: #e1dfdd; }
.sidenav .nav-icon { width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidenav .nav-icon svg { width: 21px; height: 21px; stroke-width: 1.8; }
.sidenav hr { border: none; border-top: 1px solid var(--line); margin: 0.5rem 0; }

.pref-panel {
  display: none;
  position: fixed;
  z-index: 90;
  width: 220px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  padding: 12px;
}
.pref-panel.open { display: block; }
.pref-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.pref-row-label { font-size: 0.8125rem; color: var(--ink); font-weight: 600; }
.pref-btns { display: flex; gap: 4px; }
.pref-btns button {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #8a8886;
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}
.pref-btns button[data-size="sm"] { font-size: 0.6875rem; }
.pref-btns button[data-size="md"] { font-size: 0.8125rem; }
.pref-btns button[data-size="lg"] { font-size: 0.9375rem; }
.pref-btns button:hover { background: var(--hover); }
.pref-btns button.active { border-color: var(--azure); color: var(--azure); background: #eff6fc; }

/* Collapsed on desktop: shrink to an icon-only rail, remembered via localStorage. */
html.nav-collapsed .sidenav { width: 56px; }
html.nav-collapsed .sidenav a, html.nav-collapsed .sidenav .pref-toggle { justify-content: center; padding: 0.65rem 0; }
html.nav-collapsed .sidenav .nav-label { display: none; }

.content { flex: 1; padding: 1rem 1.5rem 3rem; min-width: 0; overflow-x: auto; }
.content h1 { font-size: 1.125rem; font-weight: 600; margin: 0.3rem 0 1rem; }
.content h2 {
  font-size: 0.875rem; font-weight: 600; margin: 1.4rem 0 0.5rem;
  color: var(--ink);
}

/* ---------- Work item type icon ---------- */
.wi-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 2px;
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  vertical-align: -2px;
  flex-shrink: 0;
}
.wi-icon.type-epic { background: var(--t-epic); }
.wi-icon.type-feature { background: var(--t-feature); }
.wi-icon.type-story { background: var(--t-story); }
.wi-icon.type-bug { background: var(--t-bug); }
.wi-icon.type-issue { background: var(--t-issue); }
.wi-icon.type-task { background: var(--t-task); color: var(--ink); }

/* ---------- State dot ---------- */
.state-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -1px;
}
.state-dot.state-new { background: var(--s-new); }
.state-dot.state-active { background: var(--s-active); }
.state-dot.state-resolved { background: var(--s-resolved); }
.state-dot.state-closed { background: var(--s-closed); }

/* ---------- Avatar chip ---------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--azure);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 600;
  vertical-align: middle;
  text-transform: uppercase;
}
.avatar-name { margin-left: 6px; vertical-align: middle; }

/* ---------- Query grid (item list) ---------- */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.5rem 0 0.75rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0;
}
.filter-bar select, .filter-bar input[type="search"] {
  height: 30px;
  border: 1px solid #8a8886;
  border-radius: 2px;
  padding: 0 8px;
  font-size: 0.8125rem;
  background: #fff;
}
.filter-bar input[type="search"] { min-width: 220px; }

table { border-collapse: collapse; width: 100%; font-size: 0.8125rem; }
thead th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td { padding: 5px 10px; border-bottom: 1px solid var(--line); }
tbody tr:hover { background: var(--hover); }
td .wi-title { font-weight: 400; color: var(--ink); }
td .wi-title:hover { color: var(--azure); }

/* Inline-editable controls: invisible until hover, like ADO fields */
select.inline-edit, input.inline-edit {
  width: auto;
  max-width: 100%;
  border: 1px solid transparent;
  background: transparent;
  font-size: 0.8125rem;
  padding: 2px 4px;
  border-radius: 2px;
  cursor: pointer;
}
select.inline-edit:hover, input.inline-edit:hover,
select.inline-edit:focus, input.inline-edit:focus {
  border-color: #8a8886;
  background: #fff;
}
input.inline-edit { cursor: text; min-width: 3.5rem; }

.wi-title-input {
  display: block;
  width: 100%;
  max-width: none;
  font-size: 1.0625rem;
  font-weight: 600;
  font-family: inherit;
  margin: 0.2rem 0 0.5rem;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
}
.wi-title-input:hover { border-color: #8a8886; }
.wi-title-input:focus { outline: 2px solid var(--azure); outline-offset: -1px; background: #fff; }

/* ---------- Buttons & forms ---------- */
button, .btn {
  font-family: inherit;
  font-size: 0.8125rem;
  border-radius: 2px;
  padding: 5px 14px;
  cursor: pointer;
  border: 1px solid var(--azure);
  background: var(--azure);
  color: #fff;
}
button:hover, .btn:hover { background: var(--azure-dark); text-decoration: none; }
button.secondary, .btn.secondary {
  background: #fff; color: var(--ink); border: 1px solid #8a8886;
}
button.secondary:hover, .btn.secondary:hover { background: var(--hover); }
button.danger, .btn.danger { background: #cc293d; border-color: #cc293d; }
button.danger:hover { background: #a4263a; }

form p { margin: 0 0 0.8rem; }
form label { display: block; font-size: 0.75rem; font-weight: 600; margin-bottom: 3px; color: var(--ink-soft); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
select, textarea {
  font-family: inherit;
  font-size: 0.8125rem;
  width: 100%;
  max-width: 640px;
  border: 1px solid #8a8886;
  border-radius: 2px;
  padding: 6px 8px;
  background: #fff;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--azure); outline-offset: -1px; }
.errorlist { color: #cc293d; font-size: 0.75rem; margin: 0 0 0.5rem; padding-left: 1rem; }

/* ---------- Work item detail (two-column form) ---------- */
.wi-header {
  border: 1px solid var(--line);
  border-left: 4px solid var(--azure);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.wi-header.type-epic { border-left-color: var(--t-epic); }
.wi-header.type-feature { border-left-color: var(--t-feature); }
.wi-header.type-story { border-left-color: var(--t-story); }
.wi-header.type-bug { border-left-color: var(--t-bug); }
.wi-header.type-issue { border-left-color: var(--t-issue); }
.wi-header.type-task { border-left-color: var(--t-task); }
.wi-header h1 { margin: 0.2rem 0 0.5rem; font-size: 1.0625rem; }
.wi-header .wi-id { color: var(--ink-soft); font-weight: 400; }
.wi-meta { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; font-size: 0.8125rem; }
.wi-meta .label { color: var(--ink-soft); font-size: 0.75rem; margin-right: 4px; }
.wi-actions { margin-left: auto; display: flex; gap: 0.4rem; }
.wi-header .form-field { margin-bottom: 0.6rem; }
.wi-header .form-field:last-child { margin-bottom: 0; }
.wi-form-actions { margin-top: 1rem; display: flex; gap: 0.5rem; }

.wi-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.5rem; }
@media (max-width: 900px) { .wi-layout { grid-template-columns: 1fr; } }

.wi-panel {
  border: 1px solid var(--line);
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.9rem;
}
.wi-panel h2 { margin: 0 0 0.5rem; font-size: 0.8125rem; }
.wi-panel dl { margin: 0; }
.wi-panel dt { font-size: 0.6875rem; color: var(--ink-soft); margin-top: 0.5rem; }
.wi-panel dd { margin: 1px 0 0; font-size: 0.8125rem; }
.wi-panel ul { margin: 0.2rem 0; padding-left: 1.1rem; }
.wi-panel li { margin: 0.2rem 0; }

.markdown { font-size: 0.8125rem; line-height: 1.55; }
.markdown img { max-width: 100%; }
.markdown pre { background: var(--rail); padding: 0.6rem; overflow-x: auto; }
.markdown table td, .markdown table th { border: 1px solid var(--line); padding: 4px 8px; }
.markdown blockquote { border-left: 3px solid var(--line); margin-left: 0; padding-left: 0.8rem; color: var(--ink-soft); }

/* ---------- Discussion ---------- */
.comment { display: flex; gap: 0.6rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.comment .avatar { flex-shrink: 0; margin-top: 2px; }
.comment header { margin-bottom: 0.1rem; }
.comment header small { color: var(--ink-soft); margin-left: 0.5rem; }
.comment .markdown p:first-child { margin-top: 0.2rem; }
.comment .markdown p:last-child { margin-bottom: 0; }

/* ---------- Watch / small buttons ---------- */
.watch-btn { padding: 3px 10px; font-size: 0.75rem; }
.link-btn {
  background: none; border: none; color: #cc293d;
  cursor: pointer; padding: 0 4px; font-size: 0.75rem; width: auto; display: inline;
}
.link-btn:hover { background: none; text-decoration: underline; }

/* ---------- Tree / backlog ---------- */
.backlog-header { display: flex; align-items: baseline; gap: 1.25rem; flex-wrap: wrap; }
.visit-history { display: flex; align-items: center; gap: 4px; }
.visit-history .avatar { width: 20px; height: 20px; font-size: 0.625rem; }
.visit-history small { margin-left: 6px; color: var(--ink-soft); }

.tree-node { margin: 0; }
.tree-node summary {
  list-style: none;
  cursor: pointer;
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
  overflow: hidden;
}
.tree-node summary::before { content: "⌄"; color: var(--ink-soft); width: 0.9rem; flex-shrink: 0; }
.tree-node[open] > summary::before { content: "⌄"; }
.tree-node:not([open]) > summary::before { content: "›"; }
.tree-node.leaf > summary::before { content: " "; }
.tree-node summary:hover { background: var(--hover); }
.tree-node summary small { color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; }
.tree-children { margin-left: 1.4rem; }
.add-child { font-size: 0.6875rem; margin-left: auto; padding-left: 1rem; visibility: hidden; }
.tree-node summary:hover .add-child { visibility: visible; }

/* ---------- Messages ---------- */
.message {
  padding: 0.5rem 0.9rem;
  margin-bottom: 0.8rem;
  font-size: 0.8125rem;
  border: 1px solid var(--line);
  border-left-width: 4px;
}
.message.success { border-left-color: var(--s-closed); background: #f4faf4; }
.message.error { border-left-color: #cc293d; background: #fdf3f4; }

/* ---------- Login ---------- */
.login-card {
  max-width: 26rem;
  margin: 5rem auto;
  border: 1px solid var(--line);
  border-top: 4px solid var(--azure);
  padding: 1.5rem 2rem 2rem;
}
.login-card h1 { font-size: 1.125rem; }

fieldset[role="group"] { border: none; padding: 0; margin: 0.4rem 0; display: flex; gap: 0.5rem; }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  .sidenav {
    position: fixed;
    top: 48px;
    left: 0;
    bottom: 0;
    z-index: 100;
    width: 240px;
    max-width: 80vw;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  /* The desktop icon-rail state doesn't apply here; a mobile-opened sidebar always shows labels. */
  html.nav-collapsed .sidenav { width: 240px; }
  html.nav-collapsed .sidenav a, html.nav-collapsed .sidenav .pref-toggle { justify-content: flex-start; padding: 0.6rem 1rem; }
  html.nav-collapsed .sidenav .nav-label { display: inline; }

  html.nav-open .sidenav { transform: translateX(0); }
  html.nav-open .sidenav-backdrop {
    display: block;
    position: fixed;
    inset: 48px 0 0 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 90;
  }

  .content { padding: 0.85rem 1rem 3rem; }
  .filter-bar input[type="search"] { min-width: 0; flex: 1 1 100%; }
}

@media (max-width: 420px) {
  .username { display: none; }
}
