:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --text: #e8eef7;
  --muted: #8fa3bf;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --success: #22c55e;
  --error: #ef4444;
  --border: #2d3f56;
  --radius: 12px;
  --sidebar-width: 260px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* Admin panel */
.admin-create {
  margin-bottom: 2rem;
}

.admin-creds {
  margin-top: 1.25rem;
  padding: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.admin-creds__text {
  margin: 0 0 1rem;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: auto;
}

.admin-users {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.admin-user-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.admin-user-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.admin-user-card__meta {
  font-size: 0.8rem;
}

.admin-user-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.admin-user-card .badge {
  margin-left: 0.5rem;
  padding: 0.15rem 0.45rem;
  font-size: 0.7rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 4px;
}

.admin-user-card .badge--off {
  background: rgba(143, 163, 191, 0.15);
  color: var(--muted);
}

.btn--danger {
  color: var(--error);
  border-color: rgba(239, 68, 68, 0.35);
}

.btn--danger:hover {
  background: rgba(239, 68, 68, 0.12);
}

/* Login */
.login-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
  background: radial-gradient(ellipse at top, #1a2a44 0%, var(--bg) 55%);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.panel--center {
  width: min(100%, 420px);
}

.brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.brand__icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.brand__icon--sm {
  width: 40px;
  height: 40px;
  margin: 0;
  border-radius: 10px;
  font-size: 0.85rem;
  flex-shrink: 0;
}

h1, h2 {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.page-header {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.page-header h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.page-header .muted {
  margin: 0;
}

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

code {
  background: var(--surface-2);
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  font-size: 0.9em;
}

/* App layout */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.sidebar__title {
  display: block;
  font-size: 0.95rem;
  line-height: 1.3;
}

.sidebar__subtitle {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.sidebar__nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0 0.75rem;
  overflow-y: auto;
}

.sidebar__group-title {
  margin: 1rem 0 0.4rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.sidebar__group-title:first-child {
  margin-top: 0;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sidebar__link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar__link--active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar__icon {
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0.9;
}

.sidebar__footer {
  padding: 1rem 1.25rem 0;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.sidebar__user {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 2rem 2.5rem 3rem;
  background: radial-gradient(ellipse at top left, #1a2a44 0%, var(--bg) 50%);
  overflow-y: auto;
}

.panels {
  max-width: 720px;
}

.panel--wide {
  max-width: none;
}

.content:has(.panel--wide:not(.hidden)) .panels {
  max-width: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
}

.stat-card__value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

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

/* Поиск — карточка с горизонтальными группами полей */
.search-filters {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem 1rem;
  margin-bottom: 1.5rem;
}

.search-filters--compact {
  padding: 1rem 1.25rem;
}

.search-form {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  margin: 0;
}

.search-form--inline {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
}

.search-form__group {
  border: none;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.search-form__group legend {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.6rem;
  padding: 0;
  width: 100%;
}

.search-form__row {
  display: grid;
  gap: 0.75rem 1rem;
  align-items: end;
}

.search-form__row--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.search-form__row--docs {
  grid-template-columns: minmax(10rem, 1fr) minmax(11rem, 1.15fr) minmax(0, 2fr);
}

.search-form__span-2 {
  grid-column: auto;
}

.search-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.88rem;
  min-width: 0;
}

.search-form__grow {
  flex: 1;
  min-width: min(100%, 280px);
}

.search-form input[type="text"],
.search-form input[type="tel"],
.search-form input[type="password"] {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.search-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.search-form__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.85rem;
  margin-top: 0.15rem;
  border-top: 1px solid var(--border);
}

.search-form--inline .search-form__actions {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

@media (max-width: 960px) {
  .search-form__row--3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-form__row--docs {
    grid-template-columns: 1fr 1fr;
  }

  .search-form__row--docs .search-form__span-2 {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .search-filters {
    padding: 1rem;
  }

  .search-form__row--3,
  .search-form__row--docs {
    grid-template-columns: 1fr;
  }

  .search-form__actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .search-form__actions .btn {
    width: 100%;
    justify-content: center;
  }
}

.persons-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.person-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  background: var(--surface-2);
}

.person-card--clickable {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.person-card--clickable:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.person-detail__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.person-detail__header h2 {
  margin: 0;
  font-size: 1.15rem;
}

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

.person-detail__stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.65rem;
}

.person-detail__stat {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  background: var(--surface-2);
}

.person-detail__stat strong {
  display: block;
  font-size: 1.25rem;
  color: var(--accent);
}

.person-detail__stat span {
  font-size: 0.8rem;
  color: var(--muted);
}

.person-detail__block h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.person-detail__list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--text);
  line-height: 1.5;
}

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

.counterparty-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.counterparty-row:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.counterparty-row__count {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.person-detail__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.person-detail__note-hint {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
}

.person-note-input {
  width: 100%;
  min-height: 6rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  resize: vertical;
  box-sizing: border-box;
}

.person-detail__note-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.person-card__note-preview {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--accent);
  font-style: italic;
}

.counterparty-details {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
}

.counterparty-details__summary {
  padding: 0.6rem 0.85rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
  user-select: none;
}

.counterparty-details__summary::-webkit-details-marker {
  display: none;
}

.counterparty-details__summary::before {
  content: '▸ ';
  color: var(--accent);
}

.counterparty-details[open] .counterparty-details__summary::before {
  content: '▾ ';
}

.counterparty-details__body {
  padding: 0 0.65rem 0.65rem;
  border-top: 1px solid var(--border);
}

.btn--sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.person-card__name {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.person-card__meta {
  margin: 0 0 0.65rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

.person-card__cards-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.person-card__cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.card-chip {
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.card-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal__panel {
  position: relative;
  width: min(420px, 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  padding: 1.25rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.modal__header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.modal__close {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.modal__close:hover {
  color: var(--text);
}

.modal__subtitle {
  margin: 0 0 1rem;
  font-size: 0.9rem;
}

.modal__actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.modal__actions .btn {
  width: 100%;
  justify-content: center;
}

.search-form select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  min-width: 0;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.result-block h2 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th,
.data-table td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.empty-row {
  padding: 1rem;
  color: var(--muted);
  text-align: center;
}

.panel--graph {
  display: flex;
  flex-direction: column;
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
}

.legend-item::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-item--person::before { background: #3b82f6; }
.legend-item--counterpart::before { background: #ef4444; }
.legend-item--card::before { background: #8b5cf6; border-radius: 2px; }
.legend-item--phone::before { background: #14b8a6; }
.legend-item--operation::before { background: #f59e0b; }
.legend-item--operation-in::before { background: #22c55e; border-radius: 2px; }
.legend-item--operation-out::before { background: #ef4444; border-radius: 2px; }
.legend-item--merchant::before { background: #64748b; }

.graph-hint--layout {
  margin-bottom: 0.5rem;
}

.person-picks {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
  max-height: 200px;
  overflow-y: auto;
}

.person-pick {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.person-pick:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.graph-network {
  position: relative;
  flex: 1;
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #121a27;
  overflow: hidden;
}

.graph-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  margin: 0;
  pointer-events: none;
  z-index: 0;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
}

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

.form--inline {
  flex-direction: row;
  align-items: flex-end;
  flex-wrap: wrap;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.form label.grow { flex: 1; min-width: 220px; }

.form input[type="text"],
.form input[type="password"] {
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.file-drop:hover,
.file-drop:focus-within {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-drop input { display: none; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.1rem;
  font: inherit;
  cursor: pointer;
  font-weight: 600;
}

.btn--block {
  width: 100%;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}

.btn--primary:hover { background: var(--accent-hover); }

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

.btn--ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

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

.error {
  color: var(--error);
  font-size: 0.9rem;
  margin: 0;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  left: auto;
  transform: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.85rem 1.25rem;
  border-radius: 10px;
  max-width: min(420px, calc(100vw - 2rem));
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  z-index: 100;
}

.toast--ok { border-color: var(--success); }
.toast--err { border-color: var(--error); }

@media (max-width: 768px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
  }

  .sidebar__nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .sidebar__group-title {
    width: 100%;
  }

  .sidebar__link {
    width: auto;
    flex: 1 1 auto;
    min-width: calc(50% - 0.5rem);
    box-shadow: none;
  }

  .sidebar__link--active {
    box-shadow: inset 0 -3px 0 var(--accent);
  }

  .sidebar__footer {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
  }

  .sidebar__user {
    margin: 0;
    flex: 1;
  }

  .btn--block {
    width: auto;
  }

  .content {
    padding: 1.25rem 1rem 2rem;
  }

  .toast {
    left: 1rem;
    right: 1rem;
    max-width: none;
  }
}
