:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
.app-shell { display: flex; min-height: 100vh; overflow: hidden; }
.sidebar { width: 240px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-brand { height: 64px; display: flex; align-items: center; padding: 0 24px; border-bottom: 1px solid var(--border); font-weight: 800; font-size: 20px; color: var(--primary); }
.sidebar-nav { padding: 16px 0; overflow-y: auto; flex: 1; }
.sidebar-section { padding: 8px 0; border-top: 1px solid var(--border); }
.sidebar-item { display: flex; align-items: center; gap: 10px; padding: 11px 24px; color: #334155; font-weight: 600; border-left: 3px solid transparent; }
.sidebar-item:hover, .sidebar-item.active { background: #eff6ff; border-left-color: var(--primary); color: var(--primary); }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.header { height: 64px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; flex-shrink: 0; }
.header-left, .header-right { display: flex; align-items: center; gap: 16px; }
.content { flex: 1; overflow-y: auto; padding: 24px; }
.page-title { margin: 0 0 4px; font-size: 28px; line-height: 1.2; font-weight: 800; }
.page-subtitle { margin: 0; color: var(--muted); }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card-title { margin: 0 0 12px; font-size: 17px; font-weight: 800; }
.kpi-label { color: var(--muted); margin-bottom: 6px; }
.kpi-value { font-size: 26px; font-weight: 800; }
.kpi-foot { color: var(--muted); font-size: 12px; margin-top: 8px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-field { margin-bottom: 16px; }
.label { display: block; font-weight: 700; margin-bottom: 6px; color: #334155; }
.input, .select, .textarea { width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #fff; padding: 10px 12px; color: var(--text); outline: none; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.textarea { min-height: 96px; resize: vertical; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 10px; padding: 10px 14px; font-weight: 800; cursor: pointer; min-height: 40px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface-muted); color: #334155; border-color: var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger { background: var(--danger); color: #fff; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; color: var(--muted); background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table th, .table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8fafc; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 800; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-muted { background: #f1f5f9; color: #334155; }
.flash { border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; font-weight: 700; }
.flash-error { background: #fee2e2; color: #991b1b; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-info { background: #dbeafe; color: #1e40af; }
.toast-root { position: fixed; top: 16px; right: 16px; z-index: 50; display: grid; gap: 8px; }
.toast { background: #0f172a; color: #fff; padding: 12px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; }
.toast-danger { background: var(--danger); }
.toast-success { background: var(--success); }
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #f8fafc, #eff6ff); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px; box-shadow: 0 20px 60px rgba(15,23,42,.08); }
.auth-brand { color: var(--primary); font-size: 26px; font-weight: 900; margin-bottom: 8px; }
.muted { color: var(--muted); }
.money { font-variant-numeric: tabular-nums; font-weight: 800; }
.actions { display: flex; align-items: center; gap: 8px; }
@media (max-width: 1024px) {
  .grid-4, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s ease; }
  body.sidebar-collapsed .sidebar { transform: translateX(0); }
}
@media (max-width: 768px) {
  .content { padding: 16px; }
  .header { padding: 0 16px; }
  .grid-4, .grid-3, .grid-2, .form-row { grid-template-columns: 1fr; }
  .page-header, .toolbar { flex-direction: column; align-items: stretch; }
  .table-wrap { border: 0; background: transparent; }
  .table, .table thead, .table tbody, .table th, .table td, .table tr { display: block; }
  .table thead { display: none; }
  .table tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
  .table td { border-bottom: 1px solid var(--border); }
}
.inline-control { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.field-help { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.compact-card { padding: 16px; margin-bottom: 16px; }
.preview-list { display: grid; gap: 10px; margin: 0; }
.preview-list div { display: grid; grid-template-columns: 130px 1fr; gap: 12px; }
.preview-list dt { color: var(--muted); font-weight: 700; }
.preview-list dd { margin: 0; font-weight: 700; }
@media (max-width: 768px) {
  .inline-control { grid-template-columns: 1fr; }
  .preview-list div { grid-template-columns: 1fr; gap: 2px; }
}
.bank-combobox { position: relative; }
.dropdown-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% - 8px);
  z-index: 30;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, .14);
  padding: 6px;
}
.dropdown-item {
  display: grid;
  gap: 4px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.dropdown-item:hover,
.dropdown-item:focus {
  background: #eff6ff;
  outline: none;
}
.dropdown-empty {
  padding: 12px;
  color: var(--muted);
  font-weight: 700;
}
.bank-option-title {
  font-weight: 800;
  line-height: 1.3;
}
.bank-option-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
@media (max-width: 768px) {
  .dropdown-list { position: static; margin-top: 8px; }
}

/* Registration onboarding layout */
.auth-card-wide {
  max-width: 980px;
  padding: 32px;
}
.registration-title {
  margin-bottom: 20px;
}
.registration-form {
  display: grid;
  gap: 18px;
}
.registration-section {
  padding: 22px;
  margin-bottom: 0;
}
.registration-field-full {
  max-width: none;
}
.registration-inn-control {
  grid-template-columns: minmax(0, 1fr) auto;
}
.section-note {
  margin: -4px 0 16px;
  line-height: 1.5;
}
.company-preview-card,
.bank-preview-card {
  margin-top: 14px;
  background: #f8fafc;
}
.preview-list-wide div {
  grid-template-columns: 160px minmax(0, 1fr);
}
.preview-list dd {
  word-break: break-word;
}
.registration-docs-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.registration-submit {
  width: 100%;
  min-height: 48px;
  font-size: 15px;
}
.registration-login-link {
  margin-top: 18px;
  text-align: center;
}
.field-help-danger {
  color: var(--danger);
  font-weight: 700;
}
.field-help-success {
  color: #047857;
  font-weight: 700;
}
.bank-combobox {
  position: static;
}
.combobox-control {
  position: relative;
}
.combobox-control .dropdown-list {
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  width: 100%;
  min-width: min(760px, calc(100vw - 48px));
  max-height: 340px;
  padding: 8px;
}
.bank-option-title {
  font-weight: 600;
  font-size: 14px;
}
.bank-option-meta {
  font-weight: 400;
  font-size: 12px;
}
.dropdown-empty {
  font-weight: 500;
}

@media (min-width: 360px) {
  .auth-page { padding: 16px; }
  .auth-card-wide { padding: 20px; }
}
@media (min-width: 480px) {
  .auth-page { padding: 20px; }
  .auth-card-wide { padding: 24px; }
}
@media (min-width: 640px) {
  .auth-card-wide { max-width: 620px; }
}
@media (min-width: 768px) {
  .auth-card-wide { max-width: 720px; }
}
@media (min-width: 1024px) {
  .auth-card-wide { max-width: 920px; }
}
@media (min-width: 1280px) {
  .auth-card-wide { max-width: 980px; }
}
@media (min-width: 1536px) {
  .auth-card-wide { max-width: 1040px; }
}
@media (min-width: 1920px) {
  .auth-card-wide { max-width: 1120px; }
}
@media (max-width: 767px) {
  .auth-page {
    align-items: start;
    place-items: start center;
    padding: 12px;
  }
  .auth-card,
  .auth-card-wide {
    border-radius: 14px;
    padding: 18px;
  }
  .registration-section {
    padding: 16px;
  }
  .registration-inn-control {
    grid-template-columns: 1fr;
  }
  .registration-docs-grid {
    grid-template-columns: 1fr;
  }
  .preview-list-wide div {
    grid-template-columns: 1fr;
  }
  .combobox-control .dropdown-list {
    position: absolute;
    min-width: 100%;
    max-width: calc(100vw - 60px);
  }
}

/* Production form controls */
.input-invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .10) !important;
}
.input-valid {
  border-color: var(--success) !important;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, .10) !important;
}
.combobox-control .dropdown-list {
  top: calc(100% + 2px);
  width: 100%;
  min-width: 100%;
  max-height: 420px;
  padding: 6px;
}
.dropdown-item.bank-option {
  grid-template-columns: minmax(0, 1fr);
  gap: 3px;
  padding: 9px 10px;
}
.bank-option-title {
  font-weight: 500;
  font-size: 13px;
  line-height: 1.35;
  white-space: normal;
}
.bank-option-meta {
  font-weight: 400;
  font-size: 12px;
  line-height: 1.35;
  white-space: normal;
}
.dropdown-empty {
  font-weight: 400;
}
@media (min-width: 1024px) {
  .combobox-control .dropdown-list {
    min-width: min(860px, calc(100vw - 96px));
  }
}
@media (max-width: 767px) {
  .combobox-control .dropdown-list {
    top: calc(100% + 2px);
    max-width: calc(100vw - 60px);
    max-height: 360px;
  }
}

/* Registration inline feedback and password controls */
.form-status {
  border-radius: 10px;
  padding: 11px 13px;
  margin-bottom: 16px;
  font-weight: 700;
  line-height: 1.45;
}
.form-status-compact {
  margin-top: 8px;
  margin-bottom: 0;
  font-size: 13px;
}
.form-status-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}
.form-status-danger {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}
.form-status-info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}
.form-status-warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}
.section-mini-title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 800;
  color: #334155;
}
.company-options {
  margin-top: 14px;
  margin-bottom: 14px;
}
.company-options-list {
  display: grid;
  gap: 10px;
}
.company-option {
  display: grid;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 13px 14px;
  color: var(--text);
  cursor: pointer;
}
.company-option:hover,
.company-option:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .10);
  outline: none;
}
.company-option-selected {
  border-color: var(--primary);
  background: #eff6ff;
}
.company-option-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.company-option-name {
  font-weight: 700;
  line-height: 1.35;
}
.company-option-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.company-option-address {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.password-control {
  position: relative;
}
.password-control .input {
  padding-right: 92px;
}
.password-toggle {
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: #f1f5f9;
  color: #334155;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.password-toggle:hover,
.password-toggle:focus {
  background: #e2e8f0;
  outline: none;
}
.password-rules {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}
.password-rules li.password-rule-ok {
  color: #047857;
  font-weight: 700;
}
.password-strength {
  height: 6px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
  margin-top: 8px;
}
.password-strength-bar {
  display: block;
  width: 0;
  height: 100%;
  transition: width .2s ease;
}
.password-strength-bar.weak {
  width: 25%;
  background: var(--danger);
}
.password-strength-bar.medium {
  width: 50%;
  background: var(--warning);
}
.password-strength-bar.good {
  width: 75%;
  background: var(--primary);
}
.password-strength-bar.strong {
  width: 100%;
  background: var(--success);
}
@media (max-width: 767px) {
  .company-option-head {
    display: grid;
  }
  .password-control .input {
    padding-right: 88px;
  }
}

/* Ownership transfer */
.ownership-grid { align-items: stretch; }
.ownership-card-highlight { border-color: #bfdbfe; box-shadow: 0 10px 30px rgba(37, 99, 235, .08); }
.ownership-request-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; background: #f8fafc; }
.ownership-request-card + .ownership-request-card { margin-top: 14px; }

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(720px, calc(100vw - 32px));
  width: 100%;
}
.modal::backdrop { background: rgba(15, 23, 42, .45); }
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--text);
}
.checkbox-stack {
  display: flex;
  flex-direction: column;
  justify-content: end;
  gap: 10px;
}

.inline-role-form {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 230px;
}
.select-compact {
  min-width: 140px;
  padding: 8px 10px;
}
.btn-compact {
  padding: 8px 12px;
  min-height: auto;
}
