:root {
  --ink: #1c1915;
  --muted: #6d645b;
  --paper: #f4efe6;
  --card: #fffdf8;
  --line: #e3d9cc;
  --aside: #1e2a24;
  --aside-text: #efe7da;
  --accent: #c65a2e;
  --accent-ink: #fff8f3;
  --ok: #1f6b45;
  --shadow: 0 18px 40px rgba(48, 32, 16, 0.08);
  font-family: Outfit, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
body {
  margin: 0;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg, video, canvas { max-width: 100%; height: auto; }

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 1fr auto;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
.app > aside {
  grid-row: 1 / -1;
}
.app > main {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}
.app > .app-footer {
  grid-column: 2;
  grid-row: 2;
}

aside {
  background: var(--aside);
  color: var(--aside-text);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand > div { min-width: 0; }
.brand strong { display: block; font-family: Fraunces, Georgia, serif; font-size: 1.4rem; }
.brand small { color: #c8bfb2; display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#brand-user {
  color: #efe7da;
  cursor: pointer;
}
#brand-user:hover { text-decoration: underline; }
.mark {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--accent); color: white;
  font-family: Fraunces, Georgia, serif; font-size: 1.4rem;
}

nav { display: flex; flex-direction: column; gap: 6px; }
.nav {
  text-align: left; border: 0; background: transparent; color: #d9d0c4;
  padding: 10px 12px; border-radius: 12px;
}
.nav.active, .nav:hover { background: rgba(255,255,255,0.08); color: white; }
.nav[hidden] { display: none !important; }
.aside-note { margin-top: auto; color: #b7aea2; font-size: 0.85rem; line-height: 1.45; }

main {
  padding: 32px 40px 24px;
  max-width: 980px;
  width: 100%;
  min-width: 0;
}
.panel { display: none; }
.panel.visible { display: block; }
.prose { display: grid; gap: 12px; line-height: 1.55; }
.prose p { margin: 0; color: var(--ink); }
.prose a { color: var(--accent); }
.panel-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.eyebrow { margin: 0 0 4px; letter-spacing: 0.14em; text-transform: uppercase; font-size: 0.72rem; color: var(--accent); }
h1 { margin: 0; font-family: Fraunces, Georgia, serif; font-weight: 520; font-size: 2.4rem; }

.ghost, button[type="submit"] {
  border: 0; border-radius: 999px; padding: 10px 16px;
}
.ghost { background: transparent; border: 1px solid var(--line); }
button[type="submit"] { background: var(--ink); color: var(--accent-ink); }

.thread {
  min-height: 420px; max-height: calc(100vh - 280px); overflow: auto;
  display: flex; flex-direction: column; gap: 12px; padding-bottom: 12px;
}
.bubble {
  max-width: min(72%, 100%);
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.45;
  box-shadow: var(--shadow);
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.bubble.user { margin-left: auto; background: #f3d2c3; }
.bubble.agent { background: var(--card); border: 1px solid var(--line); }
.bubble .who { display: block; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.bubble .plain { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.bubble .md { white-space: normal; overflow-wrap: anywhere; word-break: break-word; min-width: 0; }
.bubble .md p { margin: 0 0 0.65em; }
.bubble .md p:last-child,
.bubble .md ul:last-child,
.bubble .md ol:last-child,
.bubble .md pre:last-child { margin-bottom: 0; }
.bubble .md ul,
.bubble .md ol { margin: 0 0 0.65em; padding-left: 1.25em; }
.bubble .md li { margin: 0.15em 0; }
.bubble .md h1,
.bubble .md h2,
.bubble .md h3 {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0.2em 0 0.4em;
}
.bubble .md a { color: var(--accent); }
.bubble .md code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.88em;
  background: #f3eee6;
  padding: 0.1em 0.35em;
  border-radius: 6px;
}
.bubble .md pre {
  margin: 0 0 0.65em;
  background: #1e2a24;
  color: #f4efe6;
  padding: 10px 12px;
  border-radius: 12px;
  overflow: auto;
}
.bubble .md pre code { background: transparent; color: inherit; padding: 0; }

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
textarea, input, select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 18px; box-shadow: var(--shadow); }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 0.86rem; color: var(--muted); }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.job {
  display: grid; grid-template-columns: 1fr auto; gap: 8px 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px;
}
.job h3 { margin: 0; font-size: 1rem; }
.job p { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }
.job-detail {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.job-actions { display: flex; gap: 8px; align-items: center; }
.job-actions button { border-radius: 999px; border: 1px solid var(--line); background: white; padding: 8px 12px; }
.job.off { opacity: 0.62; }
.pill { font-size: 0.75rem; border-radius: 999px; padding: 3px 8px; background: #efe6da; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; }
.stat b { display: block; font-family: Fraunces, Georgia, serif; font-size: 1.7rem; font-weight: 520; }
.stat span { color: var(--muted); font-size: 0.82rem; }
.pager { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.pager .note { margin: 0; }
.role-select { min-width: 110px; padding: 8px 10px; border-radius: 999px; }
.note { color: var(--muted); font-size: 0.85rem; }
.status { color: var(--ok); font-size: 0.9rem; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }

.gate {
  min-height: calc(100vh - 72px);
  display: grid;
  place-items: center;
  padding: 24px 16px 96px;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
body.authed #gate,
body.authed #gate-footer,
#shell[hidden],
#gate[hidden] { display: none !important; }
body.authed #shell { display: grid; }
body:not(.authed) #shell { display: none !important; }
.login-card,
.public-card {
  width: min(440px, 100%);
  max-width: 100%;
  display: grid;
  gap: 12px;
  justify-items: center;
  text-align: center;
}
.public-card {
  justify-items: start;
  text-align: left;
}
.public-card[hidden],
.login-card[hidden] { display: none !important; }
.public-card .public-back { justify-self: start; margin-bottom: 4px; }
.public-card .prose { width: 100%; }
.login-card h1,
.public-card h1 { font-size: 2rem; }
.login-card .note { max-width: 36ch; }
.login-card a,
.public-card a { color: var(--accent); }
.google-login { min-height: 48px; display: grid; place-items: center; max-width: 100%; overflow: hidden; }
.google-login iframe { color-scheme: light; max-width: 100%; }
#logout { margin-top: auto; }
.aside-note { margin-top: 12px; }

.site-footer {
  width: 100%;
  max-width: 100%;
  padding: 14px 20px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 10px 16px;
  text-align: center;
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.app-footer {
  padding-left: 40px;
  padding-right: 40px;
  max-width: 980px;
}
.gate-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
}
.footer-links {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap;
  gap: 10px 14px;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
}
.footer-link {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 0.88rem;
  white-space: nowrap;
  display: inline;
}
.footer-link:hover { color: var(--ink); text-decoration: underline; }
.footer-copy {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.footer-copy::before {
  content: "·";
  margin-right: 16px;
  color: var(--line);
}

/* Mobile chrome — hidden on desktop so the web layout stays unchanged */
.mobile-bar,
.mobile-menu,
.user-sheet { display: none; }

.icon-btn {
  width: 42px; height: 42px; border: 0; border-radius: 12px;
  background: transparent; color: inherit;
  display: grid; place-items: center; padding: 0;
}
.user-avatar-fallback {
  font-family: Outfit, "Segoe UI", sans-serif;
  font-weight: 640;
  font-size: 0.82rem;
  line-height: 1;
}
.user-avatar-fallback.lg { font-size: 1.35rem; }
.user-sheet-card {
  background: #fff;
  color: #0a0a0a;
  border-radius: 28px 28px 0 0;
  padding: 22px 20px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18);
  position: relative;
  width: min(440px, 100%);
}
.user-sheet-hero {
  display: flex; align-items: center; gap: 14px; margin-bottom: 16px; padding-right: 36px;
}
.user-sheet-hero img,
.user-sheet-hero .user-avatar-fallback,
.mobile-account-btn img,
.mobile-account-btn .user-avatar-fallback {
  width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 50%;
}
.user-sheet-hero img,
.user-sheet-hero .user-avatar-fallback {
  width: 56px; height: 56px;
  background: #00abf4; color: white;
  display: grid; place-items: center; flex-shrink: 0;
}
.user-sheet-hero h2 {
  margin: 0;
  font-family: Outfit, "Segoe UI", sans-serif;
  font-size: 1.25rem;
  font-weight: 640;
}
.user-sheet-hero .note { margin: 4px 0 0; word-break: break-word; color: #6b7280; }
.user-sheet-meta {
  margin: 0 0 16px; display: grid; gap: 10px;
}
.user-sheet-meta > div {
  display: grid; grid-template-columns: 88px 1fr; gap: 8px;
  padding: 12px 14px; border: 1px solid #e8eaed; border-radius: 16px;
  background: #f7f8f9;
}
.user-sheet-meta dt {
  margin: 0; color: #6b7280; font-size: 0.75rem;
  text-transform: uppercase; letter-spacing: 0.06em; align-self: center;
}
.user-sheet-meta dd { margin: 0; font-size: 0.95rem; word-break: break-word; }
.sheet-close {
  position: absolute; top: 12px; right: 12px;
  background: transparent; border: 1px solid #e8eaed; color: #0a0a0a;
  font-size: 1.4rem; line-height: 1;
}
.sheet-logout {
  width: 100%; border: 0; border-radius: 999px; padding: 13px 16px;
  background: #00abf4; color: #fff; font-weight: 600;
}

@media (max-width: 860px) {
  :root {
    --mobile-ink: #0a0a0a;
    --mobile-muted: #6b7280;
    --mobile-bg: #f7f8f9;
    --mobile-accent: #00abf4;
    --mobile-bar-h: 56px;
  }

  html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    position: relative;
  }

  .app {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    min-height: 100dvh;
    min-height: 100svh;
    background: #000;
    overflow-x: hidden;
    position: relative;
  }
  .app > aside,
  .app > main,
  .app > .app-footer {
    grid-column: auto;
    grid-row: auto;
  }
  body.authed #shell { display: flex; }
  body.menu-open { overflow: hidden; }
  body.menu-open .app { overflow: hidden; }

  /* Mobile header: menu left, brand center, account right */
  .mobile-bar {
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 80;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-height: var(--mobile-bar-h);
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    background: #000;
    color: #fff;
  }
  .mobile-wordmark {
    justify-self: center;
    color: #fff;
    text-decoration: none;
    font-family: Outfit, "Segoe UI", sans-serif;
    font-weight: 640;
    font-size: 0.95rem;
    letter-spacing: 0.12em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  .mobile-account-btn {
    justify-self: end;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    background: transparent;
    color: #fff;
    padding: 0;
    border-radius: 999px;
    overflow: hidden;
  }
  .mobile-account-btn img,
  .mobile-account-btn .user-avatar-fallback {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--mobile-accent);
    color: #fff;
    display: grid;
    place-items: center;
    flex-shrink: 0;
  }
  .menu-toggle {
    justify-self: start;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: #fff;
    display: grid;
    place-items: center;
    padding: 0;
    flex-shrink: 0;
  }
  .menu-toggle-bars,
  .menu-toggle-bars::before,
  .menu-toggle-bars::after {
    display: block;
    width: 18px;
    height: 1.5px;
    background: currentColor;
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }
  .menu-toggle-bars { position: relative; }
  .menu-toggle-bars::before,
  .menu-toggle-bars::after {
    content: "";
    position: absolute;
    left: 0;
  }
  .menu-toggle-bars::before { top: -6px; }
  .menu-toggle-bars::after { top: 6px; }
  body.menu-open .menu-toggle-bars { background: transparent; }
  body.menu-open .menu-toggle-bars::before {
    top: 0;
    transform: rotate(45deg);
  }
  body.menu-open .menu-toggle-bars::after {
    top: 0;
    transform: rotate(-45deg);
  }
  body.menu-open .mobile-bar {
    background: var(--mobile-bg);
    color: var(--mobile-ink);
  }
  body.menu-open .mobile-wordmark,
  body.menu-open .menu-toggle {
    color: var(--mobile-ink);
  }

  /* Full-screen menu overlay */
  .mobile-menu {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    z-index: 70;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    background: var(--mobile-bg);
    padding:
      calc(var(--mobile-bar-h) + env(safe-area-inset-top) + 16px)
      max(20px, env(safe-area-inset-right))
      max(24px, env(safe-area-inset-bottom))
      max(20px, env(safe-area-inset-left));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .mobile-menu[hidden] { display: none !important; }
  .mobile-menu-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
  }
  .mobile-nav-link {
    border: 0;
    background: transparent;
    text-align: left;
    padding: 12px 0;
    font-size: clamp(1.25rem, 6vw, 1.5rem);
    font-weight: 640;
    color: var(--mobile-ink);
    letter-spacing: -0.02em;
    width: 100%;
  }
  .mobile-nav-link.active { color: var(--mobile-accent); }
  .mobile-nav-link[hidden] { display: none !important; }
  .mobile-menu-footer {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: auto;
    padding-top: 24px;
  }
  .mobile-cta {
    border: 0;
    border-radius: 999px;
    padding: 14px 18px;
    font-size: 1rem;
    font-weight: 600;
    background: var(--mobile-accent);
    color: #fff;
    width: 100%;
  }
  .mobile-cta.ghost-cta {
    background: transparent;
    color: var(--mobile-ink);
    border: 1px solid #d7dbe0;
  }

  /* Hide desktop sidebar on mobile */
  aside { display: none !important; }

  main {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    padding: 0;
    background:
      radial-gradient(120% 80% at 50% -10%, rgba(0, 171, 244, 0.08), transparent 55%),
      var(--paper);
    border-radius: 24px 24px 0 0;
    overflow: hidden;
  }

  .app-footer,
  .gate-footer {
    flex-direction: row !important;
    flex-wrap: nowrap;
    gap: 8px 12px;
  }
  .app-footer {
    flex-shrink: 0;
    max-width: 100%;
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
    background: var(--paper);
    border-top: 1px solid var(--line);
  }
  .app-footer .footer-links,
  .gate-footer .footer-links {
    flex-direction: row !important;
  }
  .app-footer .footer-link,
  .gate-footer .footer-link,
  .app-footer .footer-copy,
  .gate-footer .footer-copy {
    font-size: 0.78rem;
  }
  .footer-copy::before { margin-right: 12px; }
  .gate-footer {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }

  .panel {
    flex: 1;
    min-height: 0;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    padding: 16px 14px max(16px, env(safe-area-inset-bottom));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .panel.visible { display: flex; flex-direction: column; }

  /* Talk: composer pinned to bottom */
  #talk.panel.visible {
    padding-bottom: 0;
    overflow: hidden;
  }
  #talk .panel-head {
    flex-shrink: 0;
    margin-bottom: 12px;
    max-width: 100%;
  }
  #talk .thread {
    flex: 1;
    min-height: 0;
    min-width: 0;
    max-height: none;
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
  }
  #talk .composer {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: end;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    padding: 10px 0 max(10px, env(safe-area-inset-bottom));
    background: var(--paper);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.04);
  }
  #talk .composer textarea {
    min-height: 44px;
    max-height: 120px;
    max-width: 100%;
    min-width: 0;
    resize: none;
  }
  #talk .composer button[type="submit"] {
    width: auto;
    min-width: 64px;
    max-width: 30vw;
    padding: 12px 14px;
    border-radius: 999px;
    background: var(--mobile-accent);
    color: #fff;
    flex-shrink: 0;
  }

  .panel-head {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
    max-width: 100%;
  }
  .eyebrow { color: var(--mobile-accent); }
  .form-grid, .stats { grid-template-columns: 1fr; }
  .card,
  .job,
  .stat,
  .table-wrap,
  .bubble.agent,
  .prose {
    border-radius: 22px;
    max-width: 100%;
    min-width: 0;
  }
  button[type="submit"] {
    border-radius: 999px;
    background: var(--mobile-accent);
    color: #fff;
  }
  .bubble { max-width: min(92%, 100%); border-radius: 22px; }
  .bubble.user { background: #d9f2ff; }
  .bubble .md pre { max-width: 100%; overflow-x: auto; }
  h1 {
    font-size: clamp(1.35rem, 6vw, 1.75rem);
    letter-spacing: -0.03em;
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  .job { grid-template-columns: 1fr; }
  .job-actions { justify-content: flex-start; flex-wrap: wrap; }
  .table-wrap {
    margin-inline: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .pager { flex-wrap: wrap; }
  .stats { grid-template-columns: 1fr; }

  .user-sheet {
    display: flex;
    position: fixed; inset: 0; z-index: 90;
    align-items: flex-end; justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    padding: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }
  .user-sheet[hidden] { display: none !important; }
  .user-sheet-card {
    width: 100%;
    max-width: 100%;
    padding-bottom: max(28px, env(safe-area-inset-bottom));
    animation: sheet-up 0.22s ease;
  }

  .gate {
    padding: 20px 14px 100px;
    width: 100%;
    max-width: 100%;
  }
  .login-card,
  .public-card {
    width: 100%;
    max-width: 100%;
  }
}

@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

@media (min-width: 861px) {
  .user-sheet {
    display: flex;
    position: fixed; inset: 0; z-index: 70;
    align-items: center; justify-content: center;
    background: rgba(20, 16, 12, 0.35);
    padding: 24px;
  }
  .user-sheet[hidden] { display: none !important; }
  .user-sheet-card {
    border-radius: 22px;
    width: min(400px, 100%);
  }
}
