* { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  color-scheme: light;
  --ink: #1c202a;
  --muted: #555d6c;
  --accent: #c9162c;
  --accent-hover: #a91023;
  --line: #e1e5eb;
  --surface: #fff;
  --wash: #f3f5f8;
  --rail: #20232c;
  --radius: 14px;
  --shadow: 0 2px 3px #1d273a08, 0 8px 22px #1d273a05;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--wash);
  font: 15px/1.55 "Instrument Sans", "Segoe UI", system-ui, sans-serif;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(31px, 3.6vw, 49px); line-height: 1.09; letter-spacing: -.053em; }
h2 { font-size: 21px; line-height: 1.25; letter-spacing: -.035em; }
h3 { font-size: 16px; letter-spacing: -.016em; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; }
.hint { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.top {
  grid-area: top;
  background: var(--surface);
  border-top: 4px solid var(--accent);
  border-bottom: 1px solid var(--line);
}
.top-inner {
  min-height: 67px;
  padding: 11px clamp(16px, 3.2vw, 48px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.brand { display: inline-flex; align-items: center; gap: 14px; text-decoration: none; color: var(--ink); }
.brand-logo { display: block; width: 116px; height: auto; }
.brand-title { padding-left: 14px; border-left: 1px solid var(--line); font-size: 16px; font-weight: 800; letter-spacing: .13em; }
.identity, #identity { display: flex; gap: 12px; align-items: center; font-size: 13px; font-weight: 650; }
#identity:empty { display: none; }
#identity button { min-height: 32px; padding: 4px 11px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 25px;
  background: #eceff4;
  color: #394353;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; background: currentColor; border-radius: 50%; flex: none; }
#environment .pill { color: #a31429; background: #fcebf0; }

main { grid-area: main; width: 100%; min-width: 0; max-width: 1480px; margin-inline: auto; padding: clamp(20px, 3.5vw, 48px); }
.has-session {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "side main";
  min-height: 100vh;
}
.sidebar { grid-area: side; background: var(--rail); padding: 28px 14px; }
#navigation { display: grid; gap: 5px; position: sticky; top: 25px; }
#navigation a {
  min-height: 43px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 8px;
  text-decoration: none;
  color: #dce0ea;
  font-size: 13px;
  font-weight: 650;
}
#navigation a:hover { background: #ffffff10; color: #fff; }
#navigation a[aria-current="page"] { background: #ffffff17; box-shadow: inset 3px 0 #ff5868; color: #fff; }
.nav-icon { position: relative; flex: none; width: 15px; height: 15px; }
.icon-register { border: 1.5px solid currentColor; border-radius: 3px; }
.icon-register::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 3px;
  right: 3px;
  height: 1px;
  background: currentColor;
  box-shadow: 0 3px currentColor;
}
.icon-report {
  border-bottom: 1.5px solid currentColor;
  background: linear-gradient(currentColor,currentColor) 1px bottom / 3px 5px no-repeat,
              linear-gradient(currentColor,currentColor) 6px bottom / 3px 8px no-repeat,
              linear-gradient(currentColor,currentColor) 11px bottom / 3px 12px no-repeat;
}

.intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 25px;
  padding: clamp(21px, 3vw, 38px);
  border-radius: 16px;
  color: white;
  background: radial-gradient(ellipse at 100% 115%, #a617356b 0, transparent 50%), linear-gradient(118deg, #222630 45%, #342833);
  border: 1px solid #282a35;
  box-shadow: 0 8px 22px #23283819;
}
.kicker { color: #ffc2cd; font-size: 11px; font-weight: 780; letter-spacing: .13em; text-transform: uppercase; margin-bottom: 9px; }
.intro .hint { color: #e1e4eb; margin-top: 9px; max-width: 52ch; }
#new { flex: none; }
#new span { font-size: 20px; line-height: 0; vertical-align: -.06em; margin-right: 3px; }
.button, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
}
.primary { background: var(--accent); color: white; }
.primary:hover { background: var(--accent-hover); }
.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.secondary:hover { background: #f3f5f8; }
button:disabled { opacity: .55; cursor: wait; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 21px; }
.card, .stat { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.stat { padding: 17px 14px; display: flex; align-items: center; gap: 11px; }
.stat-symbol {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 9px;
  background: #edf0fc;
  color: #4658a0;
  font-size: 21px;
  font-weight: 700;
  line-height: 1;
}
.stat.waiting .stat-symbol { background: #fff1d8; color: #805300; }
.stat.attention .stat-symbol { background: #fcebf0; color: #ac3549; }
.stat.done .stat-symbol { background: #e6f5ed; color: #176844; }
.stat-label, .report-metric span { display: block; font-size: 12px; color: var(--muted); font-weight: 650; }
.stat strong { display: block; font-size: 28px; line-height: 1.13; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.card-top, .section-title, .actions { display: flex; align-items: center; justify-content: space-between; gap: 13px; }
.card-top, .form-body, .actions { padding: 17px 21px; }
.card-top, .form-body { border-bottom: 1px solid var(--line); }
.card-top .hint { margin-top: 4px; font-size: 13px; }
.search { position: relative; width: min(100%, 260px); }
.search::before {
  content: "";
  position: absolute;
  top: 12px;
  left: 12px;
  width: 9px;
  height: 9px;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  pointer-events: none;
}
.search::after { content: ""; position: absolute; top: 22px; left: 21px; width: 5px; height: 1.5px; transform: rotate(45deg); background: var(--muted); pointer-events: none; }
.search input { padding-left: 32px; }

.table-wrap { overflow: auto; border-bottom-left-radius: inherit; border-bottom-right-radius: inherit; }
table { border-collapse: collapse; width: 100%; font-size: 13px; text-align: left; white-space: nowrap; }
th, td { padding: 12px 16px; border-bottom: 1px solid var(--line); }
th { background: #f5f7fa; color: #475166; font-size: 11px; font-weight: 750; text-transform: uppercase; letter-spacing: .045em; }
tbody tr:nth-child(even) { background: #fafbfd; }
tbody tr:hover { background: #f1f4f9; }
tbody tr:last-child td { border-bottom: 0; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
td strong { font-weight: 750; }
td .sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
td button { min-height: 32px; padding: 4px 10px; font-size: 12px; }
.empty { color: var(--muted); text-align: center; padding: 32px 15px; }
.pending { color: #744d00; background: #fff1d8; }
.returned, .failed { color: #92334a; background: #fcebf0; }
.publishing { background: #e6effb; color: #265184; }
.approved, .demo-approved, .published { background: #e6f5ed; color: #176844; }

input, textarea, select {
  background: white;
  border: 1px solid #c7cdd8;
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 39px;
  min-width: 0;
  width: 100%;
  color: var(--ink);
}
input::placeholder, textarea::placeholder { color: #606a7c; }
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px 16px; }
.form-body > h3, .section-title { margin-bottom: 13px; }
.conditional { margin-top: 13px; }
.form-card label, .filters label, dialog label, #login-form label { display: grid; gap: 5px; font-size: 13px; font-weight: 650; }
.form-card small { font-weight: 400; color: var(--muted); }
.currency { max-width: 160px; margin-bottom: 12px; }
.line {
  display: grid;
  grid-template-columns: repeat(2, minmax(110px, 1.2fr)) repeat(3, minmax(70px, .7fr)) auto;
  gap: 9px;
  align-items: end;
  padding: 12px;
  margin-bottom: 9px;
  border-radius: 10px;
  background: #f6f8fb;
}
.line-meta { grid-column: 1/-1; font-size: 12px; color: var(--muted); }
.line-meta:empty { display: none; }
.upload { background: #fff7f8; border: 1px dashed #bd6879; border-radius: 9px; padding: 15px; }
.upload input { background: white; }
input::file-selector-button { border: 0; border-radius: 5px; background: #f1e5e9; color: #832238; padding: 4px 8px; margin-right: 8px; cursor: pointer; }
.actions { justify-content: flex-end; }
.actions p:not(:empty) { margin-right: auto; }
#form-error, #login-error, #review-error { color: #a41b30; }

.filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 17px 21px 13px; }
.report-totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; padding: 0 21px 18px; }
.report-metric { padding: 11px 13px; background: #f3f5f9; border-radius: 8px; }
.report-metric strong { display: block; font-size: 20px; line-height: 1.24; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }

#gate { padding: 24px; max-width: 440px; }
body:not(.has-session) main { max-width: 980px; }
#gate > p { color: var(--muted); margin-top: 5px; }
#login-form { display: grid; gap: 13px; margin-top: 18px; }
#login-form button { justify-self: start; }
#login-error:empty { display: none; }
#notice { padding: 11px 14px; margin-bottom: 16px; border: 1px solid #b7daca; background: #edf8f2; color: #21593e; border-radius: 8px; }
#notice.error { border-color: #edbdc3; background: #fff0f2; color: #912336; }

dialog { width: min(770px, calc(100% - 24px)); max-height: 90vh; border: 1px solid var(--line); border-radius: 16px; padding: 22px; color: var(--ink); box-shadow: 0 18px 70px #25252840; }
dialog::backdrop { background: #1b1e28a3; }
dialog .close { float: right; margin-left: 10px; }
dialog h2 { margin-bottom: 12px; }
dialog h3 { margin: 15px 0 7px; }
dialog dl { display: grid; grid-template-columns: minmax(105px, .45fr) 1fr; gap: 7px 12px; }
dialog dt { color: var(--muted); }
dialog dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 9px 0; }

@media (max-width: 1120px) {
  .has-session { grid-template-columns: 184px minmax(0, 1fr); }
  .sidebar { padding-inline: 9px; }
  .stat { gap: 7px; padding: 12px 10px; }
  .stat-symbol { width: 29px; height: 29px; font-size: 17px; }
  .line { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .has-session { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr; grid-template-areas: "top" "side" "main"; }
  .sidebar { padding: 6px clamp(14px, 3.5vw, 30px); }
  #navigation { display: flex; position: static; }
  #navigation a { min-height: 38px; }
  #navigation a[aria-current="page"] { box-shadow: inset 0 -3px #ff5868; }
}

@media (max-width: 590px) {
  main { padding: 16px 13px 35px; }
  .top-inner { padding: 9px 13px; }
  .identity { align-items: flex-end; flex-direction: column; gap: 4px; }
  #identity { gap: 6px; font-size: 12px; }
  .brand { gap: 8px; }
  .brand-logo { width: 92px; }
  .brand-title { font-size: 13px; padding-left: 8px; }
  .intro { align-items: flex-start; flex-direction: column; margin-bottom: 16px; }
  .card-top { align-items: flex-start; flex-wrap: wrap; }
  .card-top, .form-body, .actions { padding: 14px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-bottom: 15px; }
  .search { width: 100%; }
  th, td { padding: 10px 12px; }
  .filters, .report-totals { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; padding-inline: 14px; }
  .report-metric strong { font-size: 17px; }
  .form-grid, .line { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .section-title { align-items: flex-start; flex-wrap: wrap; }
}

@media (max-width: 360px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  #navigation a { padding-inline: 8px; font-size: 12px; }
}

#pdf-status:not([hidden]) {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #edf8f2;
  color: #21593e;
}
#pdf-status.pdf-warning { background: #fff1d8; color: #744d00; }
#items-recon:not(:empty) { margin-top: 9px; }
#items-panel { border: 1px solid var(--line); border-radius: 8px; }
.invoice-items input { width: 75px; min-height: 33px; font-size: 13px; padding: 5px 7px; }
.invoice-items td:first-child input { width: 245px; }
.invoice-items td, .invoice-items th { padding: 8px; }
.invoice-items td:not(:first-child) input { text-align: right; }
