/* Infra CRM — light Bitrix24-like admin theme */
:root {
  --bg: #eef2f4;
  --bg-soft: #f5f7f8;
  --bg-card: #ffffff;
  --sidebar-bg: #535c69;
  --sidebar-bg-hover: #606b7a;
  --sidebar-text: #e8edf2;
  --sidebar-muted: #b5bdc6;
  --sidebar-active: #2fc6f6;
  --sidebar-width: 240px;
  --sidebar-collapsed: 64px;
  --text: #333333;
  --muted: #828b95;
  --border: #dfe2e6;
  --primary: #2fc6f6;
  --primary-hover: #11b2e5;
  --primary-text: #ffffff;
  --danger: #ff5752;
  --danger-hover: #e04945;
  --success: #9dcf00;
  --warning: #ffa900;
  --gray: #a8adb4;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --topbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Arial, sans-serif;
}

a { color: #2067b0; text-decoration: none; }
a:hover { color: #164a7e; }

.app-shell { min-height: 100vh; display: flex; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  z-index: 1000;
  transition: width 0.2s ease;
  overflow: hidden;
}

.app-shell.collapsed .sidebar { width: var(--sidebar-collapsed); }

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--topbar-h);
  padding: 0 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo { width: 32px; height: 32px; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: rgba(255,255,255,0.12); }

.sidebar-logo-fallback {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff;
  background: linear-gradient(135deg, #2fc6f6, #2067b0);
  flex-shrink: 0;
}

.sidebar-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.app-shell.collapsed .sidebar-title,
.app-shell.collapsed .nav-label,
.app-shell.collapsed .nav-group-title { display: none; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
.nav-group { margin-bottom: 12px; }
.nav-group-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--sidebar-muted); padding: 6px 10px 4px; }

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 6px;
  color: var(--sidebar-text); margin-bottom: 2px; white-space: nowrap;
}
.nav-link:hover { background: var(--sidebar-bg-hover); color: #fff; }
.nav-link.active { background: rgba(47,198,246,0.18); color: #fff; box-shadow: inset 3px 0 0 var(--sidebar-active); }
.nav-icon { width: 20px; height: 20px; flex-shrink: 0; opacity: 0.95; }

.sidebar-footer { padding: 10px 8px 12px; border-top: 1px solid rgba(255,255,255,0.08); }

.main-area {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.2s ease;
}
.app-shell.collapsed .main-area { margin-left: var(--sidebar-collapsed); }

.topbar {
  position: sticky; top: 0; z-index: 900;
  flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  min-height: var(--topbar-h); padding: 0 28px;
  background: var(--bg-card); border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
}

.topbar-toggle { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 20px; padding: 6px; border-radius: 6px; }
.topbar-toggle:hover { background: var(--bg-soft); }
.page-title { font-size: 18px; font-weight: 700; margin: 0; flex: 1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.content {
  flex: 1;
  width: 100%;
  padding: 24px 28px 32px;
  min-height: calc(100vh - var(--topbar-h));
}
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 999; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-width) !important; }
  .app-shell.mobile-open .sidebar { transform: translateX(0); }
  .app-shell.mobile-open .sidebar-backdrop { display: block; }
  .main-area { margin-left: 0 !important; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px; }
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: var(--radius); padding: 7px 14px; min-height: 34px;
  cursor: pointer; font-weight: 600; font-size: 13px; text-decoration: none; gap: 6px;
}
.btn:disabled { opacity: 0.65; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-gray, .btn-secondary { background: #dfe2e6; color: #535c69; }
.btn-gray:hover, .btn-secondary:hover { background: #cfd4da; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-ok { background: #e8f5d6; color: #6a8f00; }
.badge-no, .badge-danger { background: #ffecec; color: #c0392b; }
.badge-warn { background: #fff1c6; color: #7a4b00; }

.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card h2, .card h3 { margin: 0 0 12px 0; font-size: 17px; color: #333; }
.card-compact { padding: 12px 14px; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (min-width: 1600px) {
  .grid.cols-4 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) { .grid.cols-3, .grid.cols-2, .grid.cols-4 { grid-template-columns: 1fr; } }

.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.stat-value { font-size: 26px; font-weight: 800; line-height: 1.1; }
.stat-meta { margin-top: 6px; font-size: 12px; color: var(--muted); }
.stat-card.critical { border-color: #ffb4b0; background: #fff8f8; }
.stat-card.warning { border-color: #ffd88a; background: #fffbf0; }
.alert-inline { display: inline-block; margin-left: 8px; padding: 2px 7px; border-radius: 999px; font-size: 10px; font-weight: 700; background: #ff5752; color: #fff; vertical-align: middle; }

.table-responsive { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--bg-card); }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; background: var(--bg-soft); }
tr:hover td { background: #fafbfc; }
.t-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.t-actions .action-form { display: inline-flex; margin: 0; }
tr.row-locked td { background: #fff8f8; }
.lock-until { font-size: 11px; margin-top: 4px; line-height: 1.3; }
.btn-warn { background: #fff1c6; color: #7a4b00; border: 1px solid #e8c96a; }
.btn-warn:hover { background: #ffe9a8; }
.table-wide { min-width: 900px; }

.form { display: grid; gap: 10px; }
.form-row { display: grid; grid-template-columns: 180px 1fr; gap: 14px; align-items: center; }
.form-row.full { grid-template-columns: 1fr; }
label { color: var(--muted); font-size: 13px; }
input, select, textarea { width: 100%; background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 11px; outline: none; font: inherit; }
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  padding: 0;
  border-radius: 3px;
  flex-shrink: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,198,246,0.2); }
textarea { min-height: 110px; resize: vertical; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
@media (max-width: 720px) { .form-row { grid-template-columns: 1fr; } }

.flash { padding: 11px 14px; border-radius: var(--radius); margin-bottom: 14px; font-weight: 600; font-size: 13px; }
.flash.success { background: #edf6d6; color: #526900; border: 1px solid #d4e8a0; }
.flash.danger { background: #ffecec; color: #a94442; border: 1px solid #ffb4b0; }
.flash.warning { background: #fff4dd; color: #8a6200; border: 1px solid #ffd88a; }
.flash.info { background: #e5f7fd; color: #2067b0; border: 1px solid #b8e8fa; }

.filters { background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; padding: 14px; }
.form-inline { display: flex; align-items: end; gap: 14px; flex-wrap: wrap; }
.filter-group { display: flex; flex-direction: column; gap: 6px; min-width: 180px; }
.filter-group label { font-weight: 600; font-size: 12px; }
.filter-actions { display: flex; gap: 8px; align-items: end; }
.pagination { display: flex; gap: 6px; justify-content: center; margin: 16px 0; flex-wrap: wrap; }
.pagination-info { text-align: center; color: var(--muted); font-size: 13px; margin-top: 8px; }
.muted { color: var(--muted); }
.mt-10 { margin-top: 10px; }
.mt-16 { margin-top: 16px; }
.center { display: flex; align-items: center; justify-content: center; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-header h2 { margin: 0; font-size: 20px; }

.metrics-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 900px) { .metrics-grid { grid-template-columns: 1fr; } }
.gauge-card { padding: 14px; }
.gauge-title { font-size: 13px; font-weight: 700; margin: 0 0 10px; color: #535c69; }
.gauge-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.gauge-item { text-align: center; }
.gauge-ring { width: 88px; height: 88px; margin: 0 auto 6px; }
.gauge-value { font-size: 18px; font-weight: 800; }
.gauge-sub { font-size: 11px; color: var(--muted); }
.quick-links { display: flex; flex-wrap: wrap; gap: 8px; }

.checker-accordion { margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--bg-card); box-shadow: var(--shadow); }
.checker-accordion summary { cursor: pointer; padding: 12px 16px; font-weight: 700; background: var(--bg-soft); list-style: none; user-select: none; }
.checker-accordion summary::-webkit-details-marker { display: none; }
.checker-accordion summary::before { content: "▸ "; display: inline-block; }
.checker-accordion[open] summary::before { content: "▾ "; }
.checker-body { padding: 14px 16px; border-top: 1px solid var(--border); }
.checker-sub-accordion { margin-top: 12px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.checker-sub-accordion summary { cursor: pointer; padding: 10px 12px; font-weight: 600; font-size: 13px; background: #fafbfc; list-style: none; }
.checker-sub-accordion summary::-webkit-details-marker { display: none; }
.checker-sub-body { padding: 12px; border-top: 1px solid var(--border); }

.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, #eef2f4 0%, #dfe6eb 100%); }
.login-card { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 28px 24px; }
.login-step-title { margin: 0 0 8px; font-size: 20px; font-weight: 700; color: #111827; }
.login-step-hint { margin: 0 0 16px; font-size: 14px; }
.login-check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.login-form-actions { margin-top: 4px; }
.login-alt-action { margin-top: 12px; text-align: center; }
.login-alt-action .btn-link { background: transparent; border: none; color: #6b7280; padding: 0; font-size: 13px; cursor: pointer; text-decoration: underline; }
.login-alt-action .btn-link:hover { color: #374151; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand-title { font-size: 22px; font-weight: 800; margin: 0; }

.dropdown { position: relative; display: inline-block; }
.dropdown-menu { display: none; position: absolute; top: 100%; left: 0; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 1000; min-width: 180px; padding: 6px 0; }
.dropdown-menu a { display: block; padding: 8px 14px; color: var(--text); }
.dropdown-menu a:hover { background: var(--bg-soft); }
.dropdown:hover .dropdown-menu { display: block; }
.btn.disabled { opacity: 0.5; pointer-events: none; }
pre.log-box { white-space: pre-wrap; background: var(--bg-soft); border: 1px solid var(--border); padding: 12px 14px; border-radius: var(--radius); font-size: 13px; max-height: 320px; overflow: auto; }
code { background: var(--bg-soft); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn-account { display: inline-flex; align-items: center; gap: 8px; }
.btn-account svg { width: 18px; height: 18px; flex-shrink: 0; }

.service-mode-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  cursor: pointer;
  user-select: none;
}
.service-mode-wrap.is-on {
  border-color: #b45309;
  background: rgba(180, 83, 9, 0.15);
}
.service-mode-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.service-mode-wrap.is-on .service-mode-label {
  color: #fbbf24;
}
.service-mode-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  margin: 0;
  cursor: pointer;
  pointer-events: none;
}
.service-mode-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.service-mode-slider {
  position: absolute;
  inset: 0;
  background: #4b5563;
  border-radius: 999px;
  transition: 0.2s;
}
.service-mode-slider:before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.service-mode-switch input:checked + .service-mode-slider {
  background: #d97706;
}
.service-mode-switch input:checked + .service-mode-slider:before {
  transform: translateX(18px);
}
.service-mode-switch input:disabled + .service-mode-slider {
  opacity: 0.55;
}

.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); display: none; align-items: flex-start; justify-content: center; z-index: 2000; padding: 16px; overflow-y: auto; }
.modal-overlay.is-open { display: flex; }
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  margin: auto;
  display: flex;
  flex-direction: column;
  background: #1f2937;
  color: #f3f4f6;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  border: 1px solid #374151;
  overflow: hidden;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 0; flex-shrink: 0; }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-close { background: transparent; border: none; color: #9ca3af; font-size: 22px; cursor: pointer; line-height: 1; }
.modal-tabs { display: flex; gap: 18px; padding: 12px 18px 0; border-bottom: 1px solid #374151; flex-shrink: 0; }
.modal-tab { background: none; border: none; color: #9ca3af; padding: 8px 0; cursor: pointer; font-weight: 600; border-bottom: 2px solid transparent; }
.modal-tab.active { color: #fbbf24; border-bottom-color: #fbbf24; }
.modal-body { padding: 18px; overflow-y: auto; flex: 1 1 auto; min-height: 0; -webkit-overflow-scrolling: touch; }
.modal-body label { display: block; margin: 10px 0 6px; font-size: 13px; color: #d1d5db; }
.modal-body input { width: 100%; box-sizing: border-box; padding: 10px 12px; border-radius: 8px; border: 1px solid #4b5563; background: #111827; color: #f9fafb; }
.modal-section { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid #374151; }
.modal-section:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.modal-section-title { margin: 0 0 10px; font-size: 13px; color: #9ca3af; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
#twofaSetupBox img { display: block; max-width: min(220px, 100%); height: auto; margin-top: 10px; background: #fff; padding: 8px; border-radius: 8px; }
.modal-body code,
.modal-body pre {
  background: #111827;
  color: #f9fafb;
  border: 1px solid #4b5563;
  padding: 10px 12px;
  border-radius: 8px;
  display: block;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-all;
  margin: 10px 0 0;
}
.modal-body pre { white-space: pre-wrap; }
.backup-codes-list { max-height: 180px; overflow-y: auto; }
.twofa-secret-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.06em;
  user-select: all;
}
.modal-footer { display: flex; gap: 10px; padding: 0 18px 18px; }
.panel-locked .main-area::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 1500; pointer-events: none; }
.panel-locked #accountModal { z-index: 1600; }
.session-modal .modal-card { max-width: 420px; }
.modal-footer .form-inline { display: inline; }
