:root {
  color-scheme: light;
  --ink: #172233;
  --ink-soft: #465469;
  --muted: #768397;
  --line: #dce2ea;
  --line-strong: #c4ceda;
  --surface: #ffffff;
  --canvas: #f3f5f8;
  --blue: #2457d6;
  --blue-dark: #1944b4;
  --blue-pale: #edf2ff;
  --green: #1d7a52;
  --green-pale: #eaf7f0;
  --amber: #a45c07;
  --amber-pale: #fff4df;
  --red: #b23a3a;
  --red-pale: #fff0ef;
  --shadow: 0 18px 55px rgba(25, 39, 59, .08);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(36, 87, 214, .025) 1px, transparent 1px) 0 0 / 34px 34px,
    var(--canvas);
  font-family: "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }
.skip-link { position: fixed; z-index: 100; left: 12px; top: -60px; padding: 8px 12px; color: white; background: var(--ink); }
.skip-link:focus { top: 12px; }

.app-header {
  position: sticky;
  z-index: 30;
  top: 0;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 28px;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
  color: white;
  background: #172233;
}
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 31px;
  height: 31px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .55);
  color: white;
  background: var(--blue);
  font-size: 15px;
  font-weight: 800;
}
.brand-mark i { display: none; }
.brand strong, .brand small { display: block; line-height: 1.1; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 3px; color: #b9c5d5; font-size: 10px; letter-spacing: .06em; }
.account-actions { display: flex; align-items: center; gap: 12px; }
.private-badge { display: inline-flex; align-items: center; gap: 7px; color: #dbe3ef; font-size: 12px; }
.private-badge i { width: 7px; height: 7px; border-radius: 50%; background: #58c997; box-shadow: 0 0 0 3px rgba(88, 201, 151, .15); }
.header-button { padding: 6px 10px; border: 1px solid rgba(255,255,255,.25); color: white; background: transparent; cursor: pointer; }
.header-button:hover { background: rgba(255,255,255,.08); }

.workspace { width: min(1480px, calc(100% - 40px)); margin: 0 auto; padding: 30px 0 70px; }
.summary {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(520px, 1.5fr);
  align-items: stretch;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  box-shadow: var(--shadow);
}
.summary-title { display: flex; flex-direction: column; justify-content: center; padding: 21px 25px; border-right: 1px solid var(--line); }
.summary h1 { margin: 0; font-size: 27px; letter-spacing: -.025em; }
#sherlock-usage { margin-top: 5px; color: var(--muted); font-size: 12px; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0; }
.metrics div { padding: 18px 20px; border-right: 1px solid var(--line); }
.metrics div:last-child { border-right: 0; }
.metrics dt { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.metrics dd { margin: 2px 0 0; font-variant-numeric: tabular-nums; font-size: 29px; font-weight: 720; letter-spacing: -.03em; }

.taskbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 680;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { opacity: .5; cursor: not-allowed; }
.button-primary { color: white; background: var(--blue); }
.button-primary:hover:not(:disabled) { background: var(--blue-dark); }
.button-secondary { border-color: var(--line-strong); color: var(--ink); background: white; }
.button-secondary:hover:not(:disabled) { border-color: var(--blue); background: var(--blue-pale); }
.button-danger { border-color: #efc2bf; color: var(--red); background: var(--red-pale); }
.button-wide { width: 100%; }
.file-button { position: relative; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-button.is-loading { opacity: .55; pointer-events: none; }
.text-button { padding: 5px; border: 0; color: var(--blue); background: transparent; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.text-link { color: var(--blue); font-size: 12px; font-weight: 700; text-underline-offset: 3px; }
.taskbar-spacer { flex: 1; }
.taskbar-divider { width: 1px; height: 25px; margin: 0 3px; background: var(--line); }
#selected-count { min-width: 20px; padding: 1px 5px; border-radius: 4px; color: white; background: var(--ink-soft); font-size: 11px; }

.batch-panel { margin-bottom: 14px; padding: 14px 16px; border: 1px solid #b7c8f4; border-left: 4px solid var(--blue); background: var(--blue-pale); }
.batch-line { display: flex; justify-content: space-between; gap: 20px; }
.batch-line strong { font-size: 13px; }
.batch-line span { color: var(--ink-soft); font-variant-numeric: tabular-nums; font-size: 12px; }
.progress-track { height: 6px; margin-top: 10px; overflow: hidden; background: #d7e1fa; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--blue); transition: width .25s ease; }
.batch-panel p { margin: 7px 0 0; color: var(--ink-soft); font-size: 12px; }
.system-warning { margin-bottom: 14px; padding: 11px 14px; border-left: 4px solid var(--amber); color: #7a460a; background: var(--amber-pale); }

.registry { border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.registry-head { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.select-all { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-soft); cursor: pointer; font-size: 12px; font-weight: 650; }
input[type="checkbox"] { width: 17px; height: 17px; margin: 0; accent-color: var(--blue); }
.registry-tools { width: min(720px, 68%); display: flex; align-items: flex-end; gap: 9px; }
.filter-field { min-height: 42px; flex: 1; display: flex; align-items: center; gap: 7px; padding: 0 11px; border: 1px solid var(--line-strong); background: #f9fafc; }
.filter-field:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(36,87,214,.1); }
.filter-field span { color: var(--muted); font-size: 21px; line-height: 1; }
.filter-field input { min-width: 0; width: 100%; height: 40px; border: 0; outline: 0; color: var(--ink); background: transparent; }
.sort-field { width: 210px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.sort-field span { display: block; margin-bottom: 3px; }
.sort-field select { width: 100%; min-height: 30px; padding: 4px 7px; border: 1px solid var(--line-strong); color: var(--ink); background: white; font-size: 12px; text-transform: none; }

.organization-list { display: grid; }
.org-card {
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(260px, 1.4fr) minmax(260px, 1fr) minmax(190px, .7fr);
  grid-template-areas:
    "selection identity contacts workflow"
    ". actions actions actions";
  column-gap: 18px;
  padding: 18px 20px 13px 15px;
  border-bottom: 1px solid var(--line);
  box-shadow: inset 4px 0 0 var(--line-strong);
}
.org-card:last-child { border-bottom: 0; }
.org-card:hover, .org-card:focus-within { background: #fbfcff; }
.org-card.status-review { box-shadow: inset 4px 0 0 var(--blue); }
.org-card.status-searching { box-shadow: inset 4px 0 0 #2c7e98; }
.org-card.status-empty { box-shadow: inset 4px 0 0 #cf8b26; }
.org-card.status-error { box-shadow: inset 4px 0 0 var(--red); }
.card-selection { grid-area: selection; padding-top: 3px; text-align: center; }
.card-identity { grid-area: identity; min-width: 0; }
.identity-top { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.data-status { padding: 3px 6px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink-soft); background: #f7f9fb; font-size: 10px; font-weight: 750; letter-spacing: .03em; text-transform: uppercase; }
.data-status.status-review { border-color: #aac0f5; color: var(--blue-dark); background: var(--blue-pale); }
.data-status.status-searching { border-color: #a8d4df; color: #176179; background: #ebf8fb; }
.data-status.status-empty { border-color: #ecd09f; color: var(--amber); background: var(--amber-pale); }
.data-status.status-error { border-color: #ebbbb8; color: var(--red); background: var(--red-pale); }
.inn { color: var(--muted); font-family: Consolas, monospace; font-size: 11px; }
.org-title { margin: 9px 0 0; font-size: 16px; line-height: 1.35; overflow-wrap: anywhere; }
.org-address { margin: 7px 0 0; color: var(--ink-soft); font-size: 12px; overflow-wrap: anywhere; }
.org-source { margin: 8px 0 0; color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.card-contacts { grid-area: contacts; min-width: 0; }
.section-label { margin: 0 0 9px; color: var(--muted); font-size: 10px; letter-spacing: .07em; text-transform: uppercase; }
.contact-group { display: grid; grid-template-columns: 53px minmax(0, 1fr); gap: 8px; margin-bottom: 7px; }
.contact-label { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.contact-values { min-width: 0; display: grid; gap: 3px; }
.contact-link { color: var(--ink); font-size: 12px; font-weight: 650; overflow-wrap: anywhere; text-decoration-color: #a7b7cc; text-underline-offset: 3px; }
.contact-link:hover { color: var(--blue); }
.muted { color: #9aa5b3; }
.contact-person { margin: 9px 0; padding: 8px 9px; border-left: 2px solid var(--blue); background: #f7f9fd; }
.contact-person strong, .contact-person span { display: block; overflow-wrap: anywhere; }
.contact-person strong { font-size: 12px; }
.contact-person span { margin-top: 2px; color: var(--muted); font-size: 10px; }
.checked-at { margin: 9px 0 0; color: var(--muted); font-size: 10px; }
.inline-error { margin: 9px 0 0; color: var(--red); font-size: 11px; }
.card-workflow { grid-area: workflow; min-width: 0; }
.workflow-status, .workflow-note { width: 100%; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--ink); background: white; }
.workflow-status { min-height: 36px; padding: 6px 8px; }
.workflow-note { min-height: 68px; margin-top: 7px; padding: 8px; line-height: 1.35; resize: vertical; }
.workflow-status:focus, .workflow-note:focus { border-color: var(--blue); outline: 0; box-shadow: 0 0 0 3px rgba(36,87,214,.1); }
.save-state { display: block; min-height: 16px; margin-top: 4px; color: var(--muted); font-size: 10px; }
.save-state.is-saving { color: var(--amber); }
.save-state.is-saved { color: var(--green); }
.save-state.is-error { color: var(--red); }
.card-actions { grid-area: actions; display: flex; align-items: center; gap: 7px; margin-top: 12px; padding-top: 10px; border-top: 1px solid #edf0f4; }
.card-actions .button { min-height: 32px; padding: 5px 9px; font-size: 11px; }
.card-search { border-color: #b4c5ef; color: var(--blue-dark); background: var(--blue-pale); }
.card-search:hover:not(:disabled) { border-color: var(--blue); }
.report-button { border-color: transparent; color: var(--ink-soft); background: transparent; }
.report-button:hover:not(:disabled), .report-button.is-active { color: var(--red); background: var(--red-pale); }
.delete-button { margin-left: auto; border-color: transparent; color: var(--red); background: transparent; }
.delete-button:hover:not(:disabled) { background: var(--red-pale); }

.empty-state { padding: 76px 20px; color: var(--muted); text-align: center; }
.empty-state > span { display: block; color: var(--blue); font-size: 43px; line-height: 1; }
.empty-state strong { display: block; margin-top: 9px; color: var(--ink); font-size: 17px; }
.empty-state p { margin: 4px 0 0; }
.list-footer { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 16px; border-top: 1px solid var(--line); background: #fafbfd; }
.list-footer p { margin: 0; color: var(--muted); font-size: 11px; }
.pager { display: flex; gap: 7px; }
.pager .button { min-height: 33px; padding: 5px 10px; font-size: 11px; }

.modal { width: min(520px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 10px; color: var(--ink); background: white; box-shadow: 0 25px 80px rgba(14, 24, 39, .28); }
.modal::backdrop { background: rgba(17, 28, 43, .58); backdrop-filter: blur(2px); }
.modal form, .help-content { display: grid; gap: 14px; padding: 24px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.modal h2 { margin: 0; font-size: 21px; }
.icon-button { width: 34px; height: 34px; border: 1px solid var(--line-strong); border-radius: 50%; color: var(--ink); background: white; cursor: pointer; font-size: 22px; line-height: 1; }
.modal label { color: var(--ink-soft); font-size: 12px; font-weight: 650; }
.modal input, .modal textarea { width: 100%; margin-top: 5px; padding: 9px 10px; border: 1px solid var(--line-strong); border-radius: 5px; }
.modal input:focus, .modal textarea:focus { border-color: var(--blue); outline: 0; box-shadow: 0 0 0 3px rgba(36,87,214,.1); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.help-content > p { margin: 0; color: var(--ink-soft); font-size: 13px; }
.file-example { overflow: hidden; border: 1px solid var(--line); font-size: 11px; }
.file-example [role="row"] { display: grid; grid-template-columns: 125px 1fr 1.4fr; }
.file-example [role="row"] + [role="row"] { border-top: 1px solid var(--line); }
.file-example span, .file-example strong { min-width: 0; padding: 8px 9px; overflow-wrap: anywhere; }
.file-example strong { color: white; background: var(--ink); }
.file-example span + span, .file-example strong + strong { border-left: 1px solid var(--line); }

.toast-region { position: fixed; z-index: 90; right: 18px; bottom: 18px; width: min(390px, calc(100% - 36px)); display: grid; gap: 8px; }
.toast { padding: 12px 14px; border-left: 4px solid #58c997; color: white; background: var(--ink); box-shadow: 0 14px 38px rgba(17,31,48,.25); font-size: 12px; animation: toast-in .18s ease-out; }
.toast.is-error { border-left-color: #ef7c75; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.auth-page { min-height: 100dvh; }
.auth-shell { min-height: 100dvh; display: grid; place-items: center; padding: 22px; }
.auth-card { width: min(430px, 100%); padding: 34px; border: 1px solid var(--line); border-top: 4px solid var(--blue); background: white; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 30px; }
.auth-brand .brand-mark { color: white; }
.auth-brand strong, .auth-brand small { display: block; }
.auth-brand small { color: var(--muted); font-size: 11px; }
.auth-card .eyebrow { margin: 0 0 5px; color: var(--blue); font-size: 10px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.auth-card h1 { margin: 0; font-size: 30px; }
.auth-copy { margin: 11px 0 20px; color: var(--muted); font-size: 13px; }
.auth-form { display: grid; gap: 14px; }
.auth-form label { color: var(--ink-soft); font-size: 12px; font-weight: 650; }
.auth-form input { width: 100%; margin-top: 5px; padding: 10px; border: 1px solid var(--line-strong); border-radius: 5px; }
.auth-error { padding: 9px 11px; border-left: 4px solid var(--red); color: var(--red); background: var(--red-pale); font-size: 12px; }
.auth-footnote { margin: 19px 0 0; color: var(--muted); font-size: 10px; text-align: center; }

@media (max-width: 1080px) {
  .summary { grid-template-columns: 1fr; }
  .summary-title { border-right: 0; border-bottom: 1px solid var(--line); }
  .org-card {
    grid-template-columns: 30px minmax(0, 1.3fr) minmax(0, 1fr);
    grid-template-areas:
      "selection identity contacts"
      ". workflow contacts"
      ". actions actions";
  }
  .card-workflow { margin-top: 16px; }
}

@media (max-width: 760px) {
  .app-header { min-height: 58px; padding: 0 14px; }
  .brand small { display: none; }
  .private-badge { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .workspace { width: calc(100% - 18px); padding-top: 14px; }
  .summary-title { padding: 15px 16px; }
  .summary h1 { font-size: 22px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metrics div { padding: 13px 15px; border-bottom: 1px solid var(--line); }
  .metrics div:nth-child(2) { border-right: 0; }
  .metrics div:nth-last-child(-n+2) { border-bottom: 0; }
  .metrics dd { font-size: 25px; }
  .taskbar { align-items: stretch; }
  .taskbar .button { flex: 1 1 calc(50% - 5px); }
  .taskbar-divider { display: none; }
  .taskbar-spacer { flex-basis: 100%; }
  .registry-head { align-items: stretch; flex-direction: column; }
  .registry-tools { width: 100%; flex-direction: column; align-items: stretch; }
  .sort-field { width: 100%; }
  .org-card {
    grid-template-columns: 23px minmax(0, 1fr);
    grid-template-areas:
      "selection identity"
      ". contacts"
      ". workflow"
      ". actions";
    row-gap: 17px;
    padding: 17px 14px 13px 10px;
  }
  .card-workflow { margin-top: 0; }
  .card-actions { flex-wrap: wrap; margin-top: 0; }
  .delete-button { margin-left: 0; }
  .list-footer { align-items: flex-start; flex-direction: column; }
  .file-example { overflow-x: auto; }
  .file-example [role="row"] { min-width: 590px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
