:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --text: #17202a;
  --muted: #66717e;
  --line: #d8dee5;
  --line-strong: #bcc6d0;
  --accent: #087f5b;
  --accent-hover: #066749;
  --accent-soft: #e5f5ef;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --focus: #1c7ed6;
  --shadow: 0 12px 32px rgba(26, 38, 52, 0.14);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.muted { color: var(--muted); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  gap: 10px;
}
.login-panel h1 { margin: 2px 0 16px; font-size: 24px; }
.login-panel label { font-size: 12px; font-weight: 700; color: var(--muted); }
.login-panel input, .filter-row input, .filter-row select, .field-control input, .field-control select, .field-control textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus, button:focus-visible { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(28, 126, 214, 0.16); outline: none; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center;
  background: #17202a; color: #fff; border-radius: 6px; font-weight: 800;
}
.brand-mark.small { width: 34px; height: 34px; font-size: 12px; }
.form-error { min-height: 20px; color: var(--danger); margin: 2px 0 0; }

.workspace { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  min-height: 64px; padding: 10px 18px; background: var(--surface);
  border-bottom: 1px solid var(--line); display: flex; align-items: center;
  justify-content: space-between; gap: 16px;
}
.brand-line, .top-actions, .filter-row, .footer-right { display: flex; align-items: center; gap: 10px; }
.brand-line h1 { margin: 0; font-size: 18px; line-height: 1.2; }
.brand-line p { margin: 3px 0 0; font-size: 12px; }
.user-label { color: var(--muted); font-size: 13px; }
.button {
  min-height: 36px; padding: 7px 12px; border: 1px solid var(--line-strong);
  border-radius: 6px; color: var(--text); background: var(--surface);
  white-space: nowrap;
}
.button:hover { background: #eef1f4; }
.button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.button.primary:hover { background: var(--accent-hover); }
.button.danger { color: var(--danger); border-color: #e5aaa4; background: var(--danger-soft); }
.button:disabled { opacity: .45; cursor: default; }

.toolbar {
  padding: 10px 18px; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.tabs { display: inline-flex; gap: 2px; padding: 3px; background: #e9edf1; border-radius: 6px; }
.tab { min-width: 86px; border: 0; border-radius: 4px; padding: 7px 12px; background: transparent; color: var(--muted); font-weight: 700; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(26, 38, 52, .14); }
.filter-row { min-width: 0; }
.search-field { width: min(360px, 34vw); }
.filter-row select { width: 150px; }

.viewbar {
  min-height: 52px; padding: 8px 18px; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; background: #f9fafb; border-bottom: 1px solid var(--line);
}
.view-switch {
  display: inline-flex; align-items: center; gap: 2px; padding: 3px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--surface);
}
.view-option {
  min-height: 32px; padding: 6px 12px; border: 0; border-radius: 4px; background: transparent;
  color: var(--muted); font-weight: 700; white-space: nowrap;
}
.view-option span {
  display: inline-grid; width: 19px; height: 19px; margin-right: 5px; place-items: center;
  border: 1px solid #c5cdd5; border-radius: 50%; color: #56616d; font-size: 11px;
}
.view-option.active { background: #25323a; color: #fff; }
.view-option.active span { border-color: #8fd0be; background: #dff4ec; color: #145f4e; }

.table-section { padding: 12px 18px 18px; min-height: 0; flex: 1; display: flex; flex-direction: column; }
.table-meta { min-height: 30px; display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.table-wrap {
  position: relative; flex: 1; min-height: 420px; max-height: calc(100vh - 205px);
  overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
}
table { border-collapse: separate; border-spacing: 0; min-width: max-content; width: 100%; font-size: 12px; }
th, td {
  height: 38px; max-width: 230px; padding: 6px 8px; border-right: 1px solid rgba(23, 32, 42, .12);
  border-bottom: 1px solid rgba(23, 32, 42, .12); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; vertical-align: middle;
}
th {
  height: 42px; position: sticky; top: 0; z-index: 5; background: #29333d; color: #fff;
  font-weight: 700; text-align: left;
}
tbody tr { cursor: pointer; }
tbody tr:hover td { box-shadow: inset 0 0 0 9999px rgba(255, 255, 255, .18); }
th.number, td.number { width: 50px; min-width: 50px; max-width: 50px; position: sticky; left: 0; z-index: 4; text-align: center; }
th.number { z-index: 7; }
th.fio, td.fio { width: 220px; min-width: 220px; max-width: 220px; position: sticky; left: 50px; z-index: 3; }
th.fio { z-index: 6; }
td.number, td.fio { background: var(--surface); }
td.money { text-align: right; font-variant-numeric: tabular-nums; }
td.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 800; letter-spacing: 0; }
.cell-button { border: 0; background: transparent; padding: 2px 3px; color: inherit; font: inherit; cursor: copy; }
.empty-state { position: absolute; inset: 42px 0 0; display: grid; place-items: center; color: var(--muted); }

.compact-table { min-width: 1120px; table-layout: fixed; }
.compact-table th, .compact-table td { white-space: normal; }
.compact-table th { height: 38px; padding: 6px 10px; color: #dfe5e8; background: #25323a; font-size: 11px; text-transform: uppercase; }
.compact-table td { height: 94px; padding: 9px 10px; background: var(--surface); vertical-align: top; }
.compact-table tbody tr td:first-child { border-left: 4px solid var(--row-accent); }
.compact-table th.number, .compact-table td.number { width: 48px; min-width: 48px; max-width: 48px; }
.compact-table th.compact-profile, .compact-table td.compact-profile {
  width: 190px; min-width: 190px; max-width: 190px; position: sticky; left: 48px; z-index: 3;
}
.compact-table th.compact-profile { z-index: 6; }
.compact-table th.compact-access, .compact-table td.compact-access { width: 165px; }
.profile-name { display: block; margin-bottom: 8px; font-size: 14px; line-height: 1.2; overflow-wrap: anywhere; }
.profile-meta { display: block; color: var(--muted); font-size: 11px; line-height: 1.4; overflow-wrap: anywhere; }
.access-stack { display: grid; align-content: start; gap: 8px; }
.access-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.quick-copy {
  width: fit-content; max-width: 100%; padding: 0; overflow: hidden; border: 0; background: transparent;
  color: #1d596c; font-size: 12px; font-weight: 700; text-align: left; text-overflow: ellipsis; white-space: nowrap;
}
.mini-action {
  min-height: 25px; padding: 3px 7px; border: 1px solid #cbd4da; border-radius: 4px;
  background: #f4f7f8; color: #43505a; font-size: 10px; font-weight: 800;
}
.code-action { color: #0a6754; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.market-summary {
  min-height: 74px; padding-left: 9px; border-left: 4px solid var(--market-color); display: grid;
  grid-template-rows: auto 1fr auto; gap: 5px;
}
.market-heading, .market-money, .market-status, .board-market, .card-topline {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.market-heading strong { font-size: 12px; }
.container-label { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 10px; }
.container-label i, .board-market i { width: 9px; height: 9px; border: 1px solid rgba(23, 32, 42, .28); border-radius: 2px; flex: 0 0 auto; }
.market-money { align-items: baseline; }
.market-money strong { font-size: 14px; font-variant-numeric: tabular-nums; }
.market-money span { color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.status-badge {
  display: inline-flex; align-items: center; width: fit-content; min-height: 20px; padding: 2px 6px;
  border: 1px solid #d2d8de; border-radius: 7px; background: #f3f5f7; color: #68737e;
  font-size: 9px; font-weight: 800; line-height: 1.2; white-space: nowrap;
}
.status-badge.success { border-color: #a9d8c9; background: #e8f6f1; color: #086b52; }
.status-badge.danger { border-color: #efb7b1; background: #fff0ee; color: #a82a20; }
.status-badge.warning { border-color: #e5c78d; background: #fff6df; color: #77510c; }
.status-badge.info { border-color: #abcddd; background: #ebf6fa; color: #1d607d; }
.status-badge.finished { border-color: #bdc5cb; background: #e7eaed; color: #4e5962; }
.stage-cell { width: 168px; }
.stage-strip { display: grid; grid-template-columns: repeat(5, minmax(42px, 1fr)); gap: 4px; min-width: 270px; }
.stage-strip.condensed { grid-template-columns: repeat(5, minmax(23px, 1fr)); min-width: 0; }
.stage-strip span { display: grid; justify-items: center; gap: 4px; min-width: 0; color: #8a949d; }
.stage-strip i { width: 9px; height: 9px; border: 2px solid #bcc5cc; border-radius: 50%; background: var(--surface); }
.stage-strip b { max-width: 100%; overflow: hidden; font-size: 9px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.stage-strip span.done { color: #0a6c56; }
.stage-strip span.done i { border-color: #0c8064; background: #0c8064; box-shadow: 0 0 0 2px #d9f0e8; }
.compact-result { display: grid; align-content: start; gap: 6px; min-width: 135px; }
.compact-result > strong { font-size: 14px; font-variant-numeric: tabular-nums; }
.compact-result > span:not(.status-badge) { color: var(--muted); font-size: 10px; }

.board-wrap {
  position: relative; flex: 1; min-height: 420px; max-height: calc(100vh - 257px); overflow: auto;
  border: 1px solid var(--line); border-radius: 6px; background: #e7ecee;
}
.workflow-board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); min-width: 1120px; min-height: 100%; }
.board-column { min-width: 0; border-right: 1px solid #cbd3d7; }
.board-column:last-child { border-right: 0; }
.board-column > header {
  position: sticky; top: 0; z-index: 4; min-height: 44px; padding: 9px 11px; display: flex;
  align-items: center; justify-content: space-between; border-bottom: 1px solid #cbd3d7; background: #f7f9f9;
}
.board-column > header h2 { margin: 0; font-size: 12px; }
.board-column > header span { min-width: 22px; padding: 2px 6px; border-radius: 7px; background: #e1e7e9; color: #58636c; font-size: 10px; text-align: center; }
.board-list { display: grid; align-content: start; gap: 8px; padding: 8px; }
.profile-card {
  min-height: 150px; padding: 10px; border: 1px solid #ccd4d8; border-radius: 6px; background: var(--surface);
  box-shadow: 0 1px 2px rgba(23, 32, 42, .06); cursor: pointer;
}
.profile-card:hover, .profile-card:focus-visible { border-color: #6f9d91; box-shadow: 0 3px 10px rgba(23, 32, 42, .1); outline: none; }
.card-topline > span:first-child { color: var(--muted); font-size: 10px; font-weight: 800; }
.profile-card h3 { margin: 9px 0 3px; font-size: 13px; line-height: 1.25; overflow-wrap: anywhere; }
.profile-card p { margin: 0 0 10px; color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.board-markets { margin-bottom: 11px; display: grid; gap: 5px; }
.board-market { min-height: 23px; padding-top: 4px; border-top: 1px solid #edf0f2; }
.board-market span { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; }
.board-market strong { font-size: 11px; font-variant-numeric: tabular-nums; }
.board-empty-state { position: absolute; inset: 44px 0 0; display: grid; place-items: center; color: var(--muted); }

.drawer-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(23, 32, 42, .28); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 21; width: min(620px, 100vw);
  background: var(--surface-raised); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  transform: translateX(102%); transition: transform .18s ease;
}
.drawer.open { transform: translateX(0); }
.drawer form { height: 100%; display: flex; flex-direction: column; }
.drawer-header { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.drawer-header h2 { margin: 2px 0 0; font-size: 20px; overflow-wrap: anywhere; }
.eyebrow { color: var(--muted); font-size: 12px; font-weight: 700; }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); font-size: 25px; line-height: 1; }
.drawer-fields { padding: 4px 18px 18px; overflow: auto; flex: 1; }
.field-section { padding: 14px 0 6px; border-bottom: 1px solid var(--line); }
.field-section:last-child { border-bottom: 0; }
.field-section h3, .audit-section h3 { margin: 0 0 12px; font-size: 14px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field-control.full { grid-column: 1 / -1; }
.field-control label { display: block; margin: 0 0 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.field-control textarea { min-height: 100px; resize: vertical; }
.field-control input[readonly] { background: #edf1f4; color: #43505c; }
.input-with-action { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.input-with-action input { border-radius: 6px 0 0 6px; }
.input-with-action button { border: 1px solid var(--line-strong); border-left: 0; border-radius: 0 6px 6px 0; background: #eef1f4; padding: 0 10px; }
.checkbox-field { min-height: 38px; display: flex; align-items: center; gap: 8px; }
.checkbox-field input { width: 16px; height: 16px; }
.audit-section { padding: 12px 18px; max-height: 150px; overflow: auto; border-top: 1px solid var(--line); background: #f7f8fa; }
.audit-list { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.audit-entry { display: flex; justify-content: space-between; gap: 12px; }
.drawer-footer { min-height: 66px; padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 50; transform: translateX(-50%); max-width: min(560px, calc(100vw - 24px)); background: #17202a; color: #fff; padding: 10px 14px; border-radius: 6px; box-shadow: var(--shadow); }

@media (max-width: 820px) {
  .topbar, .toolbar, .viewbar { align-items: stretch; flex-direction: column; }
  .top-actions, .filter-row { width: 100%; flex-wrap: wrap; }
  .user-label { flex: 1; }
  .search-field { width: 100%; flex: 1 1 100%; }
  .filter-row select { width: 100%; }
  .filter-row label:not(.search-field) { flex: 1; }
  .table-section { padding: 10px 8px; }
  .view-switch { width: 100%; }
  .view-option { flex: 1; padding-inline: 7px; }
  .table-wrap, .board-wrap { max-height: calc(100vh - 350px); min-height: 360px; }
  th.fio, td.fio { width: 170px; min-width: 170px; max-width: 170px; }
  .compact-table { min-width: 1030px; }
  .compact-table th.compact-profile, .compact-table td.compact-profile { width: 168px; min-width: 168px; max-width: 168px; }
  .workflow-board { grid-template-columns: repeat(5, 240px); min-width: 1200px; }
  .field-grid { grid-template-columns: 1fr; }
  .field-control.full { grid-column: auto; }
  .drawer-footer { align-items: stretch; }
  .footer-right { align-items: stretch; flex-direction: column; }
}
