:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #212529;
  --text-muted: #6c757d;
  --primary: #0056b3;
  --primary-hover: #004494;
  --accent: #198754;
  --warning: #ffc107;
  --danger: #dc3545;
  --border: #dee2e6;
  --radius: 6px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.5; }
a { text-decoration: none; color: var(--primary); }
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

.navbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 0; position: sticky; top: 0; z-index: 10; }
.nav-content { display: flex; justify-content: space-between; align-items: center; }
.logo { font-weight: 600; font-size: 18px; color: var(--text); }
.nav-links { list-style: none; display: flex; gap: 16px; }
.nav-links a { color: var(--text-muted); padding: 6px 10px; border-radius: var(--radius); }
.nav-links a:hover, .nav-links a.active { background: #e9ecef; color: var(--text); }

.btn { display: inline-block; padding: 8px 16px; border-radius: var(--radius); cursor: pointer; border: none; font-size: 14px; transition: 0.2s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { border: 1px solid var(--border); background: transparent; color: var(--text); }
.badge { padding: 3px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; }
.badge-danger { background: #fde8e8; color: var(--danger); }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-default { background: #e9ecef; color: var(--text-muted); }
.link { color: var(--primary); cursor: pointer; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-top: 10px; }
input, select, textarea { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; width: 100%; }
.filters { background: var(--surface); padding: 16px; border-radius: var(--radius); box-shadow: var(--shadow); display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; align-items: center; }

h1 { margin: 24px 0 16px; font-size: 24px; font-weight: 600; }
.camera-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-top: 16px; }
.camera-card { background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); cursor: pointer; transition: transform 0.2s; }
.camera-card:hover { transform: translateY(-2px); }
.camera-preview { height: 160px; background: #e9ecef; }
.camera-info { padding: 12px; }
.checks-list { display: flex; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
.check-item { font-size: 11px; background: #e9ecef; padding: 2px 6px; border-radius: 4px; color: var(--text-muted); }

.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.data-table th, .data-table td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: #f8f9fa; font-weight: 500; color: var(--text-muted); }
.unread { background: #fcfcfc; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin: 16px 0; }
.stat-card { background: var(--surface); padding: 20px; border-radius: var(--radius); box-shadow: var(--shadow); text-align: center; }
.stat-value { font-size: 32px; font-weight: 600; color: var(--primary); }
.stat-label { color: var(--text-muted); margin-top: 4px; }

.bar-list { margin-top: 10px; }
.bar-item { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bar-name { width: 120px; font-size: 14px; }
.bar-track { flex: 1; background: #e9ecef; height: 8px; border-radius: 4px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; }
.bar-count { width: 40px; text-align: right; font-size: 14px; color: var(--text-muted); }

.event-detail { background: var(--surface); padding: 24px; border-radius: var(--radius); box-shadow: var(--shadow); }
.event-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.event-meta { color: var(--text-muted); margin-bottom: 16px; }
.media-container { background: #f8f9fa; border-radius: var(--radius); height: auto; display: flex; align-items: center; justify-content: center; margin-bottom: 16px; overflow: hidden; }
.media-preview { width: 100%; height: 100%; object-fit: cover; }
.media-placeholder { color: var(--text-muted); }
.comment-section { border-top: 1px solid var(--border); padding-top: 16px; }

.auth-body { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--bg); }
.auth-card { background: var(--surface); padding: 32px; border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 360px; text-align: center; }
.auth-card input { margin-bottom: 12px; }
.auth-card .btn { width: 100%; margin-top: 8px; }
.error { color: var(--danger); background: #fde8e8; padding: 8px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; }

.nav-row {
    display: flex;
    justify-content: space-between;  /* левое и правое по краям */
    align-items: center;
    width: 100%;
    margin-bottom: 16px;
}

.nav-left,
.nav-right {
    display: flex;
    align-items: center;
    gap: 20px;          /* расстояние между кнопками внутри блока */
}

.nav-left {
    justify-content: flex-start;
}

.nav-right {
    justify-content: flex-end;
}

.back-link {
    display: inline-block;
    color: var(--text-muted, #6c757d);
    text-decoration: none;
    transition: color 0.2s ease;
    white-space: nowrap;
}

.back-link:hover {
    color: var(--text, #212529);
}

/* Если экран узкий, чтобы кнопки не налезали друг на друга */
@media (max-width: 600px) {
    .nav-row {
        flex-wrap: wrap;
        gap: 12px;
    }
    .nav-left, .nav-right {
        flex-wrap: wrap;
        gap: 12px;
    }
}

.alert {
  background: #e8f5e9;
  border: 1px solid #c8e6c9;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  color: #2e7d32;
}
.alert-success { background: #e8f5e9; border-color: #c8e6c9; color: #2e7d32; }
.password-code {
  background: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 14px;
  margin: 0 8px;
  border: 1px solid var(--border);
}
.alert-note {
  font-size: 12px;
  color: #666;
  margin-top: 8px;
  font-style: italic;
}
.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}
.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  vertical-align: middle;
}

.password-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  flex-wrap: wrap;
}
.password-code {
  background: #fff;
  padding: 6px 10px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 14px;
  border: 1px solid var(--border);
  flex: 1;
  min-width: 200px;
  word-break: break-all;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #333;
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 1000;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.alert {
  background: #e8f5e9;
  border: 1px solid #c8e6c9;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  color: #2e7d32;
}
.alert-note {
  font-size: 12px;
  color: #666;
  margin-top: 8px;
  font-style: italic;
}

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab { padding: 10px 16px; text-decoration: none; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: 0.2s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

.enterprise-card { background: var(--surface); padding: 16px; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.enterprise-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.enterprise-header h3 { margin: 0; }
.data-table.compact th, .data-table.compact td { padding: 8px 10px; font-size: 14px; }
.checks-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.cam-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.cam-form select { width: auto; min-width: 200px; }
.delete-inline { display: inline; margin-left: 8px; }
.form-inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.form-inline input, .form-inline button { margin-bottom: 0; }

.modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal.show { display: flex; }
.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    width: 90%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 18px; }
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
}
.modal-tab {
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 14px;
    transition: 0.2s;
}
.modal-tab:hover { color: var(--text); }
.modal-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 500;
}

.modal-tab-content { padding: 16px 20px; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 14px;
}
.form-group input, .form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
}
.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: #f8f9fa;
}

.camera-source {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    background: #e9ecef;
    color: var(--text-muted);
    margin-left: 6px;
}
.camera-source.sftp::before { content: "📁"; }
.camera-source.rtsp::before { content: "📡"; }

.settings-section {
    background: var(--surface);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.settings-section h3 {
    margin: 0 0 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 18px;
    font-weight: 600;
}
.form-vertical .form-group {
    margin-bottom: 16px;
}
.form-vertical label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 14px;
}
.form-vertical input,
.form-vertical select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    box-sizing: border-box;
}
.form-vertical input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
    vertical-align: middle;
}
.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
}
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 14px;
}
.alert-success {
    background: #e8f5e9;
    border: 1px solid #c8e6c9;
    color: #2e7d32;
}
.alert-error {
    background: #fde8e8;
    border: 1px solid #f5c2c7;
    color: #b02a37;
}