:root {
  --bg: #f3f0e8;
  --ink: #1a1f16;
  --muted: #5c6356;
  --card: #fffdf8;
  --line: #d5d0c4;
  --accent: #2f5d3a;
  --accent-ink: #fff;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --err: #8b1e1e;
  --err-bg: #fde8e8;
  --ok-bg: #e7f3ea;
  --font: "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, Consolas, monospace;
  --pad: clamp(1rem, 2.5vw, 2.5rem);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 16px;
  color: var(--ink);
  background:
    radial-gradient(1400px 560px at 8% -8%, #e7efe6 0%, transparent 55%),
    radial-gradient(1100px 480px at 100% 0%, #efe6d6 0%, transparent 50%),
    var(--bg);
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem 1.5rem;
  padding: 1rem var(--pad);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.brand strong {
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.brand .muted { font-size: 0.95rem; }

.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 0.98rem;
}

.tab.active {
  color: var(--ink);
  border-color: var(--line);
  background: #fff;
  font-weight: 600;
}

main {
  flex: 1 1 auto;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 1.5rem var(--pad) 2.5rem;
}

h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.6rem, 2.2vw, 2rem);
}

h2 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
}

.lead {
  margin: 0 0 1.35rem;
  color: var(--muted);
  max-width: none;
  line-height: 1.5;
  font-size: 1.02rem;
}

.steps {
  margin: 0 0 1.25rem;
  padding-left: 1.35rem;
  color: var(--muted);
  line-height: 1.55;
  max-width: none;
  font-size: 1.02rem;
}

.steps strong { color: var(--ink); }

.flow-steps {
  list-style: none;
  margin: 0 0 1.35rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem 1rem;
}

@media (max-width: 820px) {
  .flow-steps { grid-template-columns: 1fr; }
}

.flow-step {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin: 0;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 253, 248, 0.9);
}

.flow-step__n {
  flex: 0 0 auto;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--accent-ink);
  background: var(--accent);
}

.flow-step__body {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.flow-step__body strong {
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--ink);
}

.flow-step__body span {
  font-size: 0.92rem;
  font-weight: 400;
  line-height: 1.4;
  color: var(--muted);
}

.flow-step__next {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}

.preview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.55rem 1.25rem;
  margin: 0 0 1.15rem;
  padding: 0.9rem 1.1rem;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,0.55);
  font-size: 1rem;
}

.preview .k {
  display: inline-block;
  min-width: 10rem;
  color: var(--muted);
}

.preview code {
  font-family: var(--mono);
  font-size: 0.95rem;
}

.lead code, .muted code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: rgba(0,0,0,0.05);
  padding: 0.05em 0.3em;
  border-radius: 3px;
}

.panel {
  width: 100%;
}

.panel[hidden] { display: none !important; }

.card {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.35rem 1.5rem 1.5rem;
  box-shadow: 0 1px 0 rgba(255,255,255,0.7) inset;
}

.card.compact { margin-bottom: 1.15rem; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem 1.25rem;
  margin-bottom: 1.1rem;
}

#client-form .grid {
  grid-template-columns: minmax(14rem, 2.2fr) minmax(8rem, 1fr) minmax(10rem, 1.3fr) auto;
}

@media (max-width: 720px) {
  #client-form .grid { grid-template-columns: 1fr; }
}

.grid > .span-2 {
  grid-column: 1 / -1;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.95rem;
  color: var(--muted);
}

label .hint,
.hint {
  font-size: 0.84rem;
  line-height: 1.4;
  color: var(--muted);
  font-weight: 400;
}

label.check {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
  margin-top: 1.75rem;
}

#client-form label.check {
  margin-top: 0.35rem;
  align-self: end;
  padding-bottom: 0.55rem;
}

.issue-layout {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(0, 2fr);
  gap: 1.15rem 1.35rem;
  align-items: start;
  margin-bottom: 1.1rem;
}

@media (max-width: 900px) {
  .issue-layout { grid-template-columns: 1fr; }
}

.license-body {
  min-width: 0;
}

.license-row {
  display: grid;
  gap: 0.85rem 1.1rem;
  margin-bottom: 1rem;
  align-items: start;
}

.license-row:last-child { margin-bottom: 0; }

/* Numbers stay compact; text fields take the rest. */
.license-row--limits {
  grid-template-columns: 8.5rem minmax(12rem, 1fr) auto;
  justify-content: start;
}

.term-input-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.term-input-row input[type="number"] {
  flex: 0 0 auto;
  width: 5.5rem;
  max-width: none;
}

.term-input-row .term-hint {
  flex: 1 1 auto;
  margin: 0;
  line-height: 1.35;
  white-space: normal;
}

.license-row--holder {
  grid-template-columns: minmax(11rem, 15rem) minmax(14rem, 1fr) auto;
}

.license-row--site {
  grid-template-columns: minmax(0, 1fr) minmax(9rem, 12rem);
}

.field-narrow input[type="number"] {
  width: 100%;
  max-width: 8.5rem;
}

.field-grow { min-width: 0; }

.field-contract { min-width: 0; }

.license-body .field-check {
  margin-top: 0;
  align-self: end;
  padding-bottom: 0.7rem;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .license-row--limits,
  .license-row--holder,
  .license-row--site {
    grid-template-columns: 1fr;
  }

  .field-narrow input[type="number"] { max-width: none; }

  .license-body .field-check {
    align-self: start;
    padding-bottom: 0;
  }
}

.plan-field {
  margin: 0;
  padding: 0.9rem 1.1rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.45);
  display: grid;
  gap: 0.55rem;
  align-self: stretch;
}

.plan-field legend {
  padding: 0 0.35rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.plan-opt {
  flex-direction: row;
  align-items: flex-start;
  gap: 0.65rem;
  margin: 0;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
}

.plan-opt:hover { background: rgba(47, 93, 58, 0.06); }

.plan-opt:has(input:checked) {
  background: rgba(47, 93, 58, 0.1);
  outline: 1px solid rgba(47, 93, 58, 0.28);
}

.plan-opt input {
  margin-top: 0.2rem;
  width: auto;
  flex: 0 0 auto;
}

.plan-opt span {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.plan-opt strong {
  font-size: 1.02rem;
  font-weight: 600;
}

.plan-opt small {
  font-size: 0.86rem;
  line-height: 1.4;
  color: var(--muted);
  font-weight: 400;
}

.term-field.is-disabled,
.company-field.is-disabled,
.demo-field.is-disabled {
  opacity: 0.55;
}

.term-field.is-disabled input,
.company-field.is-disabled input,
.demo-field.is-disabled input {
  background: #f0eee8;
  cursor: not-allowed;
}

.badge-demo,
.badge-archive {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
}

.badge-demo {
  color: #6b4a00;
  background: #ffe8a8;
}

.badge-archive {
  color: #4a5560;
  background: #e4e7eb;
}

.client-block--archived {
  opacity: 0.78;
  border-style: dashed;
}

.client-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-left: auto;
}

.client-actions button {
  padding: 0.35rem 0.7rem;
  font-size: 0.88rem;
}

.client-head {
  width: 100%;
}

.subtabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 1.1rem;
}

.subtab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
}

.subtab.active {
  color: var(--ink);
  border-color: var(--line);
  background: #fff;
  font-weight: 600;
}

.subtab-refresh {
  margin-left: auto;
}

input[type="text"],
input[type="number"],
select {
  font: inherit;
  font-size: 1.02rem;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  background: #fff;
  width: 100%;
}

input:disabled {
  color: var(--muted);
}

.catalog-tree {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.client-block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.2rem 1.15rem;
}

.client-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 1rem;
  margin-bottom: 0.75rem;
}

.client-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.client-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.client-block .inst-table {
  margin: 0;
}

.client-block .inst-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.inst-table .inst-actions {
  white-space: nowrap;
  vertical-align: middle;
}

.inst-table .reissue-row > td {
  padding: 0.75rem 0.5rem 1rem;
  background: transparent;
  border-bottom: none;
}

.inst-table .reissue-form {
  margin: 0;
}

.nested-label {
  display: block;
  margin: 0 0 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.file span {
  margin-bottom: 0.4rem;
  display: block;
  color: var(--muted);
  font-size: 0.95rem;
}

.file { margin-bottom: 1.1rem; }

.file input[type="file"] {
  font-size: 1rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 0.5rem;
}

button {
  font: inherit;
  font-size: 1rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 0.65rem 1.15rem;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  min-width: 14rem;
}

button.ghost { background: transparent; }

button:disabled { opacity: 0.55; cursor: not-allowed; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.15rem;
}

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.98rem;
}

th, td {
  text-align: left;
  padding: 0.55rem 0.45rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }

td { font-variant-numeric: tabular-nums; word-break: break-word; }

.banner {
  margin: 0 0 1.15rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 1rem;
}

.banner.ok { background: var(--ok-bg); color: var(--accent); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.err { background: var(--err-bg); color: var(--err); }

.banner--foot {
  margin: 0;
  border-radius: 0;
  position: sticky;
  bottom: 0;
  z-index: 20;
}

.muted { color: var(--muted); font-size: 0.9rem; }

.foot {
  text-align: center;
  padding: 1.15rem var(--pad) 1.5rem;
  border-top: 1px solid transparent;
}

.help-card {
  margin-bottom: 1rem;
}

.help-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.12rem;
}

.help-list {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--ink);
  line-height: 1.55;
}

.help-list li { margin-bottom: 0.55rem; }
.help-list li:last-child { margin-bottom: 0; }

.help-dl {
  margin: 0;
  display: grid;
  gap: 0.85rem 1.25rem;
}

.help-dl dt {
  font-weight: 650;
  color: var(--ink);
  margin: 0;
}

.help-dl dd {
  margin: 0.25rem 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.help-card code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.05);
  padding: 0.05em 0.3em;
  border-radius: 3px;
}

.online-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.online-card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.55rem 1rem;
}

.online-card__title {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.online-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.online-card__summary {
  margin: 0.45rem 0 0;
}

.online-card--decided[data-open='1'] {
  border-color: rgba(47, 93, 58, 0.35);
}

.online-detail-dl {
  margin: 0.65rem 0 0.85rem;
  display: grid;
  gap: 0.45rem 1rem;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}

.online-detail-dl > div {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.online-detail-dl dt {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.online-detail-dl dd {
  margin: 0;
  font-weight: 600;
  word-break: break-word;
}

.online-detail-dl code {
  font-size: 0.92rem;
}

.online-card__head code {
  font-family: var(--mono);
  font-size: 0.95rem;
  word-break: break-all;
}

.tab--logout {
  margin-left: auto;
  border-color: var(--line);
  color: var(--muted);
}

.login-page {
  display: grid;
  place-items: center;
  padding: var(--pad);
}

.login-card {
  width: min(100%, 22rem);
  padding: 1.5rem 1.35rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(26, 31, 22, 0.06);
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 1.25rem;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.login-card input {
  font: inherit;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.login-card button.primary {
  margin-top: 0.35rem;
  font: inherit;
  font-weight: 700;
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}

.login-card button.primary:hover {
  filter: brightness(1.05);
}
