/* The application shell: app bar, left navigation, and the main column that owns
 * the breadcrumb, the page title and the tab strip.
 *
 * The point of a shell is that a page stops having to invent where it is. Before
 * this, orientation was one hand-written `<a class="back">` on the one page that
 * happened to need it; everything else dropped you into a column of cards with
 * no indication of what you were looking at or how to get anywhere else.
 *
 * Structure, and the reason for it:
 *
 *   .appbar     identity, search, create, account - the things that are true on
 *               every page, so they never move
 *   .shell      the row below it
 *     .sidebar  where you can go. An agent is listed here the way a space is in
 *               herdwork, so moving between agents costs one click rather than a
 *               round trip through a list
 *     .main     where you are: crumb, title, tabs, then the view
 *
 * Only .view scrolls. The bar, the rail and the tab strip stay put, which is
 * what makes a long grants table feel like a table inside an app rather than a
 * page that has run away downwards.
 */

html, body { height: 100%; margin: 0; }

body.app {
  display: flex;
  flex-direction: column;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.55 var(--grot);
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   App bar
   ============================================================ */

.appbar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  height: var(--appbar-h);
  flex: none;
  padding: 0 var(--s3);
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  z-index: 70;
}

/* The hamburger. Present at every width, not only on phones: a rail you cannot
   put away is a rail that costs you 228px on the one screen - the runs table -
   where horizontal room is the whole point. */
.navtoggle {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 32px; height: 32px;
  padding: 0 7px;
  border: 0; border-radius: 0;
  background: none;
  cursor: pointer;
  flex: none;
}
.navtoggle:hover { background: var(--sunk); }
.navtoggle span { display: block; height: 2px; background: var(--muted); }

/* The brand. The mark sits between the two words rather than beside them: the
   cross does the work a space would otherwise do, so the compound name reads as
   one word with a Swiss joint. */
.appbrand {
  display: flex;
  align-items: center;
  gap: .04em;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -.025em;
  flex: none;
}
.appbrand svg { margin: 0 .1em; display: block; }
.appbrand .tail { font-weight: 400; color: var(--muted); }

/* Which deployment this is. Worth its width the moment int and prod are open in
   two tabs, and app-int.yaml says they are. */
.envtag {
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--faint);
  flex: none;
  margin-left: .15rem;
}

.searchwrap { position: relative; flex: 1 1 auto; max-width: 420px; margin: 0 auto; }
.searchbox {
  width: 100%;
  height: 30px;
  border: 1px solid var(--rule);
  border-radius: 0;
  background: var(--page);
  padding: 0 .6rem;
  font: inherit;
  font-size: .85rem;
  color: var(--ink);
  outline: none;
}
.searchbox::placeholder { color: var(--faint); }
.searchbox:focus { border-color: var(--accent); background: var(--surface); }

.searchresults {
  position: absolute;
  top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-lg);
  max-height: 60vh;
  overflow: auto;
  z-index: 80;
  padding: .2rem;
}
.sr-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .38rem .5rem;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
}
.sr-item:hover, .sr-item.active { background: var(--sunk); }
.sr-item .kind {
  font-family: var(--mono); font-size: .66rem;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--faint); flex: none; min-width: 5.5rem;
}
.sr-item .t { flex: 1; min-width: 0; font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-empty { padding: .6rem .55rem; color: var(--faint); font-size: .85rem; }

.createbtn {
  display: inline-flex; align-items: center; gap: .35rem;
  flex: none;
  border: 0; border-radius: 0;
  background: var(--accent); color: #fff;
  font: inherit; font-weight: 700; font-size: .84rem;
  padding: .38rem .7rem;
  cursor: pointer;
}
.createbtn:hover { background: var(--accent-d); }

/* The account control. Round, because it is a person - the squared tile is
   reserved for agents, and the difference is the whole convention. */
.acct { position: relative; flex: none; }
.avatarbtn {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  background: var(--ink); color: var(--surface);
  font: inherit; font-weight: 700; font-size: .68rem;
  display: grid; place-items: center;
}
.avatarbtn:hover { background: var(--muted); }
.acctdrop {
  position: absolute;
  top: calc(100% + 6px); right: 0;
  min-width: 15rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-lg);
  padding: .35rem;
  z-index: 80;
}
.acctdrop .who {
  padding: .45rem .55rem .5rem;
  border-bottom: 1px solid var(--rule-2);
  margin-bottom: .25rem;
}
.acctdrop .who .em { font-size: .84rem; overflow: hidden; text-overflow: ellipsis; }
.acctdrop .who .org { font-size: .75rem; color: var(--muted); margin-top: .1rem; }
.acctdrop a {
  display: block;
  padding: .4rem .55rem;
  color: var(--ink);
  text-decoration: none;
  font-size: .86rem;
}
.acctdrop a:hover { background: var(--sunk); }
/* The one entry in this menu that leaves the reader's own organisation. Ruled
   off and set in the accent so it does not read as another page of theirs -
   which is the same reason the console's own bar is dark. */
.acctdrop a.staff {
  border-top: 1px solid var(--rule);
  color: var(--accent-d);
  font-weight: 600;
}
.acctdrop .field { margin: .3rem .55rem .5rem; }

/* ============================================================
   Shell
   ============================================================ */

.shell { display: flex; flex: 1; min-height: 0; overflow: hidden; position: relative; }

.scrim {
  display: none;
  position: fixed; inset: var(--appbar-h) 0 0 0;
  background: rgba(22, 17, 15, .35);
  z-index: 55;
}

/* ============================================================
   Sidebar
   ============================================================ */

.sidebar {
  width: var(--nav-w);
  flex: none;
  background: var(--page);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: var(--s5);
  transition: width .16s ease;
}
body:not(.nav-open) .sidebar { width: 0; border-right: 0; }

.navsec { padding: .7rem .5rem .1rem; min-width: calc(var(--nav-w) - 1rem); }
.navsec h5 {
  margin: 0 0 .2rem;
  padding: 0 .45rem;
  font-size: .6rem;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

/* A nav row. The active one takes a red left rule and a tinted ground - the rule
   is what survives at a glance, and it means the active state is not carried by
   font weight alone. */
.navrow {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .32rem .45rem;
  color: var(--ink);
  text-decoration: none;
  font-size: .86rem;
  border-left: 2px solid transparent;
  cursor: pointer;
}
.navrow:hover { background: var(--sunk); }
.navrow.on { background: var(--accent-wash); border-left-color: var(--accent); font-weight: 700; }
.navrow .ic { width: 15px; text-align: center; color: var(--muted); font-size: .74rem; flex: none; }
.navrow.on .ic { color: var(--accent); }
.navrow .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* A queue's depth, in the rail. The point is knowing there is work without
   having to visit the page to find out, so it is only drawn when non-zero. */
.navcount {
  font-family: var(--mono);
  font-size: .64rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--accent);
  color: #fff;
  padding: .05rem .3rem;
  flex: none;
}

/* The agent list, nested under Agents. Hairline on the left so the nesting reads
   without a second colour. */
.navkids { padding-left: .5rem; margin-left: .8rem; border-left: 1px solid var(--rule); }
.navkid {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .26rem .45rem;
  font-size: .83rem;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
}
.navkid:hover { background: var(--sunk); color: var(--ink); }
.navkid.on { background: var(--sunk); color: var(--ink); font-weight: 700; }
.navkid .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* How the last run went. A dot rather than a word because it is scanned down a
   column, never read. */
.navdot { width: 6px; height: 6px; flex: none; background: var(--faint); }
.navdot.ok   { background: var(--ok); }
.navdot.err  { background: var(--accent); }
.navdot.idle { background: var(--faint); }

.navempty { padding: .25rem .55rem .5rem; color: var(--faint); font-size: .8rem; }

/* ============================================================
   Main column
   ============================================================ */

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.crumb {
  padding: .6rem var(--s5) 0;
  font-size: .74rem;
  color: var(--muted);
  font-family: var(--mono);
  flex: none;
}
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { color: var(--accent); }

/* Wraps: the title zone carries an action button on most list pages, and on a
   phone a button that refuses to drop below the heading pushes the heading off
   the screen instead. */
.pagetitle {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .6rem;
  padding: .2rem var(--s5) .5rem;
  flex: none;
}
.pagetitle > .grow { flex: 1 1 16rem; }
.pagetitle h1 { font-size: 1.3rem; margin: 0; letter-spacing: -.022em; font-weight: 700; }
.pagetitle .grow { flex: 1; min-width: 0; }
.pagetitle .lede { margin: .1rem 0 0; }
/* A title that carries a sentence under it stops centring: with two lines of
   lede beside it, a vertically centred action button floats away from the
   heading it belongs to. */
.pagetitle.with-lede { align-items: flex-start; }
.pagetitle.with-lede .agentmark { align-self: flex-start; }
.pagetitle .rolechip {
  font-size: .72rem; color: var(--muted);
  border: 1px solid var(--rule); padding: .05rem .35rem; flex: none;
}

/* An agent's mark. Squared, always - round is a person, and the app bar avatar
   is the only round one on the screen. */
.agentmark {
  width: 30px; height: 30px;
  flex: none;
  background: var(--ink);
  color: var(--surface);
  display: grid; place-items: center;
  font-size: .7rem; font-weight: 700;
  overflow: hidden;
}
.agentmark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.agentmark.sm { width: 22px; height: 22px; font-size: .58rem; }

.tabs {
  display: flex;
  gap: 0;
  padding: 0 calc(var(--s5) - .35rem);
  border-bottom: 1px solid var(--rule);
  overflow-x: auto;
  scrollbar-width: none;
  flex: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; border-radius: 0;
  background: none;
  font: inherit;
  font-size: .86rem;
  color: var(--muted);
  padding: .5rem .6rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  flex: none;
}
.tab:hover { color: var(--ink); background: none; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }

/* The only thing that scrolls. */
.view { flex: 1; overflow-y: auto; padding: var(--s4) var(--s5) var(--s7); }
.view > .viewinner { max-width: var(--content-max); }

/* ============================================================
   The right-hand form panel
   ============================================================
   For the long forms. Slides over the page rather than covering it, so the
   table you are adding a row to stays visible beside it. */

.panelscrim { position: fixed; inset: 0; background: rgba(22, 17, 15, .35); z-index: 95; }

.sidepanel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(30rem, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--rule);
  box-shadow: var(--shadow-lg);
  z-index: 96;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .18s ease;
}
.sidepanel.open { transform: translateX(0); }
@media (prefers-reduced-motion: reduce) {
  .sidepanel { transition: none; transform: translateX(0); }
}

.sidepanel form { display: flex; flex-direction: column; min-height: 0; flex: 1; }

/* The actions sit in the header, not at the foot: on a phone the keyboard
   covers the bottom of the panel, and a Save you have to dismiss the keyboard
   to reach is a Save people miss. */
.sp-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: .7rem var(--s4);
  border-bottom: 1px solid var(--rule);
  flex: none;
}
/* The title truncates rather than pushing Cancel and Save off the edge. Those
   two are the reason the header exists. */
.sp-head h2 {
  margin: 0; flex: 1; min-width: 0; font-size: 1rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sp-actions { display: flex; gap: .4rem; flex: none; }

.sp-body { padding: var(--s4); overflow-y: auto; flex: 1; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: var(--appbar-h); bottom: 0; left: 0;
    z-index: 60;
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .scrim { display: block; }
  .searchwrap { display: none; }
  .createbtn .lbl { display: none; }
  .crumb, .pagetitle { padding-left: var(--s4); padding-right: var(--s4); }
  .tabs { padding: 0 .65rem; }
  .view { padding: var(--s3) var(--s4) var(--s6); }
}

/* ============================================================
   The signed-out frame
   ============================================================
   Login, signup, verify, forgot, reset and onboarding. A navigation rail over
   pages you cannot navigate from is furniture, so they get a centred column and
   the wordmark instead. Same tokens, so it still reads as one product. */

body.auth {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.55 var(--grot);
  -webkit-font-smoothing: antialiased;
  margin: 0;
  min-height: 100%;
}
.authbar {
  display: flex;
  justify-content: center;
  padding: var(--s6) var(--s4) 0;
}
.authmain { padding: 0 var(--s4) var(--s7); }
