/* Durchreiche — one stylesheet, no build step.
   Design direction "Emaille": enamel white, enamel blue for actions and
   direct contacts, brass for confidentiality and focus. */

@layer reset, tokens, base, layout, components, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p, dl, dd, ul, figure, fieldset { margin: 0; }
  ul { padding: 0; list-style: none; }
  fieldset { border: 0; padding: 0; min-width: 0; }
  legend { padding: 0; }
  button, input, textarea, select { font: inherit; color: inherit; }
  img, svg { display: block; }
}

@layer tokens {
  :root {
    color-scheme: light dark;
    --bg: #E7ECEB;
    --surface: #FCFDFB;
    --sunken: #F1F4F2;
    --line: #CDD4D4;
    --border: #727E86;
    --ink: #17202E;
    --ink-2: #4A5565;
    --enamel: #1B458F;
    --enamel-hover: #143570;
    --enamel-ink: #1B458F;
    --enamel-tint: #E2EAF8;
    --on-enamel: #FFFFFF;
    --brass: #7D5406;
    --brass-tint: #F7ECCB;
    --brass-line: #B58A2C;
    --focus: #9A6700;
    --danger: #A3271D;
    --danger-tint: #FBE7E3;
    --danger-fill: #A3271D;

    --font-ui: "Barlow", "Avenir Next", "Segoe UI", system-ui, sans-serif;
    --font-title: "Barlow Semi Condensed", "Avenir Next Condensed", "Arial Narrow", system-ui, sans-serif;
    --font-quote: "iA Writer Quattro S", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    --t-small: 0.8125rem;
    --t-ui: 0.9375rem;
    --t-body: 1.0625rem;
    --t-quote: 0.9375rem;
    --t-h3: 1.25rem;
    --t-h2: 1.5rem;
    --t-h1: clamp(1.75rem, 1.4rem + 1.6vw, 2.25rem);

    --s-1: .25rem; --s-2: .5rem; --s-3: .75rem; --s-4: 1rem;
    --s-5: 1.5rem; --s-6: 2rem; --s-7: 3rem; --s-8: 4rem;

    --w-page: 68rem;
    --w-read: 44rem;
    --w-hatch: 26rem;

    --r-thing: 4px;
    --r-button: 6px;
    --r-person: 999px;

    --shadow-slip: 0 1px 0 rgb(23 32 46 / .05), 0 1px 3px rgb(23 32 46 / .07);
    --shadow-lift: 0 6px 16px -6px rgb(23 32 46 / .22);

    --dur-1: 120ms; --dur-2: 200ms; --dur-3: 320ms;
    --ease: cubic-bezier(.2, .7, .2, 1);
    --gutter: 1rem;
  }
  @media (min-width: 40rem) { :root { --gutter: 1.5rem; } }
  @media (prefers-color-scheme: dark) {
    :root {
      --bg: #0E141C;
      --surface: #161E29;
      --sunken: #111821;
      --line: #2B3544;
      --border: #6F7C8D;
      --ink: #E8ECF2;
      --ink-2: #A5B0C0;
      --enamel: #3566CC;
      --enamel-hover: #2A56B3;
      --enamel-ink: #9FBCF4;
      --enamel-tint: #1B2A47;
      --on-enamel: #FFFFFF;
      --brass: #E3BA61;
      --brass-tint: #2D2512;
      --brass-line: #8E6E26;
      --focus: #E3BA61;
      --danger: #F3978B;
      --danger-tint: #3A1B18;
      --danger-fill: #B5382D;
      --shadow-slip: none;
      --shadow-lift: none;
    }
  }
}

@layer base {
  html { -webkit-text-size-adjust: 100%; }
  body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: var(--t-body);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
  }
  h1, h2, h3 { font-family: var(--font-title); font-weight: 600; letter-spacing: 0; }
  h1 { font-size: var(--t-h1); line-height: 1.15; }
  h2 { font-size: var(--t-h3); line-height: 1.3; }
  h1:focus { outline: none; }
  a { color: var(--enamel-ink); }
  strong { font-weight: 600; }
  :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  ::placeholder { color: var(--ink-2); opacity: 1; }
  .icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
}

@layer layout {
  .page { padding: var(--s-6) var(--gutter) var(--s-8); }
  .read { max-width: var(--w-read); margin: 0 auto; display: grid; gap: var(--s-5); }
  .wide { max-width: var(--w-page); margin: 0 auto; display: grid; gap: var(--s-5); }

  .site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
  .site-header-inner {
    max-width: var(--w-page); margin: 0 auto; padding: 0 var(--gutter);
    display: flex; align-items: center; gap: var(--s-5); min-height: 56px;
  }
  .brand { display: flex; align-items: center; gap: var(--s-2); color: var(--ink); text-decoration: none; font-family: var(--font-title); font-weight: 600; font-size: 1.25rem; }
  .logo-frame { fill: none; stroke: var(--ink); stroke-width: 2; }
  .logo-sill { fill: var(--enamel); }
  .site-nav { display: flex; gap: var(--s-4); align-self: stretch; }
  .site-nav a {
    display: flex; align-items: center; color: var(--ink-2); text-decoration: none;
    font-size: var(--t-ui); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px;
  }
  .site-nav a:hover { color: var(--ink); }
  .site-nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--enamel); }
  .header-cta { margin-left: auto; }
  .header-cta .short { display: none; }

  @media (max-width: 39.99rem) {
    .site-header-inner { flex-wrap: wrap; gap: 0 var(--s-4); }
    .brand { min-height: 56px; }
    .site-nav { order: 3; min-height: 44px; }
    .header-cta .long { display: none; }
    .header-cta .short { display: inline; }
    .account-menu { order: 4; margin-left: auto; }
    .page { padding-top: var(--s-5); }
  }

  .auth-page { padding: var(--s-6) var(--gutter); max-width: calc(var(--w-hatch) + 2 * var(--gutter)); margin: 0 auto; }
  @media (min-width: 40rem) { .auth-page { padding-top: 16vh; } }
  .auth-brand { display: flex; align-items: center; justify-content: center; gap: var(--s-2); font-family: var(--font-title); font-weight: 600; font-size: 1.4rem; margin-bottom: var(--s-5); }
  .auth-foot { text-align: center; color: var(--ink-2); font-size: var(--t-ui); margin-top: var(--s-6); }

  .title-row { display: flex; align-items: end; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }

  .detail-grid { display: grid; gap: var(--s-5); }
  @media (min-width: 60rem) {
    .detail-grid { grid-template-columns: minmax(0, 1fr) 20rem; align-items: start; }
    .facts-card { grid-column: 2; grid-row: 1; position: sticky; top: var(--s-5); }
    .original { grid-column: 1; grid-row: 1; }
  }
}

@layer components {
  /* Buttons */
  .button {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
    min-height: 44px; padding: 0 1.125rem; border-radius: var(--r-button);
    font-size: var(--t-ui); font-weight: 600; line-height: 1.2; text-decoration: none;
    border: 1px solid transparent; cursor: pointer; white-space: nowrap;
    transition: background-color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
  }
  .button:active { transform: translateY(1px); }
  .button[disabled] { opacity: .55; cursor: not-allowed; }
  .button-small { min-height: 36px; padding: 0 .75rem; }
  @media (pointer: coarse) { .button-small { min-height: 44px; } }
  .button-block { width: 100%; }
  .button-primary { background: var(--enamel); color: var(--on-enamel); }
  .button-primary:hover { background: var(--enamel-hover); }
  .button-secondary { background: var(--surface); border-color: var(--border); color: var(--ink); }
  .button-secondary:hover { background: var(--sunken); }
  .button-quiet { background: none; color: var(--enamel-ink); padding-inline: var(--s-2); }
  .button-quiet:hover { text-decoration: underline; }
  .button-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
  .button-danger:hover { background: var(--danger-tint); }
  .button-danger-confirm { background: var(--danger-fill); border-color: var(--danger); color: #fff; }
  .button .busy { display: none; }
  .htmx-request .button .busy, .button.htmx-request .busy, form.htmx-request .button .busy { display: inline; }
  .htmx-request .button .idle, .button.htmx-request .idle, form.htmx-request .button .idle { display: none; }
  .link { color: var(--enamel-ink); }
  .actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }

  /* Hatch panel: the one signature shape (login, join, paste box) */
  .hatch { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 4px 4px 0 0; margin-bottom: 6px; }
  .hatch::after {
    content: ""; position: absolute; left: -8px; right: -8px; bottom: -7px; height: 6px;
    background: var(--enamel); border-radius: 2px;
  }
  @media (min-width: 40rem) { .hatch::after { left: -12px; right: -12px; } }
  .hatch-body { padding: var(--s-5); display: grid; gap: var(--s-4); }
  @media (min-width: 40rem) { .hatch-body { padding: var(--s-6); } }
  .hatch h1 { font-size: var(--t-h2); line-height: 1.25; }
  .hatch-body.htmx-swapping, .hatch-body.htmx-settling { opacity: .4; transition: opacity 150ms var(--ease); }
  .hatch-paste .hatch-body { padding: var(--s-4); }
  .hatch-note { margin-top: calc(-1 * var(--s-3)); }
  .with-icon { display: flex; align-items: center; gap: var(--s-2); }
  .icon-ok { color: var(--enamel-ink); width: 22px; height: 22px; }
  .lede { color: var(--ink-2); }
  .inviter { display: flex; align-items: center; gap: var(--s-3); }

  /* Fields */
  form { display: grid; gap: var(--s-4); }
  .field { display: grid; gap: var(--s-1); }
  .field > label, .field > legend { font-size: var(--t-ui); font-weight: 600; margin-bottom: var(--s-1); }
  .hint { font-size: var(--t-small); color: var(--ink-2); line-height: 1.4; }
  .field input[type=text], .field input[type=email], .field input[type=number], .field textarea, .link-field {
    width: 100%; min-height: 44px; padding: .625rem .75rem; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--r-thing); font-size: var(--t-body); line-height: 1.4;
  }
  .field input:focus, .field textarea:focus, .link-field:focus { border-color: var(--enamel-ink); }
  .field textarea { resize: vertical; }
  .hatch-paste textarea {
    font-family: var(--font-quote); font-size: var(--t-quote); line-height: 1.6;
    min-height: 12rem; max-height: 60vh; field-sizing: content; background: var(--sunken);
  }
  @media (min-width: 40rem) { .hatch-paste textarea { min-height: 16rem; } }
  .has-error input, .has-error textarea { border-color: var(--danger); }
  .field-error { display: flex; gap: var(--s-1); align-items: center; color: var(--danger); font-size: var(--t-small); font-weight: 500; }
  .field-row { display: grid; gap: var(--s-4); }
  @media (min-width: 40rem) { .field-row { grid-template-columns: 1fr 1fr; } }
  .inquiry-form h2 { margin-top: var(--s-4); }

  /* Choice tiles (radio groups) */
  .tiles { display: grid; gap: var(--s-2); }
  @media (min-width: 40rem) { .tiles { grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); } }
  .tiles-compact { display: flex; flex-wrap: wrap; }
  .tile {
    position: relative; display: grid; gap: 2px; padding: var(--s-3) var(--s-4); cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-thing);
    transition: background-color var(--dur-1) var(--ease);
  }
  .tiles-compact .tile { padding: var(--s-2) var(--s-4); min-height: 44px; align-content: center; }
  .tile input { position: absolute; opacity: 0; pointer-events: none; }
  .tile:hover { background: var(--sunken); }
  .tile-title { font-size: var(--t-ui); font-weight: 600; }
  .tile-hint { font-size: var(--t-small); color: var(--ink-2); padding-right: var(--s-5); }
  .tile-check { position: absolute; top: var(--s-3); right: var(--s-3); color: var(--enamel-ink); display: none; }
  .tile:has(input:checked) { background: var(--enamel-tint); box-shadow: inset 0 0 0 2px var(--enamel-ink); border-color: var(--enamel-ink); }
  .tile:has(input:checked) .tile-check { display: block; }
  .tile:has(input:focus-visible), .chip:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }

  /* Member chips (people are round) */
  .chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
  .chip {
    position: relative; display: inline-flex; align-items: center; gap: var(--s-2);
    min-height: 36px; padding: 0 .75rem 0 .25rem; border-radius: var(--r-person); cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); color: var(--ink-2); font-size: var(--t-ui);
  }
  @media (pointer: coarse) { .chip { min-height: 44px; } }
  .chip input { position: absolute; opacity: 0; pointer-events: none; }
  .chip-check { display: none; width: 16px; height: 16px; }
  .chip:has(input:checked) { background: var(--enamel-tint); border: 1.5px solid var(--enamel-ink); color: var(--ink); }
  .chip:has(input:checked) .avatar { background: var(--enamel); color: var(--on-enamel); }
  .chip:has(input:checked) .chip-check { display: block; color: var(--enamel-ink); }
  .chips-field[data-collapsed] { display: none; }
  .audience { display: grid; gap: var(--s-3); margin-top: var(--s-4); }
  .audience-summary { display: flex; gap: var(--s-2); align-items: center; font-size: var(--t-ui); color: var(--ink-2); }
  .is-secret { color: var(--brass); }

  /* Avatars */
  .avatar {
    display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%;
    background: var(--sunken); color: var(--ink-2); font-size: var(--t-small); font-weight: 600; line-height: 1;
    border: 1px solid var(--line);
  }
  .avatar-lg { width: 40px; height: 40px; font-size: var(--t-ui); }

  /* Badges and tags (things are square) */
  .badge {
    display: inline-flex; align-items: center; height: 24px; padding: 0 .5rem; border-radius: var(--r-thing);
    font-size: var(--t-small); font-weight: 600; width: fit-content;
  }
  .badge-direct { background: var(--enamel); color: var(--on-enamel); }
  .badge-platform { border: 1px solid var(--border); color: var(--ink-2); }
  .tags { display: flex; flex-wrap: wrap; gap: var(--s-1); }
  .tag {
    display: inline-flex; align-items: center; height: 24px; padding: 0 .5rem; border-radius: var(--r-thing);
    background: var(--sunken); border: 1px solid var(--line); font-size: var(--t-small); font-weight: 500;
  }
  .secret-hint { display: inline-flex; align-items: center; gap: var(--s-1); color: var(--brass); font-size: var(--t-small); font-weight: 500; }
  .secret-hint .icon { width: 16px; height: 16px; }

  /* Segmented filter */
  .segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-button); overflow: hidden; background: var(--surface); }
  .segmented a { padding: .5rem .875rem; min-height: 40px; display: flex; align-items: center; color: var(--ink-2); text-decoration: none; font-size: var(--t-ui); font-weight: 500; }
  .segmented a + a { border-left: 1px solid var(--border); }
  .segmented a[aria-current] { background: var(--enamel-tint); color: var(--ink); font-weight: 600; }

  /* Inquiry cards */
  .cards { display: grid; gap: var(--s-3); }
  .card {
    position: relative; display: grid; gap: var(--s-3); padding: var(--s-4);
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-thing); box-shadow: var(--shadow-slip);
    transition: box-shadow var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
  }
  @media (min-width: 40rem) { .card { padding: var(--s-4) var(--s-5); } }
  .card:hover { box-shadow: var(--shadow-lift); transform: translateY(-1px); }
  .card:has(.card-title a:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
  .card-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); }
  .card-head time { font-size: var(--t-small); color: var(--ink-2); }
  .card-title { font-size: var(--t-h3); }
  .card-title a { color: var(--ink); text-decoration: none; }
  .card-title a::after { content: ""; position: absolute; inset: 0; }
  .card-title a:focus-visible { outline: none; }
  .facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-3); }
  .facts dt { font-size: var(--t-small); color: var(--ink-2); }
  .facts dd { font-size: var(--t-ui); font-weight: 500; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
  .card-foot {
    display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); flex-wrap: wrap;
    padding-top: var(--s-3); border-top: 1px dashed var(--line); font-size: var(--t-small); color: var(--ink-2);
  }
  .by { display: inline-flex; align-items: center; gap: var(--s-2); }

  /* Detail */
  .back { display: inline-flex; align-items: center; gap: var(--s-1); font-size: var(--t-ui); width: fit-content; text-decoration: none; }
  .back:hover { text-decoration: underline; }
  .detail-head { display: grid; gap: var(--s-3); }
  .detail-head .title-row { align-items: start; }
  .facts-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-thing); box-shadow: var(--shadow-slip); }
  .facts-card section { display: grid; gap: var(--s-2); padding: var(--s-4); justify-items: start; }
  .facts-card section + section { border-top: 1px solid var(--line); }
  .facts-card h2 { font-size: var(--t-ui); font-family: var(--font-ui); color: var(--ink-2); font-weight: 600; }
  .facts-card .facts { grid-template-columns: 1fr; gap: var(--s-1); width: 100%; }
  .facts-card .facts div { display: flex; justify-content: space-between; gap: var(--s-3); }
  .contact { overflow-wrap: anywhere; }
  .notice-inline {
    display: flex; gap: var(--s-2); align-items: start; padding: var(--s-3);
    background: var(--brass-tint); border: 1px solid var(--brass-line); border-radius: var(--r-thing); font-size: var(--t-ui);
  }
  .notice-inline .icon { color: var(--brass); margin-top: 2px; }
  .original { display: grid; gap: var(--s-3); }
  .original-text {
    background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r-thing); padding: var(--s-5);
    font-family: var(--font-quote); font-size: var(--t-quote); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 72ch;
  }

  /* Panels, notices, rows (invites) */
  .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-thing); padding: var(--s-5); display: grid; gap: var(--s-4); }
  .notice { border-radius: var(--r-thing); padding: var(--s-4) var(--s-5); display: grid; gap: var(--s-3); }
  .notice-secret { background: var(--brass-tint); border: 1px solid var(--brass-line); }
  .notice-secret h2 .icon { color: var(--brass); }
  .link-field { font-family: var(--font-quote); font-size: var(--t-quote); }
  #invites-panel { display: grid; gap: var(--s-5); }
  #invites-panel section { display: grid; gap: var(--s-3); }
  .rows { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-thing); }
  .row { display: flex; justify-content: space-between; align-items: start; gap: var(--s-3); padding: var(--s-3) var(--s-4); flex-wrap: wrap; }
  .row + .row { border-top: 1px solid var(--line); }
  .row-title { font-size: var(--t-ui); font-weight: 600; }
  .row-meta { font-size: var(--t-small); color: var(--ink-2); }
  .row.is-new { animation: fade-new 1.2s var(--ease); }
  @keyframes fade-new { from { background: var(--enamel-tint); } to { background: transparent; } }

  /* Two-step confirm without a browser dialog */
  .confirm > summary { list-style: none; }
  .confirm > summary::-webkit-details-marker { display: none; }
  .confirm[open] > summary { display: none; }
  .confirm form { display: grid; gap: var(--s-2); max-width: 20rem; font-size: var(--t-small); }
  .confirm-delete { justify-self: start; }

  /* Sticky submit bar */
  .sticky-bar {
    position: sticky; bottom: 0; z-index: 2; margin: var(--s-4) calc(-1 * var(--gutter)) 0;
    padding: var(--s-3) var(--gutter) calc(var(--s-3) + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line);
    display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  }
  .sticky-summary { font-size: var(--t-ui); font-weight: 500; color: var(--ink-2); }
  .sticky-summary.is-secret { color: var(--brass); }

  /* Flashes */
  .flashes { max-width: var(--w-read); margin: 0 auto var(--s-5); display: grid; gap: var(--s-2); }
  .auth-page .flashes { margin-bottom: var(--s-4); }
  .flash { display: flex; align-items: start; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--r-thing); font-size: var(--t-ui); }
  .flash p { flex: 1; }
  .flash > .icon { margin-top: 2px; }
  .flash-info { background: var(--enamel-tint); }
  .flash-info > .icon { color: var(--enamel-ink); }
  .flash-error { background: var(--danger-tint); }
  .flash-error > .icon { color: var(--danger); }
  .flash-close { background: none; border: 0; padding: 0; width: 32px; height: 32px; margin: -6px -8px -6px 0; display: grid; place-items: center; cursor: pointer; color: var(--ink-2); }

  /* Empty state */
  .empty { display: grid; justify-items: center; text-align: center; gap: var(--s-3); padding: var(--s-8) 0 var(--s-6); color: var(--ink-2); }
  .empty .logo-frame { stroke: var(--ink-2); }

  /* Account menu */
  .account-menu { position: relative; }
  .account-menu summary { display: flex; align-items: center; gap: var(--s-2); cursor: pointer; list-style: none; min-height: 44px; font-size: var(--t-ui); color: var(--ink-2); }
  .account-menu summary::-webkit-details-marker { display: none; }
  .account-menu-panel {
    position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; min-width: 14rem; display: grid; gap: var(--s-2);
    padding: var(--s-3) var(--s-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-thing); box-shadow: var(--shadow-lift);
  }
  .account-menu-panel form { display: block; }
  .account-menu-panel .button-quiet { padding: 0; min-height: 32px; }
  .account-full-name { font-size: var(--t-ui); }
}

@layer utilities {
  .muted { color: var(--ink-2); }
  .visually-hidden {
    position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .skip-link { position: absolute; left: var(--s-2); top: -100px; background: var(--surface); padding: var(--s-2) var(--s-3); z-index: 10; border-radius: var(--r-thing); }
  .skip-link:focus { top: var(--s-2); }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition-property: color, background-color, border-color !important; }
    .card:hover { transform: none; }
    .button:active { transform: none; }
  }
}

@layer components {
  form > .button:not(.button-block) { justify-self: start; }
}
