/* Juno base layer — paper, ink, hairline rules. Tokens live in tokens.css. */

* { box-sizing: border-box; }

/* The `hidden` attribute must win over the layout `display` a component sets. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  font-variant-ligatures: none;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-wash); color: var(--ink); }

/* Focus is an outline so it occupies no visual depth. */
:focus-visible {
  outline: var(--focus-width) solid var(--accent);
  outline-offset: var(--focus-offset);
}

h1, h2, h3, h4, h5 {
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }

/* Reading text. Chrome stays monospace; prose opts into the serif. */
.prose { font-family: var(--font-prose); font-size: var(--text-md); line-height: var(--leading-prose); }

/* ---------------------------------------------------------------- scrollbars */

* { scrollbar-width: thin; scrollbar-color: var(--rule-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--rule-strong);
  border: 3px solid var(--paper);
}
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

/* --------------------------------------------------------------------- brand */

.brand { 
  display: flex; 
  align-items: center; 
  gap: var(--space-2); 
  text-decoration: none; 
  color: inherit;
  transition: opacity var(--duration) var(--ease);
}
.brand:hover { opacity: 0.8; }

/* A solid square with subtle polish */
.brand-mark {
  width: 16px;
  height: 16px;
  flex: none;
  background: var(--accent);
  border-radius: var(--radius-sm);
  transition: transform var(--duration) var(--ease);
}
.brand:hover .brand-mark {
  transform: scale(1.05);
}

.brand-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  letter-spacing: 0.05em;
}
.brand-sub { display: block; font-size: var(--text-2xs); color: var(--ink-faint); }

/* -------------------------------------------------------------------- panels
   Not cards. A panel is a region bounded by hairlines; it shares the page
   background and casts nothing. */

.panel {
  background: var(--paper);
  border: var(--rule-width) solid var(--rule);
  border-radius: var(--radius);
}

.panel-pad { padding: var(--pad-panel-tight); }

/* Section label: monospace, sentence case, sitting on a rule. */
.panel-title {
  margin: 0 0 var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: var(--rule-width) solid var(--rule);
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-none);
  color: var(--ink-muted);
}

/* A title sharing its rule with a control on the right. */
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: var(--rule-width) solid var(--rule);
}
.panel-head .panel-title { margin: 0; padding: 0; border-bottom: none; }

/* A panel that takes the remaining column height and scrolls its own list. */
.panel-fill { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.panel-fill > .toggle-list,
.panel-fill > .entry-list,
.panel-fill > .activity,
.panel-fill > .detail-body { overflow-y: auto; }

/* --------------------------------------------------------------------- forms */

label.field { display: block; margin-bottom: var(--space-3); }
label.field > span {
  display: block;
  margin-bottom: var(--space-1);
  font-size: var(--text-2xs);
  font-weight: var(--weight-normal);
  color: var(--ink-muted);
}

input, select, textarea {
  width: 100%;
  padding: var(--space-1) var(--space-2);
  min-height: var(--control-h);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  background: var(--paper-raised);
  border: var(--rule-width) solid var(--rule-strong);
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--duration) var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
/* A ring outside a neutral border. Recolouring the border too made a focused
   field read as an error. */
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: var(--focus-width) solid var(--accent);
  outline-offset: var(--focus-offset);
}
textarea { resize: vertical; min-height: var(--space-16); line-height: var(--leading-normal); }
select { padding-right: var(--space-1); }

/* Checkboxes opt out of the full-width field rule. */
input[type="checkbox"], input[type="radio"] {
  width: auto;
  min-height: auto;
  accent-color: var(--accent);
}
.check-row {
  margin: var(--space-1) 0 var(--space-4);
  font-size: var(--text-xs);
  color: var(--ink-muted);
}

/* ------------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--control-h);
  padding: 0 var(--space-3);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: var(--weight-normal);
  color: var(--ink);
  background: var(--paper);
  border: var(--rule-width) solid var(--rule-strong);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--duration) var(--ease), border-color var(--duration) var(--ease),
    background-color var(--duration) var(--ease);
}
.btn:hover { border-color: var(--ink); }
.btn:disabled { color: var(--ink-faint); border-color: var(--rule); cursor: not-allowed; }

/* Primary is solid ink, not accent — the accent stays reserved for state. */
.btn-primary {
  color: var(--ink-inverse);
  background: var(--ink);
  border-color: var(--ink);
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-primary:disabled { background: var(--ink-faint); border-color: var(--ink-faint); color: var(--paper); }

.btn-ghost { border-color: transparent; color: var(--ink-muted); }
.btn-ghost:hover { color: var(--ink); border-color: var(--rule-strong); }

.btn-danger { color: var(--status-bad); border-color: var(--rule-strong); }
.btn-danger:hover { border-color: var(--status-bad); }

.btn-sm { height: var(--control-h-sm); padding: 0 var(--space-2); font-size: var(--text-2xs); }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------------- tags
   Square, hairline, monospace. Replaces the old rounded-pill chips. */

.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0 var(--space-1);
  min-height: 18px;
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  line-height: var(--leading-snug);
  color: var(--ink-muted);
  background: var(--paper);
  border: var(--rule-width) solid var(--rule);
  border-radius: var(--radius);
  white-space: nowrap;
}
.tag-accent { color: var(--accent); border-color: var(--accent); }
.tag-strong { color: var(--ink); border-color: var(--rule-strong); }
.tag-ok { color: var(--status-ok); border-color: var(--status-ok); }
.tag-warn { color: var(--status-warn); border-color: var(--status-warn); }
.tag-bad { color: var(--status-bad); border-color: var(--status-bad); }

/* ------------------------------------------------------------- status marks
   A 6px solid square. No pill, no halo, no pulse. */

.mark {
  width: var(--mark-status);
  height: var(--mark-status);
  flex: none;
  background: var(--status-idle);
}
.mark-ok { background: var(--status-ok); }
.mark-warn { background: var(--status-warn); }
.mark-bad { background: var(--status-bad); }

/* -------------------------------------------------------------------- tables */

table.data { width: 100%; border-collapse: collapse; font-size: var(--text-xs); }
table.data th {
  text-align: left;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-none);
  color: var(--ink-muted);
  border-bottom: var(--rule-width) solid var(--rule-strong);
  white-space: nowrap;
}
table.data td {
  padding: var(--space-2);
  border-bottom: var(--rule-width) solid var(--rule);
  vertical-align: top;
}
table.data tbody tr:hover { background: var(--paper-sunken); }

/* -------------------------------------------------------------------- toasts */

#toasts {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-width: 320px;
}
.toast {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  color: var(--ink);
  background: var(--paper);
  border: var(--rule-width) solid var(--rule-strong);
  border-left: 2px solid var(--ink);
  border-radius: var(--radius);
  opacity: 1;
  transition: opacity var(--duration) var(--ease);
}
.toast.error { border-left-color: var(--status-bad); }
.toast.ok { border-left-color: var(--status-ok); }
.toast.leaving { opacity: 0; }

/* --------------------------------------------------------------------- utils */

.row { display: flex; align-items: center; gap: var(--space-2); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.row-end { justify-content: flex-end; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }
.mono { font-family: var(--font-ui); font-size: var(--text-xs); }
.tiny { font-size: var(--text-2xs); }
.small { font-size: var(--text-xs); }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.push-right { margin-left: auto; }

.empty {
  padding: var(--space-4) var(--space-2);
  color: var(--ink-faint);
  font-size: var(--text-2xs);
}

/* Spacing utilities, named for their grid step so no raw px reaches markup. */
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-3 { margin-bottom: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.field-inline { margin: 0; }
.scroll-y { overflow-y: auto; }

/* Busy indicator: a static accent square beside a text label. Nothing spins. */
.busy-mark {
  display: inline-block;
  width: var(--mark-status);
  height: var(--mark-status);
  flex: none;
  background: var(--accent);
  vertical-align: baseline;
}

/* ----------------------------------------------------------------- app shell */

.app-nav {
  position: relative;
  z-index: var(--z-nav);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--nav-height);
  padding: 0 var(--space-4);
  border-bottom: var(--rule-width) solid var(--rule-strong);
  background: var(--paper);
}
/* A ruled sidebar column, used by both the chat and memory layouts. */
.side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}
.side > .panel {
  border: none;
  border-bottom: var(--rule-width) solid var(--rule);
  border-radius: var(--radius);
}
.side > .panel:last-child { border-bottom: none; }

.nav-links { display: flex; gap: var(--space-3); }
/* A long display name shortens rather than pushing the sign-out button off. */
.app-nav [data-whoami] { min-width: 0; }
.app-nav [data-whoami] .who-name { max-width: 18ch; }
.nav-link {
  display: flex;
  align-items: center;
  height: var(--nav-height);
  padding: 0;
  font-size: var(--text-xs);
  color: var(--ink-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color var(--duration) var(--ease), border-color var(--duration) var(--ease);
}
.nav-link:hover { color: var(--ink); }
.nav-link.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ------------------------------------------------------------------- footer */

.app-footer {
  flex: none;
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--space-8);
  padding: 0 var(--space-4);
  border-top: var(--rule-width) solid var(--rule);
  background: var(--paper);
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  color: var(--ink-faint);
  letter-spacing: var(--tracking-none);
}

kbd {
  padding: 0 var(--space-1);
  font-family: var(--font-ui);
  font-size: var(--text-3xs);
  color: var(--ink-muted);
  border: var(--rule-width) solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--paper-sunken);
}

/* ------------------------------------------------------------ side drawers
   A workspace column stays a column while there is room for it. Below the
   layout breakpoint the same markup becomes a sheet that slides over the work
   area, so nothing is dropped from a narrow screen — only relocated. Opened by
   [data-drawer-toggle] buttons; see initDrawers() in api.js. */

.drawer-toggle,
.drawer-close,
.drawer-scrim { display: none; }

@media (max-width: 1024px) {
  .drawer-toggle,
  .drawer-close { display: inline-flex; }

  [data-drawer-panel] {
    position: fixed;
    top: var(--nav-height);
    bottom: 0;
    /* Above the stage overlays, which are themselves at the overlay level. */
    z-index: var(--z-tooltip);
    width: min(320px, 88vw);
    background: var(--paper);
    overflow-y: auto;
    overscroll-behavior: contain;
    transition: transform var(--duration) var(--ease);
  }
  [data-drawer-panel][data-drawer-side="left"] {
    left: 0;
    border-right: var(--rule-width) solid var(--rule-strong);
    transform: translateX(-101%);
  }
  [data-drawer-panel][data-drawer-side="right"] {
    right: 0;
    border-left: var(--rule-width) solid var(--rule-strong);
    transform: translateX(101%);
  }
  [data-drawer-panel][data-open] { transform: none; }

  html[data-drawer] .drawer-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-tooltip) - 1);
    background: color-mix(in srgb, var(--ink) 38%, transparent);
  }

  /* A sheet carries its own dismissal. The panels below it are already titled,
     so this bar holds nothing but the way out. */
  .drawer-head {
    position: sticky;
    top: 0;
    z-index: var(--z-base);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: var(--space-2) var(--pad-panel-tight);
    background: var(--paper);
    border-bottom: var(--rule-width) solid var(--rule-strong);
  }
}

/* ---------------------------------------------------------------- responsive
   Phone and small-tablet chrome: metadata gives way to navigation, controls
   grow to a thumb, and fields hit the 16px floor below which iOS zooms the
   whole page on focus. */

@media (max-width: 820px) {
  :root {
    --gutter: var(--space-3);
    --pad-panel: var(--space-3);
    --control-h: 32px;
    --control-h-sm: 28px;
  }

  input, select, textarea { font-size: 16px; }

  .app-nav { gap: var(--space-3); padding: 0 var(--space-3); }
  .app-nav [data-whoami] { display: none; }
  .brand-sub { display: none; }
  .nav-links { gap: var(--space-3); }

  #toasts { left: var(--space-3); right: var(--space-3); bottom: var(--space-3); max-width: none; }

  .app-footer { height: var(--space-7); }
  .panel-pad { padding: var(--space-3); }
}

@media (max-width: 480px) {
  .empty { padding: var(--space-3) 0; }
}
