:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }

.hidden { display: none !important; }

/* Видимый фокус для клавиатурной навигации */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.input:focus-visible { outline: none; }

/* Уважение к prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===== Login ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #eef2ff 0%, #f4f6fa 50%, #ecfeff 100%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
}
.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
}
.login-card p.sub {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 14px;
}
.login-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ===== Layout ===== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  padding: 4px 12px 20px;
  letter-spacing: .2px;
}
.sidebar .brand span { color: #60a5fa; }
.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  color: #cbd5e1;
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 14.5px;
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-btn.active { background: var(--accent); color: #fff; }
.nav-btn svg { flex-shrink: 0; }
.sidebar .spacer { flex: 1; }
.sidebar .userbox {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: 13px;
}
.sidebar .userbox .login { color: #fff; font-weight: 600; }
.sidebar .userbox .role-tag { color: #60a5fa; font-size: 12px; }
.sidebar .userbox button {
  margin-top: 10px;
  width: 100%;
  background: rgba(255,255,255,.08);
  color: #e2e8f0;
  border: none;
  border-radius: 7px;
  padding: 8px;
  cursor: pointer;
  font-size: 13px;
}
.sidebar .userbox button:hover { background: rgba(255,255,255,.15); }

.main {
  padding: 28px 32px 60px;
  min-width: 0;
}
.main > section { animation: page-in .18s ease; }
@keyframes page-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.page-title { font-size: 21px; font-weight: 700; margin: 0 0 4px; }
.page-sub { color: var(--text-muted); font-size: 14px; margin: 0 0 22px; }

/* ===== Cards / common ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card h3 { margin: 0 0 14px; font-size: 15.5px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #334155; }
.input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .08s;
  background: var(--accent);
  color: #fff;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.danger:hover { background: #fee2e2; }
.btn.ghost { background: transparent; color: var(--accent); padding: 6px 10px; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn.full { width: 100%; justify-content: center; }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  color: var(--text-muted);
  line-height: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ===== Tabs ===== */
.tabs {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
  margin-bottom: 18px;
}
.tab-btn {
  border: none;
  background: none;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text-muted);
}
.tab-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(15,23,42,.1); }

/* ===== Dropzone ===== */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 42px 20px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--surface-2);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .dz-title { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.dropzone .dz-sub { font-size: 13px; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.data th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface-2);
}
table.data td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
table.data tr.group-start td { border-top: 2px solid var(--border); }
table.data tbody tr { transition: background .1s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data th.num { text-align: right; }
table.data .muted { color: var(--text-muted); }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
}
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.orange { background: var(--warn-soft); color: var(--warn); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.gray { background: var(--surface-2); color: var(--text-muted); }

/* ===== Manual input table ===== */
.manual-table input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: 6px 8px;
  outline: none;
}
.manual-table input:focus { border-color: var(--accent); background: var(--surface); }
.manual-table td { padding: 3px 4px; }

.paste-zone {
  width: 100%;
  min-height: 70px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 12px;
  resize: vertical;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}
.paste-zone:focus { border-color: var(--accent); background: var(--accent-soft); }

/* ===== Stats row ===== */
.stats-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  min-width: 140px;
  box-shadow: var(--shadow);
}
.stat .val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.stat.warn { border-color: #fecaca; background: var(--danger-soft); }
.stat.warn .val { color: var(--danger); }

/* Секции в таблице результатов */
table.data tr.section-row td {
  padding: 10px 12px;
  font-weight: 700;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
table.data tr.section-row svg { vertical-align: -2px; margin-right: 6px; }
table.data tr.section-row.nf td { background: var(--danger-soft); color: var(--danger); }
table.data tr.section-row.ok td { background: var(--success-soft); color: var(--success); }

/* Строки без роли в прайсе */
table.data tr.nf-row td { background: #fff7f7; }
table.data tr.nf-row:hover td { background: #fef2f2; }

/* ===== Roles accordion ===== */
.role-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}
.role-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
}
.role-head:hover { background: var(--surface-2); }
.role-head .role-name { font-weight: 700; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.role-head .chev { transition: transform .18s; color: var(--text-muted); }
.role-block.open .role-head .chev { transform: rotate(90deg); }
.role-body { border-top: 1px solid var(--border); animation: page-in .15s ease; }
.role-block:not(.open) .role-body { display: none; }
.role-actions { display: flex; gap: 6px; align-items: center; }

.svc-edit-input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  width: 100%;
  outline: none;
}
.svc-edit-input:focus { border-color: var(--accent); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(3px);
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in .15s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, .3);
  padding: 28px;
  width: 100%;
  max-width: 400px;
  animation: pop-in .18s ease;
}
@keyframes pop-in { from { transform: scale(.95); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px;
}
.modal-icon.danger { background: var(--danger-soft); color: var(--danger); }
.modal-icon.info { background: var(--accent-soft); color: var(--accent); }
.modal-card h3 { margin: 0 0 8px; font-size: 17px; }
.modal-card p { margin: 0 0 20px; color: var(--text-muted); font-size: 14px; line-height: 1.5; }
.modal-card .input { margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ===== Toast ===== */
#toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #0f172a;
  color: #fff;
  border-radius: 9px;
  padding: 12px 14px 12px 16px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(15,23,42,.25);
  animation: slide-in .2s ease;
  max-width: 380px;
}
.toast svg { flex-shrink: 0; margin-top: 1px; }
.toast .t-close {
  background: none; border: none; color: rgba(255,255,255,.7);
  cursor: pointer; padding: 0 0 0 6px; line-height: 1; font-size: 16px;
}
.toast .t-close:hover { color: #fff; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== Loader ===== */
.loader-overlay {
  position: fixed;
  inset: 0;
  background: rgba(244,246,250,.75);
  backdrop-filter: blur(2px);
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.spinner {
  width: 42px; height: 42px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { font-weight: 600; color: var(--text); }

/* ===== Checkbox rows (settings) ===== */
.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 9px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--surface);
}
.check-row:hover { border-color: var(--accent); }
.check-row.checked { border-color: var(--accent); background: var(--accent-soft); }
.check-row .cb {
  width: 20px; height: 20px;
  border-radius: 6px;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  background: var(--surface);
}
.check-row.checked .cb { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ===== Search bar ===== */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.search-box {
  position: relative;
  flex: 1;
  min-width: 220px;
  max-width: 420px;
}
.search-box input { padding-left: 36px; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }

/* ===== Users ===== */
.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 9px;
  margin-bottom: 8px;
  background: var(--surface);
}
.user-row .u-login { font-weight: 600; flex: 1; }
.user-row .u-date { color: var(--text-muted); font-size: 12.5px; }

.pwd-wrap { display: flex; gap: 8px; }
.pwd-wrap .input { flex: 1; }

/* ===== Mobile ===== */
.mobile-header { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: min(280px, 82vw);
    z-index: 500;
    transform: translateX(-100%);
    transition: transform .2s ease;
    height: 100vh;
  }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.4);
    z-index: 400;
  }
  .mobile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #0f172a;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 300;
  }
  .mobile-header .burger {
    background: none; border: none; color: #fff; cursor: pointer; padding: 4px; line-height: 0;
  }
  .mobile-header .m-brand { font-weight: 700; }
  .mobile-header .m-brand span { color: #60a5fa; }
  .main { padding: 18px 14px 50px; }
  .stats-row .stat { flex: 1; min-width: 100px; padding: 12px 14px; }
  .stat .val { font-size: 18px; }
  .user-row { flex-wrap: wrap; }
  .user-row .u-actions { width: 100%; display: flex; gap: 8px; justify-content: flex-end; }
}

/* ===== Search clear ===== */
.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  line-height: 0;
  border-radius: 6px;
}
.search-clear:hover { background: var(--surface-2); color: var(--text); }
.search-count { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

/* ===== Credentials block in modal ===== */
.creds-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 14px 16px;
  margin-bottom: 20px;
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 14px;
}
.creds-block .cred-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.creds-block .cred-label { color: var(--text-muted); font-family: 'Inter', system-ui, sans-serif; font-size: 13px; }
