/* Тёмная тема: графит + синий акцент */
:root {
  --bg: #0c0f14;
  --bg-elev: #141922;
  --bg-card: #1a1f2a;
  --border: rgba(148, 163, 184, 0.18);
  --text: #e8eaef;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-dim: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.22);
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, var(--accent-glow), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(37, 99, 235, 0.12), transparent 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.page {
  min-height: 100vh;
  padding: clamp(1rem, 3vw, 2rem);
  max-width: 1120px;
  margin: 0 auto;
}

.layout {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar__logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  box-shadow: 0 0 24px var(--accent-glow);
}

.topbar__title {
  font-weight: 600;
  font-size: 1.05rem;
}

.topbar__sub {
  font-size: 0.8rem;
  color: var(--muted);
}

.topbar__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 900px) {
  .grid {
    grid-template-columns: 1.15fr 0.85fr;
    align-items: start;
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.card--narrow {
  max-width: 420px;
  margin: 8vh auto 0;
}

.card--aside {
  background: var(--bg-elev);
}

.card__title {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
  font-weight: 600;
}

.card__title--small {
  font-size: 1rem;
}

.card__lead {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field__label {
  font-size: 0.85rem;
  color: var(--muted);
}

.field__input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.field__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field__input--readonly {
  opacity: 0.85;
  cursor: default;
  background: var(--bg-elev);
}

.field-hint {
  margin: -0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.card--settings {
  max-width: 640px;
}

.settings-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.list--api {
  margin-top: 0.5rem;
}

.list--api a.link {
  font-weight: 500;
}

.form__actions {
  margin-top: 0.25rem;
}

.form--inline {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  font-family: inherit;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  color: #fff;
  border-color: rgba(255, 255, 255, 0.12);
}

.btn--primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn--ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn--ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge--ok {
  border-color: rgba(74, 222, 128, 0.35);
  color: var(--ok);
}

.badge--warn {
  border-color: rgba(251, 191, 36, 0.4);
  color: #fbbf24;
}

.notice {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.25);
  color: var(--muted);
  font-size: 0.9rem;
}

.notice--error {
  background: rgba(248, 113, 113, 0.08);
  border-color: rgba(248, 113, 113, 0.35);
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.flash--ok {
  background: rgba(74, 222, 128, 0.1);
  border: 1px solid rgba(74, 222, 128, 0.35);
  color: var(--ok);
}

.flash--err {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: var(--danger);
}

.list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.list li {
  margin-bottom: 0.5rem;
}

.hints-lead {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
}

.list--hints {
  padding-left: 0;
  list-style: none;
}

.list--hints > li {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.list--hints > li:last-child {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

.list--hints__group {
  display: block;
  color: var(--text);
  font-size: 0.92rem;
  margin-bottom: 0.35rem;
}

.list--hints__desc {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
  line-height: 1.45;
}

.list--nested {
  margin: 0.35rem 0 0;
  padding-left: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.list--nested li {
  margin-bottom: 0.35rem;
}

.list--nested code {
  white-space: nowrap;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.form-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 0.5rem 0 0.25rem;
  padding: 1rem 0 0;
  border-top: 1px solid var(--border);
}

.form-section--contract {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.form-section__title {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.contract-fields {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field__input--date {
  min-height: 2.75rem;
  color-scheme: dark;
}

.field--contract-preview .field__label {
  margin-bottom: 0.35rem;
}

.contract-preview {
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.45;
  min-height: 2.75rem;
}

.field-row--date-num {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0.75rem;
  width: 100%;
}

.field-row--date-num .field--compact {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field--row-split {
  margin-bottom: 0;
}

.party-rep-fields {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 0.25rem;
}

.party-rep-fields--in-section {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
}

.field__input--textarea {
  width: 100%;
  min-height: 8rem;
  resize: vertical;
  font-family: inherit;
  line-height: 1.45;
}

.field__input:disabled,
.field__input--select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.field-row--basis {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0.75rem;
  width: 100%;
}

.field-row--basis .field--compact {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

@media (max-width: 520px) {
  .field-row--date-num {
    flex-direction: column;
  }
  .field-row--basis {
    flex-direction: column;
  }
}

.fields-dynamic {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field--counterparty .field__label {
  margin-bottom: 0.35rem;
}

.field-row {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0.75rem;
  width: 100%;
}

.field-row__select {
  flex: 0 0 auto;
  min-width: 10rem;
  max-width: 42%;
}

.field-row__text {
  flex: 1 1 auto;
  min-width: 0;
}

@media (max-width: 520px) {
  .field-row {
    flex-direction: column;
  }
  .field-row__select {
    max-width: none;
    width: 100%;
  }
}

.result {
  margin-top: 1.25rem;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
}

.result.hidden {
  display: none;
}

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

.result__ok {
  color: var(--ok);
  margin-bottom: 0.75rem;
}

.result__err {
  color: var(--danger);
}

.result__folder {
  margin: 0.5rem 0 0.75rem;
  font-size: 0.95rem;
}

.result__notice {
  margin: 0.65rem 0 0.5rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.1);
  color: #fbbf24;
  font-size: 0.9rem;
}

.result__links {
  margin: 0;
  padding-left: 1.1rem;
}

.link {
  color: var(--accent);
  text-decoration: none;
}

.link:hover {
  text-decoration: underline;
}
