:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #637083;
  --line: #d9e0e7;
  --blue: #2364aa;
  --green: #1f7a4d;
  --red: #b42318;
  --amber: #996a13;
  --ink: #0f1720;
  --shadow: 0 1px 2px rgba(15, 23, 32, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  padding: 0 12px;
  font-weight: 650;
}

button:hover {
  filter: brightness(0.95);
}

button.secondary {
  background: #fff;
  color: var(--blue);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 36px;
  padding: 7px 9px;
}

textarea {
  min-height: 116px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}

input[type="file"] {
  padding: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

td small {
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 18px 24px;
  background: #111820;
  color: #fff;
  border-bottom: 1px solid #0b1117;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
}

.brand-mark img {
  width: 46px;
  height: 46px;
  display: block;
  border-radius: 8px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: #c2cad5;
}

.top-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.top-actions input {
  min-width: 230px;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.sidebar,
.workspace {
  display: grid;
  align-content: start;
  gap: 14px;
}

.tool-panel,
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tool-panel {
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0;
}

.field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.field + .field {
  margin-top: 10px;
}

.field.compact {
  color: #d8dee7;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 10px;
}

.full {
  width: 100%;
}

.full + .full {
  margin-top: 8px;
}

.csv-import-field {
  margin-bottom: 8px;
}

.import-status {
  margin: 8px 0 12px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-line;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric {
  padding: 14px;
  min-height: 104px;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0;
}

.metric small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.35;
}

.candidate-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
}

.load-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.result-box {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.result-box strong {
  display: block;
  font-size: 18px;
  margin-bottom: 6px;
}

.result-box p {
  margin: 4px 0;
  color: var(--text);
}

.result-box ul {
  margin: 8px 0 0 18px;
  padding: 0;
}

.result-box li {
  margin: 4px 0;
}

.result-box.allowed {
  border-color: rgba(31, 122, 77, 0.35);
  background: #eef8f2;
}

.result-box.blocked {
  border-color: rgba(180, 35, 24, 0.35);
  background: #fff2f0;
}

.result-box.warning {
  border-color: rgba(153, 106, 19, 0.35);
  background: #fff8e8;
}

.result-box.muted {
  color: var(--muted);
}

.case-actions {
  display: grid;
  grid-template-columns: minmax(180px, 240px) auto auto;
  gap: 8px;
  margin-top: 10px;
  justify-content: start;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.table-wrap {
  overflow-x: auto;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 800;
}

.badge.good {
  color: var(--green);
  background: #e9f7ef;
}

.badge.bad {
  color: var(--red);
  background: #fdecea;
}

.badge.warn {
  color: var(--amber);
  background: #fff4d6;
}

.delete-btn {
  min-height: 30px;
  border-color: #c7d0da;
  background: #fff;
  color: var(--red);
  padding: 0 9px;
}

@media (max-width: 1180px) {
  .status-grid,
  .two-column {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .candidate-grid,
  .load-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions input {
    min-width: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .status-grid,
  .two-column,
  .candidate-grid,
  .load-grid,
  .case-actions {
    grid-template-columns: 1fr;
  }
}

/* ====== Вход, бейдж пользователя, синхронизация ====== */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 32, 0.55);
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel, #fff);
  border: 1px solid var(--line, #d9e0e7);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(15, 23, 32, 0.25);
  padding: 24px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-mark {
  align-self: center;
}

.login-mark img {
  width: 44px;
  height: 44px;
  display: block;
}

.login-card h2 {
  margin: 0;
  font-size: 18px;
  text-align: center;
}

.login-sub {
  margin: -6px 0 6px;
  color: var(--muted, #637083);
  font-size: 12px;
  text-align: center;
}

.login-error {
  margin: 0;
  min-height: 16px;
  color: var(--red, #b42318);
  font-size: 12px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-email {
  color: var(--muted, #637083);
  font-size: 12px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green, #1f7a4d);
  flex: none;
}

.sync-dot[data-state="syncing"] {
  background: var(--amber, #996a13);
}

.sync-dot[data-state="error"] {
  background: var(--red, #b42318);
}
