/* applications area (redesign). Loaded after app.css; uses tokens.css only.
   Applications list, apply flow (documents → send), application page, update-status sheet, inbox. */

/* ── Shared bits ─────────────────────────────────────────── */
.app-field { display: grid; gap: 6px; }
.app-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
.app-break { overflow-wrap: anywhere; }
.app-prewrap { white-space: pre-line; overflow-wrap: anywhere; }
.app-mailtext { white-space: pre-line; overflow-wrap: anywhere; color: var(--ink-2); font: var(--text-small); padding: 4px 0 8px; }
.app-subhead { font: var(--text-label); color: var(--ink-3); margin: var(--space-2) 0 0; }

details.app-fold > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; color: var(--ink-2); font: var(--text-label); min-height: 44px; }
details.app-fold > summary::-webkit-details-marker { display: none; }
details.app-fold > summary .icon { transition: transform var(--dur); }
details.app-fold[open] > summary .icon:first-child { transform: rotate(90deg); }
details.app-fold > summary:hover { color: var(--ink); }

/* "⋯" menu */
.app-more { position: relative; }
.app-more > summary { list-style: none; cursor: pointer; }
.app-more > summary::-webkit-details-marker { display: none; }
.app-more[open] > summary { background: var(--surface-2); }
.app-more__panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 240px; padding: var(--space-2); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow-2); display: grid; }
.app-more__panel a, .app-more__panel button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 12px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--ink); text-decoration: none; font: var(--text-body); cursor: pointer; text-align: left; }
.app-more__panel a:hover, .app-more__panel button:hover { background: var(--surface-2); }
.app-more__panel .app-more__danger { color: var(--bad); }

/* Page head of the application pages: compact on phones (title, then actions in one row). */
.app-head .page-head__text { min-width: 0; }
.app-head h1 { overflow-wrap: anywhere; }
.app-head__meta { gap: 6px 10px; }
@media (max-width: 640px) {
  .app-head { gap: var(--space-3); margin-bottom: var(--space-4); }
  .app-head h1 { font-size: 1.5rem; line-height: 1.2; }
  .app-head .page-head__text { gap: 4px; }
  .app-head .page-head__actions { margin-left: 0; width: 100%; }
  .app-head .page-head__actions > .btn { flex: 1; }
  .back { margin-bottom: var(--space-3); }
}

/* ── Applications list ───────────────────────────────────── */
.app-stats { display: flex; flex-wrap: wrap; gap: 6px 28px; margin: 0 0 var(--space-4); padding: var(--space-4) var(--space-5); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.app-stats > div { display: flex; flex-direction: row-reverse; align-items: baseline; gap: 6px; }
.app-stats dt { color: var(--ink-3); font: var(--text-small); }
.app-stats dd { margin: 0; font: 600 1.375rem/1 var(--font-serif); color: var(--ink); }
@media (max-width: 560px) { .app-stats { display: grid; grid-template-columns: 1fr 1fr; padding: var(--space-3) var(--space-4); gap: 10px 16px; }
  .app-stats > div { flex-direction: column-reverse; align-items: flex-start; gap: 2px; } }

.app-filter { margin-bottom: var(--space-2); }
.app-filter > summary .count { margin-left: 2px; }
.app-filter__form { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); align-items: end; padding: var(--space-4);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.app-filter__field { display: grid; gap: 6px; }
.app-filter__actions { display: flex; gap: var(--space-2); }
.app-closed { margin-top: var(--space-5); }
.app-closed > .list { margin-top: var(--space-2); }
.list__item .pill { flex: none; }
@media (max-width: 560px) {
  .app-hide-phone { display: none; }
  .app-list .list__item { gap: var(--space-3); padding: var(--space-3) var(--space-4); align-items: flex-start; }
  .app-list .logo { width: 36px; height: 36px; }
  .app-list .list__title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
  .app-list .list__sub { white-space: normal; }
  .app-list .list__end { margin-top: 2px; }
  .app-stats dd { font-size: 1.125rem; }
}

/* ── Apply step 1: documents ─────────────────────────────── */
.app-writing { display: flex; align-items: center; gap: var(--space-4); }
.app-writing .spinner { color: var(--accent); width: 24px; height: 24px; flex: none; }
.app-docs { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.app-doc { display: grid; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); text-decoration: none; color: inherit;
  transition: border-color var(--dur); }
.app-doc:hover { border-color: var(--line-strong); }
.app-doc > span:last-child { display: grid; gap: 2px; }
.app-doc__page { aspect-ratio: 210/150; border-radius: 8px; background: var(--surface-2); padding: 14px 16px; display: grid; align-content: start; gap: 6px; overflow: hidden; }
.app-doc__page i { display: block; height: 5px; border-radius: 3px; background: var(--line-strong); }
.app-doc__page i.h { height: 8px; width: 55%; background: var(--ink-3); }
.app-doc__page i.a { width: 30%; background: var(--accent); opacity: .7; }
.app-doc__page--mail i.h { width: 40%; }
.app-doc__name { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
@media (max-width: 560px) {
  .app-docs { grid-template-columns: 1fr; gap: var(--space-2); }
  .app-doc { grid-template-columns: 64px 1fr; align-items: center; }
  .app-doc__page { aspect-ratio: 1; padding: 8px; gap: 4px; }
  .app-doc__page i { height: 3px; } .app-doc__page i.h { height: 5px; }
}
.app-continue { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--space-3); }
.app-continue .small { display: inline-flex; align-items: center; gap: 6px; }
@media (max-width: 560px) { .app-continue { flex-direction: column-reverse; align-items: stretch; text-align: center; } .app-continue .small { justify-content: center; } }

.app-gen { display: grid; gap: var(--space-4); }
.app-gen__row { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.app-gen__kinds { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.app-gen__kinds .choice { min-height: 44px; }

/* Own files: which version goes out (Job Portal's or the user's file), extra files, the e-mail text. */
.app-section__title { font: var(--text-h3, 600 1.125rem/1.3 var(--font-sans)); margin: 0; }
.app-own > div > p { margin: 4px 0 0; }
.app-tiles { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.app-tile--wide { grid-column: 1 / -1; }
.app-tile { display: grid; align-content: start; gap: var(--space-3); padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); min-width: 0; }
.app-tile__head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.app-tile__icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); flex: none; }
.app-tile__title, .card .app-tile__title { font: 600 1rem/1.3 var(--font-sans); margin: 0; flex: 1 0 auto; }
.app-tile__text { margin: 0; }
.app-tile__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.app-tile__actions form { display: contents; }
.app-tile__actions .app-upload { display: flex; }
.app-file { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--surface-2);
  color: var(--ink); text-decoration: none; min-width: 0; }
.app-file:hover { background: var(--surface-3); }
.app-file > .icon { flex: none; color: var(--ink-2); }
.app-file__name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.app-file > .small { flex: none; display: inline-flex; align-items: center; gap: 4px; }
.app-upload { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.app-upload__pick { cursor: pointer; }
.app-upload__pick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.app-upload__pick.is-over { border-color: var(--accent); background: var(--accent-soft); }
.app-upload__busy { display: inline-flex; align-items: center; gap: 8px; }
.app-upload__busy[hidden] { display: none; }
.app-upload__busy .spinner { width: 16px; height: 16px; color: var(--accent); }
.upload-error { color: var(--bad); flex-basis: 100%; }
.app-emailform { padding-top: var(--space-2); }
.app-extras > div > p { margin: 4px 0 0; }
.app-extras__list, .app-files__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.app-extras__list li { display: flex; align-items: center; gap: 6px; min-width: 0; }
.app-extras__list .app-file { flex: 1; }
.app-extras__list form { flex: none; }
.app-extras > .app-upload { justify-self: start; }
.app-files { display: grid; gap: 6px; }
.app-files > p { margin: 4px 0 0; }
.app-file__text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.app-file__meta { color: var(--ink-3); }
.app-side__sub { display: block; font-weight: 400; overflow-wrap: anywhere; }
@media (max-width: 560px) {
  .app-tiles { grid-template-columns: 1fr; }
  .app-tile__actions, .app-tile__actions .app-upload { display: grid; gap: var(--space-2); }
  .app-tile__actions .btn { width: 100%; justify-content: center; }
}

/* ── Apply step 2: send ──────────────────────────────────── */
.app-send { display: grid; gap: var(--space-5); }
.app-ways { border: 0; padding: 0; margin: 0; }
.app-way--off { cursor: default; background: var(--surface-2); border-style: dashed; }
.app-way--off:hover { border-color: var(--line-strong); }
.app-way--off .option__title { color: var(--ink-2); }
.app-way__lock { display: grid; place-items: center; width: 18px; height: 18px; margin-top: 3px; color: var(--ink-3); }
.app-way--off a { font-weight: 600; }
.option__desc strong { color: var(--ink-2); }

.app-preview { display: grid; gap: var(--space-3); }
.app-dl { display: grid; gap: 8px; margin: 0; }
.app-dl > div { display: grid; grid-template-columns: 72px 1fr; gap: 12px; }
.app-dl dt { color: var(--ink-3); }
.app-dl dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.pill--file { text-decoration: none; height: 32px; }
a.pill--file:hover { background: var(--surface-3); }

.app-via { display: grid; gap: var(--space-4); }
.app-howto { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
/* Only the chosen way's panel and preview rows (browsers without :has show all panels). */
@supports selector(:has(*)) {
  .app-send:has(input[name="via"][value="portal"]:checked) .app-via:not(.app-via--portal),
  .app-send:has(input[name="via"][value="mail"]:checked) .app-via:not(.app-via--mail),
  .app-send:has(input[name="via"][value="site"]:checked) .app-via:not(.app-via--site),
  .app-send:has(input[name="via"][value="site"]:checked) .app-for-email,
  .app-send:not(:has(input[name="via"][value="site"]:checked)) .app-for-site { display: none; }
}
.app-marksent { display: grid; gap: 4px; padding: var(--space-4); border-radius: var(--radius-lg); background: var(--surface-2); }
.app-marksent__row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
.app-marksent .app-field { max-width: 240px; }

.app-copy { display: grid; gap: var(--space-3); padding: 4px 0 var(--space-2); }
.app-copy__item { display: grid; gap: 4px; }
.app-copy__row { display: flex; gap: 6px; align-items: flex-start; }
.app-copy__row .input, .app-copy__row .textarea { flex: 1; min-width: 0; background: var(--surface-2); }
.app-copy__btn { border: 1px solid var(--line-strong); flex: none; }

/* ── Application page ────────────────────────────────────── */
.app-next { display: grid; grid-template-columns: auto 1fr; gap: var(--space-3) var(--space-4); align-items: center; padding: var(--space-5); border-radius: var(--radius-lg);
  background: var(--accent-soft); }
.app-next__text { display: grid; gap: 2px; min-width: 0; }
.app-next__caps { color: var(--accent-text); }
.app-next__when { font: var(--text-h2); color: var(--ink); }
.app-next__actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: var(--space-2); }
.app-next__actions form { display: contents; }
.app-next__icon { width: 56px; height: 56px; border-radius: 12px; display: grid; place-items: center; background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-1); }
@media (min-width: 640px) { .app-next { grid-template-columns: auto 1fr auto; } .app-next__actions { grid-column: auto; justify-content: flex-end; } }
@media (max-width: 640px) {
  .app-next { padding: var(--space-3) var(--space-4); gap: 10px var(--space-3); }
  .app-next__when { font-size: 1.125rem; line-height: 1.3; }
  .app-next .app-cal, .app-next__icon { width: 46px; }
  .app-next__icon { height: 46px; }
  .app-cal span { font-size: 1.25rem; }
  .app-next__actions .btn { min-height: 40px; }
}
.app-cal { width: 56px; border-radius: 12px; overflow: hidden; background: var(--surface); text-align: center; box-shadow: var(--shadow-1); }
.app-cal b { display: block; background: var(--accent); color: var(--accent-ink); font: var(--text-caps); letter-spacing: .08em; text-transform: uppercase; padding: 3px 0; }
.app-cal span { display: block; font: 600 1.5rem/1.6 var(--font-serif); color: var(--ink); }

.app-mail { display: grid; gap: var(--space-3); min-width: 0; }
.app-mail__from { display: flex; gap: var(--space-3); align-items: flex-start; }
.app-mail__who { flex: 1; min-width: 0; display: grid; gap: 2px; justify-items: start; }
.app-mail__who strong { overflow-wrap: anywhere; }
.app-mail__kind { margin-top: 4px; }
.app-mail__caps { margin: 4px 0 8px; }
.app-mail__date { display: flex; gap: 8px; align-items: center; margin: 0; }
.app-mail__actions { margin-top: 2px; }
.app-mail__unlink { padding-left: 0; }
.app-mail__divider { margin: 2px 0; }
.app-mail__question { margin: 0; }
.app-todo { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.app-todo li { display: flex; gap: 10px; align-items: flex-start; }
.app-todo .icon { margin-top: 3px; color: var(--accent-text); }

.app-thread { overflow: hidden; }
.app-thread__item + .app-thread__item { border-top: 1px solid var(--line); }
.app-thread__item > summary { list-style: none; cursor: pointer; }
.app-thread__item > summary::-webkit-details-marker { display: none; }
.app-thread__item > summary:hover { background: var(--surface-2); }
.app-thread__item[open] .app-thread__chev { transform: rotate(90deg); }
.app-thread__chev { color: var(--ink-3); transition: transform var(--dur); }
.app-thread__body { display: grid; gap: var(--space-3); padding: 0 var(--space-5) var(--space-4); justify-items: start; }
.app-thread__body > * { max-width: 100%; }
.app-nomail { display: flex; gap: var(--space-3); align-items: flex-start; }
.app-nomail p { margin: 2px 0 0; }

.app-side__title { font: var(--text-h3, 600 1.125rem/1.3 var(--font-sans)); margin: 0 0 var(--space-2); display: block; }
.app-side__docs { display: grid; gap: 2px; }
.app-side__doc { display: flex; align-items: center; gap: var(--space-3); min-height: 44px; padding: 0 8px; margin: 0 -8px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 600; }
.app-side__doc span:first-of-type { flex: 1; }
.app-side__doc:hover { background: var(--surface-2); }
.app-side__doc .icon { color: var(--ink-2); }
.app-notes { display: grid; gap: var(--space-2); }
.app-notes .app-side__title { margin: 0; }
.app-notes .textarea { min-height: 90px; }

/* History (designer's timeline) */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-4); }
.timeline li { position: relative; display: grid; grid-template-columns: 28px 1fr auto; gap: var(--space-3); align-items: start; }
.timeline li::before { content: ""; position: absolute; left: 13px; top: 30px; bottom: calc(-1 * var(--space-4)); width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline__dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); }
.timeline__dot .icon { width: 14px; height: 14px; }
.timeline__dot--accent { background: var(--accent-soft); color: var(--accent-text); }
.timeline__body { min-width: 0; display: grid; gap: 2px; padding-top: 3px; }
.app-timeline__del { width: 36px; height: 36px; color: var(--ink-3); margin-top: -4px; }

/* ── Update-status sheet (:target, no JS needed) ─────────── */
.app-sheet { position: fixed; inset: 0; z-index: 50; display: none; align-items: end; justify-items: center; }
.app-sheet:target { display: grid; }
.app-sheet__scrim { position: absolute; inset: 0; background: var(--scrim); }
.app-sheet__panel { position: relative; display: grid; gap: var(--space-4); }
.app-sheet__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.app-sheet__head h2 { margin: 0; }
.app-sheet__head p { margin: 4px 0 0; }
.app-sheet__head .icon-btn { margin: -8px -8px 0 0; }
.app-sheet__options { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.app-sheet__option { padding: var(--space-3) var(--space-4); }
.app-sheet__fields { display: grid; gap: var(--space-3); grid-template-columns: 1fr 1fr; }
.app-sheet__date { grid-column: 1 / -1; }
.app-sheet__datetime, .app-sheet__place { display: none; }
.app-sheet__panel:has(input[name="type"][value="interview_scheduled"]:checked) .app-sheet__date { display: none; }
.app-sheet__panel:has(input[name="type"][value="interview_scheduled"]:checked) .app-sheet__datetime,
.app-sheet__panel:has(input[name="type"][value="interview_scheduled"]:checked) .app-sheet__place { display: grid; }
@media (max-width: 560px) { .app-sheet__fields { grid-template-columns: 1fr; } .app-sheet__option .option__desc { display: none; } }
@media (min-width: 700px) { .app-sheet { align-items: center; } .app-sheet__panel { border-radius: var(--radius-lg); } .app-sheet__panel .sheet__grip { display: none; } }
@media (min-width: 700px) { .app-sheet__options { grid-template-columns: 1fr 1fr; } }

/* ── Inbox ───────────────────────────────────────────────── */
.app-confirm { border-color: var(--warn); display: grid; gap: var(--space-4); }
.app-confirm__head { display: flex; gap: var(--space-3); align-items: center; }
.app-confirm__icon { background: var(--warn-soft); color: var(--warn); }
.app-confirm__title { font: var(--text-h3, 600 1.125rem/1.3 var(--font-sans)); margin: 0; }
.app-confirm__head p { margin: 2px 0 0; }
.app-confirm__row { gap: var(--space-3); }
.app-confirm__code { font: 600 1.375rem/1 var(--font-mono, ui-monospace, monospace); letter-spacing: .12em; padding: 10px 14px; background: var(--surface-2); color: var(--ink);
  border: 0; border-radius: var(--radius-sm); max-width: 100%; }
.app-confirm__foot { justify-content: space-between; align-items: flex-start; }
.app-choose { display: grid; gap: var(--space-3); }
.app-choose--other { display: none; padding: var(--space-4); border-radius: var(--radius-md); background: var(--surface-2); }
.app-choose--other:target { display: grid; }
.app-empty { display: grid; justify-items: center; gap: 4px; }
.app-empty__icon { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); margin-bottom: var(--space-2); }
.app-empty__icon .icon { width: 30px; height: 30px; }
.app-inbox-foot { text-align: center; }

/* Stacks use gap; cancel the older ".card + .card" margin inside them. */
.app-stack > :is(.card, form, section, article, div, details) { margin-top: 0; }
.app-confirm__row > span.row { flex-wrap: nowrap; gap: var(--space-2); max-width: 100%; }
input.app-confirm__code { width: auto; min-width: 0; min-height: 0; border: 0; box-shadow: none; }
#portal-send { display: none; }
