/*
 * appcore web shell styles (spec §13, brief item 13).
 *
 * Scoped under #app-shell and built on the shared site tokens that every
 * product page already loads (site.css + the generated theme.css):
 *
 *   --ink --wash --paper --flag --flag-ink --flag-wash --ok --line --muted
 *   --font-head --font-body --radius --radius-small
 *
 * Each is read once, at the top of #app-shell, into a private --s-* token with
 * a fallback, so the shell also works on a page that loads none of them. The
 * older --app-* properties still win when a page sets them:
 *
 *   --app-ink --app-bg --app-wash --app-accent --app-font
 *
 * The signed-in email link renders into `[data-app-shell="auth"]` elements
 * that live OUTSIDE #app-shell (the page header hosts it), so its classes
 * (.app-shell-auth-link, .app-shell-auth-btn) read the same tokens with the
 * same fallbacks.
 */

#app-shell,
.app-shell-auth-link,
.app-shell-auth-btn {
  --s-ink: var(--app-ink, var(--ink, #14213d));
  --s-paper: var(--app-bg, var(--paper, #ffffff));
  --s-wash: var(--app-wash, var(--wash, #f3f5f9));
  --s-flag: var(--app-accent, var(--flag, #c2410c));
  --s-flag-ink: var(--flag-ink, #ffffff);
  --s-flag-wash: var(--flag-wash, #fdeee6);
  --s-ok: var(--ok, #1b7348);
  --s-danger: #b3261e;
  --s-line: var(--line, color-mix(in srgb, var(--s-ink) 16%, transparent));
  --s-muted: var(--muted, color-mix(in srgb, var(--s-ink) 72%, white));
  --s-font-head: var(--font-head, var(--app-font, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif));
  --s-font-body: var(--font-body, var(--app-font, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif));
  --s-radius: var(--radius, 10px);
  --s-radius-small: var(--radius-small, 6px);
}

#app-shell {
  color: var(--s-ink);
  font-family: var(--s-font-body);
  line-height: 1.5;
  max-width: 64rem;
  margin: 0 auto;
  padding: 0;
  box-sizing: border-box;
}

#app-shell *,
#app-shell *::before,
#app-shell *::after {
  box-sizing: inherit;
}

#app-shell a {
  color: var(--s-ink);
  text-underline-offset: 0.18em;
}

/* ---- live status (visually hidden until it has a message) ---- */

#app-shell .app-shell__status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

#app-shell .app-shell__status:not(:empty) {
  position: static;
  width: auto;
  height: auto;
  clip: auto;
  white-space: normal;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  border-radius: var(--s-radius-small);
  background: var(--s-flag-wash);
  border: 1px solid var(--s-flag);
  font-weight: 600;
}

/* ---- header row: tab bar + balance pill ---- */

#app-shell .app-shell__main {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

#app-shell .app-shell__bar {
  display: flex;
  align-items: center;
  gap: 0.75rem 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--s-line);
}

#app-shell .app-shell__tabs {
  display: flex;
  flex: 1 1 auto;
  gap: 0.35rem;
  min-width: 0;
  flex-wrap: wrap;
  padding: 0.25rem 0.25rem 0.35rem 0.25rem;
  margin: -0.25rem;
  scrollbar-width: thin;
}

#app-shell .app-shell__tab {
  flex: none;
  padding: 0.45em 0.95em;
  border-radius: 999px;
  border: 1px solid var(--s-line);
  background: var(--s-paper);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

#app-shell .app-shell__tab:hover {
  background: var(--s-wash);
  border-color: var(--s-ink);
}

#app-shell .app-shell__tab[aria-current="page"] {
  background: var(--s-ink);
  border-color: var(--s-ink);
  color: var(--s-paper);
}

#app-shell .app-shell__pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  padding: 0.4em 0.9em;
  border-radius: 999px;
  border: 2px solid var(--s-ink);
  background: var(--s-paper);
  font-family: var(--s-font-head);
  font-weight: 700;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  white-space: nowrap;
}

#app-shell .app-shell__pill:hover {
  background: var(--s-wash);
}

/* ---- the one visible view ---- */

#app-shell .app-shell__view {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  outline: none;
}

#app-shell .app-shell__panel {
  background: var(--s-paper);
  border: 1px solid var(--s-ink);
  border-radius: var(--s-radius);
  box-shadow: 10px 10px 0 color-mix(in srgb, var(--s-ink) 12%, transparent);
  padding: 1.25rem 1.4rem;
  min-width: 0;
}

#app-shell .app-shell__panel--danger {
  border-color: var(--s-danger);
  box-shadow: 10px 10px 0 color-mix(in srgb, var(--s-danger) 14%, transparent);
}

#app-shell h2,
#app-shell h3 {
  font-family: var(--s-font-head);
  font-weight: var(--font-head-weight, 700);
  line-height: 1.15;
  letter-spacing: -0.01em;
}

#app-shell .app-shell__panel h2 {
  margin: 0 0 0.9rem;
  font-size: 1.4rem;
}

#app-shell .app-shell__panel h3 {
  margin: 0 0 0.4rem;
  font-size: 1.1rem;
}

#app-shell .app-shell__balance {
  margin: 0 0 0.75rem;
  font-family: var(--s-font-head);
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

#app-shell .app-shell__notice {
  margin: 0.4rem 0;
  color: var(--s-muted);
  font-size: 0.95rem;
}

#app-shell .app-shell__warning {
  margin: 0.4rem 0;
  padding: 0.5rem 0.75rem;
  border-radius: var(--s-radius-small);
  background: var(--s-flag-wash);
  box-shadow: inset 3px 0 0 var(--s-flag);
  font-weight: 600;
}

#app-shell .app-shell__who {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.6rem;
  margin: 0 0 1rem;
}

#app-shell .app-shell__who-label {
  color: var(--s-muted);
  font-size: 0.9rem;
}

#app-shell .app-shell__who-email {
  overflow-wrap: anywhere;
}

/* ---- credit packs ---- */

#app-shell .app-shell__packs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem;
  margin: 0.9rem 0;
}

#app-shell .app-shell__packs .app-shell__btn {
  justify-content: center;
  padding: 1rem 0.75rem;
  background: var(--s-wash);
}

#app-shell .app-shell__packs .app-shell__btn:hover:not(:disabled) {
  background: var(--s-paper);
  box-shadow: 4px 4px 0 color-mix(in srgb, var(--s-ink) 14%, transparent);
}

#app-shell .app-shell__checkout-consent:not(:empty) {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--s-line);
}

/* ---- upload units ---- */

#app-shell .app-shell__unit {
  border-top: 1px solid var(--s-line);
  padding-top: 1rem;
  margin-top: 1rem;
}

#app-shell .app-shell__unit:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

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

#app-shell .app-shell__field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.6rem 0;
}

#app-shell .app-shell__field--checkbox {
  align-items: flex-start;
}

#app-shell .app-shell__field label {
  font-weight: 600;
  font-size: 0.9rem;
  flex-basis: 100%;
}

#app-shell .app-shell__field--checkbox label {
  flex-basis: auto;
  font-weight: 400;
  font-size: 1rem;
}

#app-shell .app-shell__input {
  width: 100%;
  padding: 0.6em 0.8em;
  font: inherit;
  color: inherit;
  background: var(--s-paper);
  border: 1px solid color-mix(in srgb, var(--s-ink) 40%, transparent);
  border-radius: var(--s-radius-small);
}

#app-shell .app-shell__input[type="file"] {
  padding: 0.5em;
  background: var(--s-wash);
  border-style: dashed;
}

#app-shell .app-shell__checkbox {
  width: 1.1rem;
  height: 1.1rem;
  flex: 0 0 auto;
  margin-top: 0.2rem;
  accent-color: var(--s-ink);
}

#app-shell .app-shell__consent-label {
  max-width: 40rem;
}

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

#app-shell .app-shell__btn,
.app-shell-auth-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  font: inherit;
  font-weight: 600;
  font-family: var(--s-font-body);
  padding: 0.6em 1.2em;
  border-radius: var(--s-radius-small);
  border: 2px solid var(--s-ink);
  background: transparent;
  color: var(--s-ink);
  cursor: pointer;
  text-decoration: none;
}

#app-shell .app-shell__btn:hover:not(:disabled),
.app-shell-auth-btn:hover {
  background: var(--s-wash);
}

#app-shell .app-shell__btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#app-shell .app-shell__btn--primary,
.app-shell-auth-btn {
  background: var(--s-ink);
  border-color: var(--s-ink);
  color: var(--s-paper);
}

#app-shell .app-shell__btn--primary:hover:not(:disabled),
.app-shell-auth-btn:hover {
  background: color-mix(in srgb, var(--s-ink) 86%, white);
}

#app-shell a.app-shell-auth-btn {
  color: var(--s-paper);
}

#app-shell .app-shell__btn--secondary {
  border-color: var(--s-line);
  border-width: 1px;
  padding: 0.4em 0.9em;
  font-size: 0.9rem;
}

#app-shell .app-shell__btn--danger {
  border-color: var(--s-danger);
  color: var(--s-danger);
  padding: 0.4em 0.9em;
  font-size: 0.9rem;
}

#app-shell .app-shell__btn--danger:hover:not(:disabled) {
  background: var(--s-danger);
  color: #ffffff;
}

#app-shell .app-shell__panel--danger .app-shell__btn--danger {
  padding: 0.6em 1.2em;
  font-size: inherit;
}

#app-shell .app-shell__auth-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

#app-shell .app-shell__auth-link {
  font-weight: 600;
}

.app-shell-auth-link {
  color: var(--s-ink);
  font-family: var(--s-font-body);
  font-size: 0.9rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* ---- focus (same ring as the marketing pages) ---- */

#app-shell .app-shell__btn:focus-visible,
#app-shell .app-shell__input:focus-visible,
#app-shell .app-shell__checkbox:focus-visible,
#app-shell .app-shell__tab:focus-visible,
#app-shell .app-shell__pill:focus-visible,
#app-shell a:focus-visible,
.app-shell-auth-link:focus-visible,
.app-shell-auth-btn:focus-visible {
  outline: 3px solid var(--s-flag);
  outline-offset: 3px;
}

/* ---- API key reveal, tables ---- */

#app-shell .app-shell__key-reveal:empty {
  display: none;
}

#app-shell .app-shell__key-value {
  display: block;
  padding: 0.6rem 0.75rem;
  margin: 0.5rem 0;
  background: var(--s-wash);
  border: 1px solid var(--s-line);
  border-radius: var(--s-radius-small);
  word-break: break-all;
}

/* ---- "Using your API key" documentation on #keys ---- */

#app-shell .app-shell__api-docs {
  margin-top: 1.25rem;
}

#app-shell .app-shell__api-docs h3 {
  margin: 1.25rem 0 0.4rem;
}

#app-shell .app-shell__api-docs-label {
  margin: 0.75rem 0 0.25rem;
  font-weight: 600;
}

#app-shell .app-shell__api-docs pre {
  overflow-x: auto;
  margin: 0.25rem 0 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--s-wash);
  border: 1px solid var(--s-line);
  border-radius: var(--s-radius-small);
  font-size: 0.85rem;
  line-height: 1.45;
}

#app-shell .app-shell__api-docs pre code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}

#app-shell .app-shell__table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  font-size: 0.95rem;
}

#app-shell .app-shell__table th,
#app-shell .app-shell__table td {
  text-align: left;
  padding: 0.6rem 0.6rem 0.6rem 0;
  border-bottom: 1px solid var(--s-line);
  vertical-align: top;
}

#app-shell .app-shell__table th {
  color: var(--s-muted);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  border-bottom-color: var(--s-ink);
}

#app-shell .app-shell__table td .app-shell__notice {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
}

/* Status chips: same shape as site.css .chip / .chip--ok / .chip--flag. */
#app-shell .app-shell__chip {
  display: inline-flex;
  align-items: center;
  font-weight: 700;
  font-size: 0.8rem;
  white-space: nowrap;
  padding: 0.25em 0.65em;
  border-radius: 999px;
  border: 1px solid var(--s-line);
  background: var(--s-wash);
  color: var(--s-ink);
}

#app-shell .app-shell__chip--ok {
  border-color: transparent;
  background: color-mix(in srgb, var(--s-ok) 12%, var(--s-paper));
  color: var(--s-ok);
}

#app-shell .app-shell__chip--flag {
  border-color: transparent;
  background: var(--s-flag);
  color: var(--s-flag-ink);
}

/* Amber: a failed job or a done job whose credits were returned. */
#app-shell .app-shell__chip--warning {
  border: 1px solid #f0c36d;
  background: #fff4d6;
  color: #7a4b00;
}

/* ---- brand dialogs (web/lib/dialog.mjs): a native <dialog> inside #app-shell, so it carries the tokens ---- */

#app-shell .app-shell__dialog {
  box-sizing: border-box;
  width: calc(100% - 2rem);
  max-width: 420px;
  padding: 0; /* the panel carries the padding, so any click on the <dialog> itself is the backdrop */
  border: 1px solid var(--s-line);
  border-radius: var(--s-radius);
  background: var(--s-paper);
  color: var(--s-ink);
  font-family: var(--s-font-body);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

#app-shell .app-shell__dialog-panel {
  padding: 1.5rem;
}

#app-shell .app-shell__dialog::backdrop {
  background: rgba(10, 14, 25, 0.55);
}

#app-shell .app-shell__dialog-title {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  line-height: 1.25;
}

#app-shell .app-shell__dialog-body {
  margin: 0 0 1.25rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

#app-shell .app-shell__dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

#app-shell .app-shell__download-link {
  margin-right: 0.5rem;
  font-weight: 600;
}

/* ---- open problems of a finished job ---- */

#app-shell .app-shell__problems-row[hidden] {
  display: none;
}

#app-shell .app-shell__problems {
  padding: 0.5rem 0 0.75rem;
}

#app-shell .app-shell__problem {
  border: 1px solid var(--s-line);
  border-left-width: 4px;
  border-radius: var(--s-radius-small);
  background: var(--s-paper);
  padding: 0.6rem 0.8rem;
  margin: 0.5rem 0;
}

#app-shell .app-shell__problem p {
  margin: 0.25rem 0;
}

#app-shell .app-shell__problem--critical {
  border-left-color: var(--s-danger);
}

#app-shell .app-shell__problem--major {
  border-left-color: var(--s-flag);
}

#app-shell .app-shell__problem--minor {
  border-left-color: var(--s-muted);
}

/* coverage and not-reviewed notices are about the review itself: washed, not bordered like a finding */
#app-shell .app-shell__problem--notice {
  background: var(--s-flag-wash);
}

#app-shell .app-shell__problem-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

#app-shell .app-shell__problem-quote {
  margin: 0.4rem 0;
  padding: 0.4rem 0.75rem;
  border-left: 3px solid var(--s-line);
  background: var(--s-wash);
  overflow-wrap: anywhere;
}

#app-shell .app-shell__problem-quote p {
  margin: 0;
}

#app-shell .app-shell__problem-source {
  color: var(--s-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

/* ---- narrow screens ---- */

@media (max-width: 40rem) {
  #app-shell .app-shell__bar {
    flex-wrap: wrap;
  }

  #app-shell .app-shell__pill {
    order: -1;
    margin-left: auto;
  }

  #app-shell .app-shell__tabs {
    flex-basis: 100%;
  }

  #app-shell .app-shell__panel {
    padding: 1rem;
    box-shadow: 5px 5px 0 color-mix(in srgb, var(--s-ink) 12%, transparent);
  }
}

@media (max-width: 40rem) {
  #app-shell .app-shell__table,
  #app-shell .app-shell__table thead,
  #app-shell .app-shell__table tbody,
  #app-shell .app-shell__table tr,
  #app-shell .app-shell__table th,
  #app-shell .app-shell__table td {
    display: block;
    width: 100%;
  }

  #app-shell .app-shell__table thead {
    display: none;
  }

  #app-shell .app-shell__table td {
    border-bottom: none;
    padding: 0.15rem 0;
  }

  /* the header row is hidden in the card layout, so each value names itself */
  #app-shell .app-shell__table td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--s-muted);
    font-weight: 600;
  }

  #app-shell .app-shell__table tr {
    border-bottom: 1px solid var(--s-line);
    padding-bottom: 0.6rem;
    margin-bottom: 0.6rem;
  }
}

@media (prefers-reduced-motion: no-preference) {
  #app-shell .app-shell__view > .app-shell__panel {
    animation: app-shell-in 0.3s both;
  }

  @keyframes app-shell-in {
    from {
      opacity: 0;
      transform: translateY(6px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}

/* ---- multi-file picker (change 6): drop zone, chosen-file list, counter ---- */

#app-shell .app-shell__dropzone {
  border: 2px dashed var(--s-line);
  border-radius: var(--s-radius);
  padding: 1rem;
  background: var(--s-wash);
}

#app-shell .app-shell__dropzone.is-dragover {
  border-style: solid;
  border-color: var(--s-flag);
}

#app-shell .app-shell__dropzone > p {
  margin: 0 0 0.5rem;
}

#app-shell .app-shell__file-input {
  display: block;
  max-width: 100%;
  margin: 0 0 0.5rem;
  font: inherit;
  color: var(--s-muted);
}

#app-shell .app-shell__file-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

#app-shell .app-shell__file-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0;
  border-top: 1px solid var(--s-line);
}

#app-shell .app-shell__file-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

#app-shell .app-shell__file-size {
  flex: 0 0 auto;
  color: var(--s-muted);
  font-size: 0.9rem;
}

#app-shell .app-shell__file-count {
  margin: 0.5rem 0 0;
  color: var(--s-muted);
  font-size: 0.9rem;
}

/* ---- dark: only when the page asks for it (the product pages are light) ---- */

@media (prefers-color-scheme: dark) {
  #app-shell:not([data-theme="light"]) {
    --s-ink: var(--app-ink, #f2f2f2);
    --s-paper: var(--app-bg, #16181d);
    --s-wash: var(--app-wash, #20232a);
    --s-line: color-mix(in srgb, var(--s-ink) 20%, transparent);
    --s-muted: color-mix(in srgb, var(--s-ink) 72%, transparent);
    --s-danger: #f2b8b5;
    --s-ok: #7fd1a6;
    /* the host page may stay light: carry our own surface */
    background: var(--s-wash);
    --s-flag-wash: color-mix(in srgb, var(--s-flag) 18%, var(--s-paper));
  }

  #app-shell:not([data-theme="light"]) .app-shell__dropzone {
    background: var(--s-paper);
  }

  #app-shell:not([data-theme="light"]) .app-shell__chip--warning {
    border-color: #8a6a1f;
    background: #3a2d0e;
    color: #f5d48a;
  }
}

#app-shell[data-theme="dark"] .app-shell__dropzone {
  background: var(--s-paper);
}

#app-shell[data-theme="dark"] .app-shell__chip--warning {
  border-color: #8a6a1f;
  background: #3a2d0e;
  color: #f5d48a;
}

#app-shell[data-theme="dark"] {
  --s-ink: var(--app-ink, #f2f2f2);
  --s-paper: var(--app-bg, #16181d);
  --s-wash: var(--app-wash, #20232a);
  --s-line: color-mix(in srgb, var(--s-ink) 20%, transparent);
  --s-muted: color-mix(in srgb, var(--s-ink) 72%, transparent);
  --s-danger: #f2b8b5;
  --s-ok: #7fd1a6;
  /* the host page may stay light: carry our own surface */
  background: var(--s-wash);
  --s-flag-wash: color-mix(in srgb, var(--s-flag) 18%, var(--s-paper));
}
