:root {
  --harbor: #17303a;
  --paper: #fbf8f1;
  --white: #ffffff;
  --rust: #b14b32;
  --sage: #5b756c;
  --rule: #d6d2c8;
  --bg: var(--paper);
  --ink: var(--harbor);
  --muted: #53636a;
  --line: var(--rule);
  --accent: var(--rust);
  --ok: #2f6b4f;
  --bad: #9b1d2a;
  --unread-tint: #f7e2cf;
  --selected-tint: #fff6ef;
  --tree-new-tint: #fff4ed;
  --shadow: 0 10px 30px rgba(36, 22, 20, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 400px at 10% -10%, rgba(196, 92, 45, 0.12), transparent),
    var(--bg);
  color: var(--ink);
  font: 16px/1.45 Aptos, "Segoe UI", system-ui, sans-serif;
}
body { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

#app { max-width: 520px; margin: 0 auto; padding: 16px 16px 8px; }
body[data-page="app"] { padding-bottom: 0; }
body[data-page="app"] #app { max-width: none; margin: 0; padding: 0; }
.auth-panel { max-inline-size: 32rem; margin-inline: auto; padding: clamp(2rem, 7vw, 5rem) 1rem; }
.auth-panel form { padding: 1.5rem; background: var(--white); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); }
.auth-tabs { display: flex; gap: .25rem; margin-block: 1.5rem; padding: .25rem; background: #efe9dd; border-radius: 12px; }
.auth-tab { flex: 1; display: flex; align-items: center; justify-content: center; min-block-size: 44px; padding: .55rem 1rem; border-radius: 9px; color: var(--harbor); font-weight: 700; text-decoration: none; }
.auth-tab:hover { background: rgb(255 255 255 / .6); }
.auth-tab.current { background: var(--white); box-shadow: 0 1px 3px rgb(23 48 58 / .15); }
.auth-divider { position: relative; margin: 1.25rem 0; color: var(--muted); text-align: center; }
.auth-divider::before, .auth-divider::after { content: ""; position: absolute; inset-block-start: 50%; inline-size: calc(50% - 1.25rem); border-block-start: 1px solid var(--rule); }
.auth-divider::before { inset-inline-start: 0; }
.auth-divider::after { inset-inline-end: 0; }
.google-button { display: flex; align-items: center; justify-content: center; gap: .6rem; min-block-size: 46px; padding: .65rem 1.1rem; background: var(--white); color: var(--harbor); border: 1px solid var(--rule); border-radius: 12px; font-weight: 700; text-decoration: none; }
.google-button:hover { background: var(--selected-tint); border-color: var(--harbor); }
.auth-note { margin-block-start: 1rem; font-size: .9rem; text-align: center; }
.field { display: grid; gap: .4rem; margin: 0 0 1rem; }
.check-field { display: flex; align-items: center; gap: .65rem; }
.check-field input { inline-size: 1.25rem; block-size: 1.25rem; min-block-size: 0; padding: 0; accent-color: var(--rust); }
.check-field label { font-weight: 500; }

/* Buttons and link-buttons inside the application; the landing keeps its own treatment. */
body[data-page="app"] .button { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; inline-size: auto; min-block-size: 44px; padding: .65rem 1.1rem; border: 1px solid transparent; border-radius: 12px; font-weight: 700; line-height: 1.2; text-decoration: none; cursor: pointer; }
body[data-page="app"] .button.primary { background: var(--rust); color: var(--white); border-color: var(--rust); }
body[data-page="app"] .button.primary:hover, body[data-page="app"] button.primary:hover { background: #983f29; border-color: #983f29; }
body[data-page="app"] .secondary { background: var(--white); color: var(--harbor); border: 1px solid var(--harbor); font-weight: 700; }
body[data-page="app"] .secondary:hover { background: var(--selected-tint); }
body[data-page="app"] .danger:hover { background: #f6d9dd; }
body[data-page="app"] .text-button { inline-size: 100%; background: transparent; color: var(--white); border: 1px solid rgb(255 255 255 / .45); }
body[data-page="app"] .text-button:hover { background: rgb(255 255 255 / .08); }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; color: var(--accent); }
h1, h2, h3 { font-family: "Iowan Old Style", "Palatino Linotype", Palatino, serif; margin: 0 0 8px; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
.muted { color: var(--muted); margin: 0 0 12px; }
.screen { animation: rise 0.25s ease; }
.hidden { display: none !important; }

.card, .hero, .menu, .item {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card, .hero { padding: 16px; margin-bottom: 14px; }
.stack { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
input, select, textarea, button {
  font: inherit;
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 12px 14px;
  background: #fff;
  color: var(--ink);
}
button, a { min-block-size: 44px; }
.skip-link, .back-link, .landing-header nav a, .hero-cta .button,
.closing .button, .landing-footer > a { display: inline-flex; align-items: center; }
.skip-link { position: absolute; inset-block-start: .5rem; inset-inline-start: .5rem; z-index: 50; padding: .6rem 1rem; background: var(--harbor); color: var(--white); font-weight: 700; transform: translateY(-150%); }
.skip-link:focus { transform: none; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--rust);
  outline-offset: 3px;
}
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: auto; }
button { min-height: 46px; cursor: pointer; }
.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.ghost { background: transparent; }
.danger { background: #fbeaec; color: var(--bad); border-color: #f0c9ce; }
.menu { text-align: left; font-weight: 700; margin-bottom: 8px; }
.inline { display: flex; gap: 8px; }
.inline > * { flex: 1; }
.wrap { flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.row-between h2 { margin: 0; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { background: var(--paper); border-radius: var(--radius); padding: 14px; border: 1px solid var(--line); }
.stat b { display: block; font-size: 1.4rem; }
.stat span { color: var(--muted); font-size: 13px; }

.list { display: grid; gap: 10px; }
.item { padding: 14px; }
.item h3 { margin: 0 0 4px; font-size: 1.02rem; }
.item p { margin: 0; color: var(--muted); font-size: 14px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #efe4d6; }
.pill.ok { background: #dcebde; color: var(--ok); }
.pill.bad { background: #f8dfe2; color: var(--bad); }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 250, 243, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.tabbar button {
  border: 0;
  background: transparent;
  min-height: 48px;
  font-size: 13px;
  font-weight: 700;
}
.tabbar button.active { color: var(--accent); }

.toast {
  position: fixed;
  left: 16px; right: 16px; bottom: calc(92px + env(safe-area-inset-bottom));
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  border-radius: 12px;
  text-align: center;
  z-index: 20;
}

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Authenticated reading canvas. Kept separate from the landing styles above. */
/* The sidebar's width lives here, as padding, so `main` can centre itself
   in the space that is left. Carried on `main` as a start margin it left a
   capped content block flush against the rail and the whole right side of a
   wide screen empty. */
.workspace { min-height: 100dvh; padding-inline-start: 16rem; background: var(--paper); }
.workspace .mobile-header { display: none; }
.workspace .mobile-nav { display: none; }
.workspace .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 2; inline-size: 16rem; display: flex; flex-direction: column; gap: 1.25rem; padding: 2rem 1.25rem; background: var(--harbor); color: var(--white); }
.workspace .sidebar nav { display: grid; gap: .25rem; }
.workspace .sidebar a { display: flex; align-items: center; min-block-size: 44px; padding: .45rem .6rem; color: #f4f7f5; text-decoration: none; border-inline-start: 2px solid transparent; }
.workspace .sidebar a:hover, .workspace .sidebar a.current { background: rgb(255 255 255 / .08); border-inline-start-color: var(--rust); }
.workspace .sidebar .brand { padding: 0; font: 1.5rem/1.1 "Iowan Old Style", "Palatino Linotype", Palatino, serif; }
.workspace .plan-note { margin-block-start: auto; color: #cdd8d4; font-size: .9rem; }
.workspace main {
  max-inline-size: 72rem;
  min-block-size: 100dvh;
  margin-inline: auto;
  padding-block: clamp(1.5rem, 4vw, 3.5rem);
  /* A display inset is not a phone-only concern: a laptop in a dock and a
     phone asking for the desktop site both report widths above the compact
     breakpoint. */
  padding-inline:
    max(clamp(1.5rem, 4vw, 3.5rem), env(safe-area-inset-left, 0px))
    max(clamp(1.5rem, 4vw, 3.5rem), env(safe-area-inset-right, 0px));
}
.workspace .page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-block-end: 2rem; }
.workspace .overview { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 1rem; margin-block-end: 2rem; padding-block: 1.5rem; border-block: 3px solid var(--harbor); }
.workspace .stream { padding: 0; margin: 0; list-style: none; border-block-start: 1px solid var(--rule); }
.workspace .stream li { padding: 1rem 0; border-block-end: 1px solid var(--rule); }
.workspace .stream a { color: var(--harbor); font-weight: 700; }
.workspace .empty { color: var(--muted); }
.workspace .actions { display: flex; flex-wrap: wrap; gap: .75rem; }
.workspace .settings-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1rem; }
/* Each card carries a title and a line saying what it holds, so it stacks
   rather than centring a single label. */
.workspace .setting-link { display: grid; align-content: start; gap: .3rem; min-block-size: 44px; padding: 1rem; background: var(--white); color: var(--harbor); border: 1px solid var(--rule); border-radius: 14px; text-decoration: none; }
.workspace .setting-link strong { font-size: 1.02rem; }
.workspace .setting-link .muted { margin: 0; font-size: .9rem; font-weight: 400; }
.workspace .account-card { display: grid; gap: .35rem; margin-block-end: 1.5rem; padding: 1.25rem; background: var(--white); border: 1px solid var(--rule); border-radius: 14px; }
.workspace .account-card h2 { margin: 0; }
.workspace .account-card p { margin: 0; }
.workspace .account-card .button { justify-self: start; margin-block-start: .5rem; }
.workspace .account-email { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.workspace .pill { padding: .12rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.workspace .pill-ok { background: #e3efe8; color: var(--ok); }
.workspace .pill-warn { background: var(--unread-tint); color: var(--rust); }
.workspace .account-plan { margin-block-start: .5rem; padding-block-start: .75rem; border-block-start: 1px solid var(--rule); color: var(--muted); }
/* Set apart from the card grid on purpose: ending the session must not be
   one mis-tap away from a navigation card. */
.workspace .account-session { margin-block-start: 2rem; padding-block-start: 1.5rem; border-block-start: 1px solid var(--rule); }
.workspace .account-session h2 { margin-block-end: .25rem; }
.workspace .account-session .muted { margin-block-end: 1rem; }
.workspace .field-group { margin: 0 0 1.5rem; padding: 1.25rem; background: var(--white); border: 1px solid var(--rule); border-radius: 14px; }
.workspace .field-group legend { padding-inline: .5rem; font-weight: 700; font-family: "Iowan Old Style", "Palatino Linotype", Palatino, serif; font-size: 1.1rem; }
.workspace .field-group .muted { margin-block-end: 1rem; }
.workspace .field-group .field:last-child { margin-block-end: 0; }
.workspace form { max-inline-size: 42rem; padding: 1.5rem; background: var(--white); border: 1px solid var(--rule); border-radius: 0; }
.workspace button { inline-size: auto; }
.workspace main > button { margin-block-end: 2rem; }
.workspace form > button { margin-block-start: .5rem; margin-inline-end: .5rem; }
.workspace .stream li > strong { display: block; }
.workspace .stream li > button, .workspace .stream li > .button { margin-block-start: .5rem; margin-inline-end: .5rem; }
.workspace .settings-links { margin-block-end: 2rem; }
.workspace .setting-link:hover, .workspace .setting-link.current { border-color: var(--rust); box-shadow: inset 4px 0 0 var(--rust); }
.workspace .tree-item .button { margin-block-start: 1rem; }
.workspace input:user-invalid, .workspace select:user-invalid, .workspace textarea:user-invalid, .workspace [aria-invalid="true"] { border-color: var(--rust); }
.workspace .message.error { color: #7e2615; background: #fff0ea; padding: .75rem 1rem; }
.workspace .visually-hidden { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.workspace dialog { max-inline-size: 30rem; border: 1px solid var(--rule); box-shadow: 0 1rem 3rem rgb(23 48 58 / .25); }
.workspace dialog::backdrop { background: rgb(23 48 58 / .55); }
.workspace .case-search-form { max-inline-size: 28rem; margin-block-end: 1.5rem; padding: 0; background: transparent; border: 0; }
.workspace .case-layout { display: grid; grid-template-columns: minmax(16rem, 24rem) minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.workspace .case-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }
.workspace .case-rows .empty { padding: 1rem 0; }
/* The card owns the border and the rounding; the button and the detail
   link inside it are flush, so the two read as one object. */
.workspace .case-card { display: grid; overflow: hidden; background: var(--white); border: 1px solid var(--rule); border-radius: 14px; }
.workspace .case-card[aria-current="true"], .workspace .case-card:has(.case-row[aria-current="true"]) { border-color: var(--harbor); box-shadow: 0 1px 0 var(--harbor) inset; }
.workspace .case-row { width: 100%; text-align: left; display: grid; gap: .15rem; padding: .85rem 1rem; background: transparent; border: 0; border-radius: 0; cursor: pointer; }
/* Reaching the detail used to mean scrolling past every card to the
   summary column, which on a phone is stacked below the whole list. */
.workspace .case-card-detail { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .7rem 1rem; color: var(--harbor); font-weight: 700; text-decoration: none; background: var(--paper); border-block-start: 1px solid var(--rule); }
.workspace .case-card-detail::after { content: "›"; font-size: 1.25rem; line-height: 1; }
.workspace .case-card-detail:hover { background: var(--selected-tint); }
.workspace .pager { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-block-start: 1.5rem; }
.workspace .pager-count { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.workspace .pager button:disabled { opacity: .45; cursor: default; }
.workspace .case-row strong { color: var(--harbor); }
.workspace .case-row[aria-current="true"] { border-inline-start: 4px solid var(--rust); background: var(--selected-tint); }
.workspace .unread-badge { justify-self: start; display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--unread-tint); color: var(--rust); }
.workspace .case-summary { position: sticky; top: 1rem; padding: 1.5rem; background: var(--white); border: 1px solid var(--rule); }
.workspace .case-summary .unread-count { font-weight: 700; color: var(--rust); }
.workspace .case-summary .button.primary { margin-block-start: 1rem; display: inline-flex; }
.workspace .back-link { margin-block-end: 1rem; color: var(--harbor); font-weight: 700; }
.workspace .case-tree, .workspace .change-history, .workspace .case-runs { margin-block-start: 2rem; }
.workspace .case-tree > ol, .workspace .tree-others > ol, .workspace .tree-group > ol, .workspace .change-history ol, .workspace .case-runs ol { display: grid; gap: 1rem; margin: 0; padding: 0; list-style: none; }
.workspace .tree-others, .workspace .tree-group { margin-block-start: 1rem; }
.workspace .tree-item { padding: 1rem; border-inline-start: .25rem solid var(--rule); background: var(--white); }
.workspace .tree-item.is-new { border-inline-start-color: var(--rust); background: var(--tree-new-tint); }
.workspace .new-badge { display: inline-block; padding: .1rem .5rem; background: var(--unread-tint); color: var(--rust); font-size: .75rem; font-weight: 700; }
.workspace .act-fields { display: grid; grid-template-columns: minmax(8rem, 13rem) minmax(0, 1fr); gap: .35rem 1rem; margin: 1rem 0 0; }
.workspace .act-fields dt { color: var(--muted); }
.workspace .act-fields dd { margin: 0; overflow-wrap: anywhere; }
/* A sumilla is a paragraph: give it the full width and a line length and
   leading that can actually be read, instead of a narrow table cell. */
.workspace .act-fields dd.is-prose { grid-column: 1 / -1; max-inline-size: 68ch; margin-block-start: .15rem; line-height: 1.65; }
.workspace .act-fields dd.is-prose::before { content: ""; display: block; }
.workspace .alert-entry { display: grid; gap: .2rem; padding: .85rem 1rem; background: var(--white); border-inline-start: .25rem solid var(--rule); }
.workspace .alert-entry .alert-summary { max-inline-size: 68ch; margin: .15rem 0 0; line-height: 1.6; }
.workspace .change-entry h3 { margin: 0 0 .15rem; font-size: 1rem; }
.workspace .failed-link { display: inline-block; margin-block-start: 1rem; color: var(--muted); font-weight: 700; }
.workspace .change-entry { padding: 1rem; background: var(--white); border-inline-start: .25rem solid var(--rule); }
@media (max-width: 60rem) {
  /* Between the compact shell and a real desktop -- a phone asking for the
     desktop site lands here -- a 16rem rail took a quarter of the viewport. */
  .workspace { padding-inline-start: 13rem; }
  .workspace .sidebar { inline-size: 13rem; padding-inline: 1rem; }
  .workspace .case-layout { grid-template-columns: 1fr; }
  .workspace .case-summary { position: static; }
}
@media (max-width: 48rem) {
  body { padding-bottom: 0; }
  .workspace { padding-inline-start: 0; }
  .workspace .sidebar { display: none; }
  /* Sticky: a case detail runs to several screens, and the way back to
     the rest of the panel should not be at the top of that scroll. */
  .workspace .mobile-header { position: sticky; inset-block-start: 0; z-index: 4; display: flex; align-items: center; justify-content: space-between; gap: .75rem; min-block-size: 56px; padding-block-start: env(safe-area-inset-top, 0px); padding-inline: max(1rem, env(safe-area-inset-left, 0px)) max(1rem, env(safe-area-inset-right, 0px)); background: var(--harbor); }
  .workspace .mobile-header a { display: flex; align-items: center; min-block-size: 44px; color: var(--white); text-decoration: none; }
  .workspace .mobile-header .brand { font-size: 1.25rem; }
  /* The gutter is measured against the notch, not assumed: a plain 1rem
     is clipped in landscape on a phone with an inset. The bottom clears
     the fixed navigation and the home bar. */
  .workspace main {
    margin-inline-start: 0;
    max-inline-size: none;
    padding-block: 1.25rem calc(76px + env(safe-area-inset-bottom, 0px));
    padding-inline: max(1rem, env(safe-area-inset-left, 0px)) max(1rem, env(safe-area-inset-right, 0px));
  }
  .workspace .page-heading { display: block; margin-block-end: 1.5rem; }
  .workspace .page-heading > :last-child { margin-block-start: 1rem; }
  .workspace h1 { font-size: 1.4rem; }
  .workspace .act-fields { grid-template-columns: 1fr; gap: .1rem; }
  .workspace .act-fields dt { font-weight: 700; color: inherit; }
  .workspace .act-fields dd + dt { margin-block-start: .75rem; }
  /* A flat bordered list is hard to scan with a thumb; each entry becomes
     its own surface with room to breathe. */
  .workspace .stream { border-block-start: 0; display: grid; gap: .75rem; }
  .workspace .stream li { padding: .9rem 1rem; background: var(--white); border: 1px solid var(--rule); border-block-end: 1px solid var(--rule); border-radius: 14px; }
  .workspace .stream li.empty { background: transparent; border: 0; padding-inline: 0; }
  .workspace .tree-item, .workspace .change-entry { border-radius: 0 14px 14px 0; }
  .workspace .case-card-detail { min-block-size: 48px; }
  .workspace .settings-links { grid-template-columns: 1fr; }
  .workspace .account-card, .workspace .field-group { padding: 1rem; }
  .workspace .account-session .button { inline-size: 100%; }
  .workspace .pager { gap: .75rem; }
  .workspace .pager button { flex: 1; }
  .workspace .pager-count { flex: 0 0 auto; text-align: center; font-size: .85rem; }
  .workspace .mobile-nav { position: fixed; inset: auto 0 0; z-index: 3; display: grid; grid-template-columns: repeat(4, 1fr); padding-block-end: env(safe-area-inset-bottom, 0px); padding-inline: max(0px, env(safe-area-inset-left, 0px)) max(0px, env(safe-area-inset-right, 0px)); background: var(--harbor); }
  .workspace .mobile-nav a { display: flex; align-items: center; justify-content: center; min-block-size: 58px; padding: .4rem .25rem; color: var(--white); text-align: center; text-decoration: none; font-size: .78rem; font-weight: 700; border-block-start: 3px solid transparent; }
  .workspace .mobile-nav a.current { background: rgb(255 255 255 / .08); border-block-start-color: var(--rust); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
