/* ===== VARIABLES ===== */
:root {
  --bg: #f0f9ff;
  --card: #ffffff;
  --primary: #0ea5e9;
  --primary-hover: #0284c7;
  --primary-light: #e0f2fe;
  --text: #0c4a6e;
  --text-light: #64748b;
  --border: #bae6fd;
  --border-hover: #7dd3fc;
  --tag-bg: #e0f2fe;
  --tag-text: #0369a1;
  --tag-border: #7dd3fc;
  --error: #dc2626;
  --success: #10b981;
  --shadow-sm: 0 1px 2px 0 rgba(14, 165, 233, 0.05);
  --shadow: 0 4px 6px -1px rgba(14, 165, 233, 0.1), 0 2px 4px -1px rgba(14, 165, 233, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(14, 165, 233, 0.1), 0 4px 6px -2px rgba(14, 165, 233, 0.05);
  --radius: 8px;
  --radius-lg: 12px;
}

/* ===== RESET & BASE ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
.container { max-width: 1400px; margin: 0 auto; padding: 2rem; }

/* ===== LOGIN ===== */
.login-wrap { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 1rem; }
.login-card {
  background: var(--card); padding: 2.5rem; border-radius: var(--radius-lg);
  border: 2px solid var(--border); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 420px; text-align: center;
}
.login-card h2 { margin-bottom: 1.5rem; color: var(--primary); font-size: 1.75rem; font-weight: 700; }
.login-card input, .login-card button { width: 100%; }

/* ===== FORMS & INPUTS ===== */
input:not([type="checkbox"]):not([type="radio"]) {
  width: 100%; padding: 0.75rem 1rem; margin: 0.5rem 0 1rem;
  border: 2px solid var(--border); border-radius: var(--radius);
  font-size: 1rem; background: var(--card); transition: all 0.2s;
}
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

/* ===== BUTTONS ===== */
button {
  padding: 0.75rem 1.5rem; background: var(--card); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radius);
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  transition: all 0.2s; box-shadow: var(--shadow-sm);
}
button:hover { border-color: var(--border-hover); transform: translateY(-1px); box-shadow: var(--shadow); }
button:active { transform: translateY(0); }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-secondary { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--border-hover); background: var(--bg); }

.btn-icon { background: var(--card); border: 2px solid var(--border); padding: 0.4rem 0.6rem; font-size: 1rem; }
.btn-icon:hover { border-color: var(--primary); transform: scale(1.1); }

.btn-save { background: var(--success); color: #fff; border-color: var(--success); padding: 0.5rem 0.75rem; }
.btn-save:hover { background: #059669; border-color: #059669; }

.btn-cancel { background: var(--error); color: #fff; border-color: var(--error); padding: 0.5rem 0.75rem; }
.btn-cancel:hover { background: #dc2626; border-color: #dc2626; }

.btn-delete { background: #fff1f2; color: var(--error); border-color: #fecaca; padding: 0.5rem 0.75rem; }
.btn-delete:hover { background: var(--error); color: #fff; border-color: var(--error); }

.logout-btn { padding: 0.5rem 1rem; background: var(--card); color: var(--text-light); border: 1px solid var(--border); font-size: 0.85rem; height: 36px; }
.logout-btn:hover { border-color: var(--error); color: var(--error); background: #fef2f2; }

/* ===== HEADER & NAVIGATION ===== */
.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  padding: 0.85rem 1.25rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 2rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.header-left { display: flex; align-items: center; gap: 1.5rem; }
.header-left h1 { font-size: 1.25rem; font-weight: 800; color: var(--primary); margin: 0; white-space: nowrap; }

.tabs { display: flex; gap: 0.25rem; background: var(--bg); padding: 0.35rem; border-radius: var(--radius); border: 1px solid var(--border); }
.tab { padding: 0.5rem 1rem; border-radius: var(--radius); cursor: pointer; font-weight: 600; font-size: 0.9rem; color: var(--text-light); transition: all 0.2s; }
.tab:hover { color: var(--text); background: rgba(255,255,255,0.6); }
.tab.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }

.search-box, .filter-select, .logout-btn {
  height: 38px;
  box-sizing: border-box;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-left: auto; /* Жёстко прижимает всё вправо, ломается меньше */
}

/* ===== CONTROLS (Search & Selects) ===== */
.search-box {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 0.6rem;
  width: 220px;
  flex-shrink: 0;
  overflow: hidden;
}

.search-icon {
  font-size: 1rem;
  margin-right: 0.5rem;
  opacity: 0.5;
  flex-shrink: 0;
  line-height: 1;
  pointer-events: none;
}

.search-input {
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
  height: 100%;
  width: 100%;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
  outline: none;
  box-shadow: none !important;
}
.search-input::placeholder { color: var(--text-light); opacity: 0.7; }
.search-input:focus { box-shadow: none; }

.filter-select {
  height: 36px; padding: 0 0.75rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--text); font-size: 0.85rem; font-weight: 500;
  cursor: pointer; outline: none; transition: all 0.2s; min-width: 120px;
}
.filter-select:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.filter-select:hover { border-color: var(--border-hover); }

/* ===== TABLES ===== */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius-lg); border: 2px solid var(--border); box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.9rem; min-width: 900px; }
.data-table th {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  color: #fff; padding: 1rem; text-align: left; font-weight: 600;
  border-bottom: 2px solid var(--primary-hover); white-space: nowrap;
}
.data-table th:first-child { border-top-left-radius: var(--radius); }
.data-table th:last-child { border-top-right-radius: var(--radius); }
.data-table th { font-weight: 600; }
.data-table td { font-weight: 400; }

.data-table td { padding: 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:hover td { background: var(--primary-light); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:last-child td:first-child { border-bottom-left-radius: var(--radius); }
.data-table tr:last-child td:last-child { border-bottom-right-radius: var(--radius); }

/* ===== TAGS ===== */
.tag { display: inline-block; background: var(--tag-bg); color: var(--tag-text); padding: 0.25rem 0.75rem; border-radius: 99px; font-size: 0.75rem; font-weight: 600; margin-right: 0.35rem; margin-bottom: 0.25rem; border: 1px solid var(--tag-border); }
.tag-admin { background: #dcfce7; color: #166534; border-color: #bbf7d0; }

/* ===== ADMIN PANEL ===== */
.admin-panel { background: var(--card); padding: 1.5rem; border-radius: var(--radius-lg); border: 2px solid var(--border); box-shadow: var(--shadow); margin-bottom: 2rem; }
.admin-panel > h3 {
  color: var(--primary);
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 1.5rem 0;
  padding: 0;
  border: none;
  line-height: 1.2;
}
.admin-tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.admin-tab { padding: 0.5rem 1rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; font-weight: 600; }
.admin-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.panel-header h3 { margin: 0; font-size: 1.25rem; font-weight: 700; color: var(--primary); }
.panel-header .btn-primary { flex: 0 0 auto; width: auto; padding: 0.6rem 1.2rem; margin-left: 1rem; }

.router-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); gap: 1rem; }
.router-card { display: flex; justify-content: space-between; align-items: center; padding: 1rem; background: var(--card); border: 2px solid var(--border); border-radius: var(--radius); transition: all 0.2s; box-shadow: var(--shadow-sm); }
.router-card:hover { border-color: var(--border-hover); box-shadow: var(--shadow); transform: translateY(-2px); }
.router-info { flex: 1; margin-right: 0.75rem; }
.router-addr { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.5rem; }
.edit-input { margin: 0; padding: 0.5rem; font-size: 0.9rem; border: 2px dashed var(--border); border-radius: var(--radius); background: var(--primary-light); }
.edit-input:focus { border-color: var(--primary); border-style: solid; background: var(--card); }
.router-actions { display: flex; gap: 0.5rem; }

/* ===== MODAL & USER FORM ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6); display: flex; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(4px); }
.modal { background: var(--card); padding: 2rem; border-radius: var(--radius-lg); border: 2px solid var(--border); width: 90%; max-width: 500px; box-shadow: var(--shadow-lg); }
.modal h3 { margin-bottom: 1.25rem; font-size: 1.25rem; font-weight: 700; color: var(--primary); }
.modal-input { margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: 0.75rem; margin-top: 1rem; }
.modal-actions .btn-primary, .modal-actions .btn-secondary { flex: 1; }
.modal .checkbox-label {
  font-weight: 400 !important;
  color: var(--text);
}
.modal .checkbox-grid .checkbox-item {
  font-weight: 400 !important;
}

/* Checkboxes & Permissions */
.checkbox-label { display: inline-flex; align-items: center; gap: 0.75rem; width: auto; margin: 0.75rem 0; cursor: pointer; font-weight: 500; }
input[type="checkbox"] { width: 18px; height: 18px; margin: 0; border: 2px solid var(--border); border-radius: 4px; cursor: pointer; accent-color: var(--primary); flex-shrink: 0; }
.router-perms { margin-top: 0.5rem; padding: 0.75rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.router-perms p { margin: 0 0 0.5rem 0; font-weight: 600; }
.checkbox-grid { display: flex; flex-direction: column; gap: 0.5rem; max-height: 150px; overflow-y: auto; }
.checkbox-item { display: inline-flex; align-items: center; gap: 0.75rem; width: auto; cursor: pointer; font-size: 0.9rem; }

/* ===== UTILITIES ===== */
.empty-state { text-align: center; color: var(--text-light); padding: 4rem 2rem; background: var(--card); border: 2px dashed var(--border); border-radius: var(--radius-lg); font-size: 1.1rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }
.small { font-size: 0.85rem; color: var(--text-light); }
.small .muted { color: var(--text-light); font-size: 0.8rem; }
.users-cell { max-width: 300px; word-break: break-word; line-height: 1.5; }
.muted { color: var(--text-light); font-size: 0.85rem; }
.error-msg { color: var(--error); font-size: 0.85rem; margin-top: 0.75rem; padding: 0.5rem; background: #fef2f2; border: 1px solid #fecaca; border-radius: var(--radius); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .header-bar { flex-direction: column; align-items: stretch; padding: 1rem; }
  .header-left { justify-content: space-between; margin-bottom: 1rem; }
  .header-right { justify-content: flex-start; }
  .search-input { width: 100%; }
}
@media (max-width: 768px) {
  .container { padding: 1rem; }
  .router-grid { grid-template-columns: 1fr; }
  .data-table { font-size: 0.8rem; }
  .data-table th, .data-table td { padding: 0.75rem 0.5rem; }
}

/* Лого в шапке */
.app-logo {
  height: 32px;
  width: 32px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 6px;
}

/* Лого на странице входа */
.login-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  margin-bottom: 1rem;
  border-radius: 8px;
}