/* ==========================================================================
   Admin shell — header, page layout, stat tiles, data tables, toolbars,
   and the editor's sticky bar. Document styles live in doc.css.
   ========================================================================== */

/* --- Header --------------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--ink);
  color: #fff;
}

.app-header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  max-width: var(--container);
  min-height: var(--header-h);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: #fff;
  text-decoration: none;
}

.app-header__logo {
  height: 26px;
  width: auto;
  filter: brightness(0) invert(1);
}

.app-header__product {
  padding-left: var(--space-3);
  border-left: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--gold);
  font-size: var(--size-xs);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.app-nav {
  display: flex;
  gap: var(--space-1);
  margin-left: auto;
}

.app-nav__link {
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.5;
  cursor: pointer;
  font-size: var(--size-sm);
  font-weight: 600;
  text-decoration: none;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.app-nav__link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.app-nav__link[aria-current="page"] {
  background: rgba(200, 162, 52, 0.18);
  color: var(--gold);
}

.app-nav__link--logout {
  margin-left: var(--space-2);
  color: rgba(255, 255, 255, 0.5);
}

/* --- Page ----------------------------------------------------------------- */

.page {
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--space-6) var(--gutter) var(--space-7);
}

.page__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.page__eyebrow {
  color: var(--gold-deep);
  font-size: var(--size-xs);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.page__title {
  margin-top: var(--space-1);
  font-size: var(--size-display);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.page__lead {
  margin-top: var(--space-2);
  max-width: 60ch;
  color: var(--muted);
  font-size: var(--size-sm);
}

.page__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* --- Stat tiles ----------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.stat {
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--paper);
  box-shadow: var(--shadow-card);
}

.stat__label {
  color: var(--muted);
  font-size: var(--size-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat__value {
  margin-top: var(--space-1);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat--released .stat__value {
  color: var(--ink-soft);
}

.stat--pending .stat__value {
  color: var(--gold-deep);
}

.stat--signed .stat__value {
  color: var(--success);
}

/* --- Card + toolbar ------------------------------------------------------- */

/* No overflow clipping: row action menus open past the card edge. The
   rounded corners are carried by the first and last children instead. */
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--paper);
  box-shadow: var(--shadow-card);
}

.card > :first-child {
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
}

.card > :last-child,
.table tbody tr:last-child td:first-child {
  border-bottom-left-radius: inherit;
}

.card > :last-child,
.table tbody tr:last-child td:last-child {
  border-bottom-right-radius: inherit;
}

.table-wrap,
.table,
.table tbody,
.table tbody tr:last-child {
  border-radius: inherit;
}

.card__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--line);
}

.card__toolbar .field__input {
  min-height: 38px;
}

.card__search {
  flex: 1 1 240px;
  max-width: 420px;
}

.card__filter {
  flex: 0 0 auto;
  width: 220px;
}

.card__count {
  margin-left: auto;
  color: var(--muted);
  font-size: var(--size-sm);
}

/* --- Data table ----------------------------------------------------------- */

/* Row menus overflow the card, so the wrap must not clip. */
.table-wrap {
  overflow: visible;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--size-sm);
}

.table th,
.table td {
  padding: 14px var(--space-4);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.table th:first-child,
.table td:first-child {
  padding-left: var(--space-5);
}

.table th:last-child,
.table td:last-child {
  padding-right: var(--space-5);
}

.table thead th {
  color: var(--muted);
  font-size: var(--size-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.table tbody tr {
  transition: background var(--dur) var(--ease);
}

.table tbody tr:hover {
  background: var(--panel);
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table__primary {
  font-weight: 700;
}

.table__secondary {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: var(--size-xs);
}

.table__num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.table th.table__num {
  text-align: right;
}

.table__menu {
  text-align: right;
}

.table__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-1);
  white-space: nowrap;
}

.table__link {
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.table__link:hover {
  color: var(--gold-deep);
}

.table__flag {
  display: inline-block;
  margin-left: 6px;
  color: var(--danger);
  font-size: var(--size-xs);
  font-weight: 700;
}

.empty {
  padding: var(--space-7) var(--space-5);
  color: var(--muted);
  font-size: var(--size-sm);
  text-align: center;
}

.empty__title {
  margin-bottom: var(--space-1);
  color: var(--ink);
  font-size: var(--size-lg);
  font-weight: 700;
}

/* --- Login ---------------------------------------------------------------- */

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: var(--gutter);
}

.login__card {
  width: min(400px, 100%);
  padding: var(--space-6);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--paper);
  box-shadow: var(--shadow-card);
}

.login__logo {
  height: 32px;
  width: auto;
  margin-bottom: var(--space-5);
}

.login__title {
  font-size: var(--size-xl);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.login__lead {
  margin: var(--space-2) 0 var(--space-5);
  color: var(--muted);
  font-size: var(--size-sm);
}

.login__form {
  display: grid;
  gap: var(--space-4);
}

.login__key {
  font-size: 22px;
  letter-spacing: 0.4em;
  text-align: center;
}

/* --- Editor bar ----------------------------------------------------------- */

.editor-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 15;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.editor-bar__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-4);
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--space-3) var(--gutter);
}

.editor-bar__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  min-width: 0;
}

.editor-bar__number {
  font-size: var(--size-lg);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.editor-bar__save {
  color: var(--muted);
  font-size: var(--size-xs);
}

.editor-bar__save[data-state="dirty"] {
  color: var(--danger);
}

.editor-bar__save[data-state="saving"] {
  color: var(--gold-deep);
}

.editor-bar__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.editor-bar__client {
  min-width: 220px;
}

/* --- Editor panels (share, signed) --------------------------------------- */

.editor {
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--space-5) var(--gutter) var(--space-7);
}

.notice {
  display: grid;
  gap: var(--space-3);
  width: 210mm;
  max-width: 100%;
  margin: 0 auto var(--space-5);
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius-md);
  background: var(--paper);
  box-shadow: var(--shadow-card);
  scroll-margin-top: calc(var(--header-h) + 88px);
}

.notice--signed {
  border-left-color: var(--success);
}

.notice__title {
  font-size: var(--size-md);
  font-weight: 700;
}

.notice__text {
  color: var(--muted);
  font-size: var(--size-sm);
}

.notice__text strong {
  color: var(--danger);
}

.notice__row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.notice__row .field__input {
  flex: 1 1 260px;
  min-width: 0;
  font-size: var(--size-sm);
}

.payment-list {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.payment-list__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--desk);
  font-size: var(--size-sm);
}

.payment-list__main {
  display: grid;
  min-width: 0;
}

.payment-list__actions {
  display: flex;
  gap: var(--space-1);
}

.payment-list__empty {
  color: var(--muted);
  font-size: var(--size-sm);
}

.payment-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--desk);
}

.payment-info__item dt {
  color: var(--muted);
  font-size: var(--size-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.payment-info__item dd {
  margin: 2px 0 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.choice {
  margin: 0;
  padding: 0;
  border: 0;
}

.choice__list {
  display: grid;
  gap: var(--space-2);
  max-height: 260px;
  overflow-y: auto;
}

.choice__item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-3);
  align-items: start;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}

.choice__item:hover {
  border-color: var(--gold);
}

.choice__item:has(input:checked) {
  border-color: var(--gold);
  background: var(--gold-tint);
}

.choice__item input {
  margin-top: 3px;
}

.choice__body {
  display: grid;
  gap: 2px;
  font-size: var(--size-sm);
}

.choice__title {
  font-weight: 700;
}

.choice__text {
  color: var(--muted);
}

.stat--unpaid .stat__value {
  color: var(--danger);
}

.stat__value--money {
  font-size: 20px;
}

.editor__hint {
  width: 210mm;
  max-width: 100%;
  margin: 0 auto var(--space-3);
  color: var(--muted);
  font-size: var(--size-xs);
  text-align: center;
}

/* --- Narrow screens ------------------------------------------------------- */

@media (max-width: 720px) {
  .app-header__product {
    display: none;
  }

  /* Four sections no longer fit beside the logo: the menu drops to its own scrollable row.
     The taller header then scrolls away and the editor bar takes the top edge. */
  .app-header {
    position: static;
  }

  .editor-bar {
    top: 0;
  }

  .app-header__inner {
    flex-wrap: wrap;
    row-gap: 0;
    padding-top: var(--space-2);
  }

  .app-nav {
    width: 100%;
    margin: 0 calc(var(--space-2) * -1);
    padding-bottom: var(--space-2);
    overflow-x: auto;
    scrollbar-width: none;
  }

  .app-nav__link {
    flex: none;
    padding: 8px;
    font-size: var(--size-xs);
    white-space: nowrap;
  }

  .app-nav__link--logout {
    margin-left: auto;
  }

  .page {
    padding-top: var(--space-5);
  }

  .card__toolbar {
    padding: var(--space-3) var(--space-4);
  }

  .card__filter {
    width: 100%;
  }

  .card__count {
    margin-left: 0;
  }

  /* The table folds into stacked cards; each cell carries its heading. */
  .table thead {
    display: none;
  }

  .table,
  .table tbody,
  .table tr,
  .table td {
    display: block;
  }

  .table tr {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--line);
  }

  .table td,
  .table td:first-child,
  .table td:last-child {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 6px 0;
    border: 0;
    text-align: right;
  }

  .table td::before {
    content: attr(data-label);
    flex: none;
    color: var(--muted);
    font-size: var(--size-xs);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .table td[data-label=""]::before {
    display: none;
  }

  .table__num {
    text-align: right;
  }

  .table__menu {
  text-align: right;
}

.table__actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
    padding-top: var(--space-2);
  }

  .editor-bar__actions {
    width: 100%;
    margin-left: 0;
  }

  .editor-bar__client {
    width: 100%;
  }
}

@media print {
  .app-header,
  .editor-bar,
  .notice,
  .editor__hint,
  .toast {
    display: none;
  }

  .editor {
    padding: 0;
  }
}
