@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root{
  /* dark theme (default) - deep purple fading to black */
  --bg:        linear-gradient(160deg, #1E1033 0%, #120A22 35%, #08050D 70%, #000000 100%);
  --bg-hero:   radial-gradient(1100px 420px at 15% -10%, rgba(34,211,184,.09), transparent 60%),
               radial-gradient(900px 380px at 90% 0%, rgba(139,92,246,.10), transparent 55%);
  --panel:     #171426;
  --panel-2:   #110D1C;
  --panel-hover: #1D1930;
  --border:    #2A2440;
  --border-soft: #201C33;
  --text:      #ECEFF4;
  --muted:     #938FA6;
  --muted-2:   #6E6A80;

  --accent:    #22D3B8;   /* teal - primary/online/foreign route */
  --accent-2:  #3B82F6;   /* blue - secondary accent */
  --grad:      linear-gradient(135deg, #22D3B8 0%, #3B82F6 100%);
  --ru:        #F5A623;   /* amber - route via MikroTik / RU networks */
  --danger:    #F0526B;
  --danger-bg: rgba(240,82,107,.15);
  --ok-bg:     rgba(34,211,184,.15);
  --ru-bg:     rgba(245,166,35,.15);

  --radius:    16px;
  --radius-sm: 10px;
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 12px 32px -16px rgba(0,0,0,.55);
  --shadow-lg: 0 4px 10px rgba(0,0,0,.35), 0 30px 60px -20px rgba(0,0,0,.6);

  --avatar-1: linear-gradient(135deg,#22D3B8,#0EA5A0);
  --avatar-2: linear-gradient(135deg,#3B82F6,#6366F1);
  --avatar-3: linear-gradient(135deg,#F5A623,#F97316);
  --avatar-4: linear-gradient(135deg,#EC4899,#F0526B);
  --avatar-5: linear-gradient(135deg,#8B5CF6,#6366F1);
  --avatar-6: linear-gradient(135deg,#06B6D4,#3B82F6);
}

[data-theme="light"]{
  --bg:        linear-gradient(160deg, #FFFFFF 0%, #F3F1FA 45%, #EAE6F5 100%);
  --bg-hero:   radial-gradient(1100px 420px at 15% -10%, rgba(34,211,184,.08), transparent 60%),
               radial-gradient(900px 380px at 90% 0%, rgba(139,92,246,.07), transparent 55%);
  --panel:     #FFFFFF;
  --panel-2:   #F5F4FA;
  --panel-hover: #ECEAF6;
  --border:    #E3E0EF;
  --border-soft: #ECEAF4;
  --text:      #1C1A28;
  --muted:     #6B6780;
  --muted-2:   #9490A6;

  --danger-bg: rgba(240,82,107,.10);
  --ok-bg:     rgba(20,184,166,.11);
  --ru-bg:     rgba(245,166,35,.12);

  --shadow:    0 1px 2px rgba(30,16,51,.05), 0 12px 28px -16px rgba(30,16,51,.12);
  --shadow-lg: 0 4px 10px rgba(30,16,51,.06), 0 30px 55px -20px rgba(30,16,51,.18);
}

*{ box-sizing:border-box; }

body{
  margin:0;
  background:var(--bg);
  background-attachment:fixed;
  color:var(--text);
  font-family:'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size:14px;
  -webkit-font-smoothing:antialiased;
  transition:background .2s ease, color .2s ease;
}

code, .mono, .data, td.num, .ip{
  font-family:'IBM Plex Mono', monospace;
}

a{ color:var(--accent); text-decoration:none; transition:color .15s ease; }
a:hover{ text-decoration:underline; }

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

/* ---------------------------------------------------------------- sidebar */
.sidebar{
  width:236px;
  background:var(--panel-2);
  border-right:1px solid var(--border-soft);
  padding:22px 0;
  flex-shrink:0;
}
.brand{
  font-weight:800;
  font-size:16px;
  letter-spacing:-.01em;
  padding:0 20px 20px;
  color:var(--text);
  border-bottom:1px solid var(--border-soft);
  margin-bottom:14px;
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:9px;
}
.brand-dot{
  width:10px; height:10px; border-radius:4px;
  background:var(--grad);
  box-shadow:0 0 14px rgba(34,211,184,.5);
  flex-shrink:0;
}
.brand small{ display:block; width:100%; color:var(--muted-2); font-weight:500; font-size:11px; margin-top:2px; letter-spacing:0; }

.nav{ padding:0 10px; }
.nav a{
  display:flex;
  align-items:center;
  gap:11px;
  padding:9px 12px;
  margin-bottom:2px;
  color:var(--muted);
  font-size:13.5px;
  font-weight:500;
  border-radius:10px;
  transition:color .15s ease, background .15s ease;
}
.nav a svg{
  width:16px; height:16px; flex-shrink:0;
  fill:none; stroke:currentColor; stroke-width:1.6; stroke-linecap:round; stroke-linejoin:round;
  opacity:.75;
}
.nav a:hover{ color:var(--text); text-decoration:none; background:var(--panel-hover); }
.nav a.active{ color:#02120F; background:var(--grad); font-weight:600; }
.nav a.active svg{ opacity:1; color:#02120F; }
.nav a.nav-logout{ margin-top:12px; padding-top:14px; border-top:1px solid var(--border-soft); border-radius:0; color:var(--muted-2); }
.nav a.nav-logout:hover{ color:var(--danger); background:transparent; }

.theme-toggle{
  display:flex; align-items:center; width:100%; margin-top:6px;
  background:none; border:none; cursor:pointer; padding:0;
  font-family:'Inter',sans-serif;
}
.theme-toggle span{
  display:flex; align-items:center; gap:11px; width:100%;
  padding:9px 12px; border-radius:10px; color:var(--muted); font-size:13.5px; font-weight:500;
  transition:color .15s ease, background .15s ease;
}
.theme-toggle span svg{ width:16px; height:16px; flex-shrink:0; opacity:.75; }
.theme-toggle:hover span{ color:var(--text); background:var(--panel-hover); }
.theme-toggle-to-dark{ display:none; }
[data-theme="light"] .theme-toggle-to-dark{ display:flex; }
[data-theme="light"] .theme-toggle-to-light{ display:none; }

.login-theme-toggle{
  position:fixed; top:20px; right:20px; width:38px; height:38px;
  border-radius:50%; background:var(--panel); border:1px solid var(--border);
  display:flex; align-items:center; justify-content:center; cursor:pointer;
  box-shadow:var(--shadow);
}
.login-theme-toggle span{ padding:0; }
.login-theme-toggle:hover{ border-color:#333B4E; }

.main{ flex:1; padding:36px 44px; max-width:1280px; background-image:var(--bg-hero); background-repeat:no-repeat; }

h1{ font-size:22px; font-weight:800; letter-spacing:-.01em; margin:0 0 5px; }
h2{ font-size:15px; font-weight:700; margin:0 0 14px; color:var(--text); letter-spacing:-.005em; }
.subtitle{ color:var(--muted); font-size:13.5px; margin-bottom:28px; }

.grid{ display:grid; grid-template-columns:repeat(auto-fit, minmax(200px,1fr)); gap:14px; margin-bottom:32px; }

.stat-row{ display:flex; gap:12px; margin-bottom:32px; overflow-x:auto; padding-bottom:6px; scrollbar-width:thin; }
.stat-row .card{ flex:1 1 0; min-width:158px; }
.stat-row::-webkit-scrollbar{ height:5px; }
.stat-row::-webkit-scrollbar-thumb{ background:var(--border); border-radius:99px; }

/* ------------------------------------------------------------------ cards */
.card{
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:20px 22px;
  box-shadow:var(--shadow);
  transition:border-color .15s ease, transform .15s ease, box-shadow .15s ease;
  overflow:hidden;
}
.stat-card{ display:flex; align-items:flex-start; gap:13px; }
.stat-text{ min-width:0; flex:1; }
.stat-icon{
  width:36px; height:36px; border-radius:11px; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  background:var(--ok-bg); color:var(--accent);
}
.stat-icon svg{ width:18px; height:18px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
.stat-label{ color:var(--muted); font-size:11px; font-weight:600; text-transform:uppercase; letter-spacing:.055em; margin-bottom:6px; overflow-wrap:break-word; }
.stat-value{ font-size:21px; font-weight:800; letter-spacing:-.015em; overflow-wrap:break-word; font-variant-numeric:tabular-nums; line-height:1.15; }
.stat-sub{ color:var(--muted-2); font-size:11.5px; margin-top:5px; overflow-wrap:break-word; word-break:break-word; }

.stat-dual{ display:flex; flex-direction:column; gap:7px; margin-top:1px; }
.stat-dual-row{ display:flex; align-items:baseline; gap:7px; }
.stat-dual-icon{ color:var(--muted-2); flex-shrink:0; }
.stat-dual-icon svg{ width:12px; height:12px; fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; }
.stat-dual-value{ font-size:15px; font-weight:700; font-variant-numeric:tabular-nums; letter-spacing:-.01em; }

/* ------------------------------------------------------------- peer cards */
.peer-grid{ display:grid; grid-template-columns:repeat(auto-fill, minmax(280px,1fr)); gap:14px; }
.peer-card{
  background:var(--panel); border:1px solid var(--border); border-radius:var(--radius);
  padding:18px 20px; box-shadow:var(--shadow); position:relative; overflow:hidden;
}
.peer-card:hover{ border-color:#2C3346; }
.peer-card.is-offline{ opacity:.72; }
.peer-card.is-disabled{ opacity:.5; }
.peer-head{ display:flex; align-items:center; gap:12px; margin-bottom:14px; padding-right:78px; }
.peer-head-text{ min-width:0; flex:1; }
.avatar{
  width:40px; height:40px; border-radius:12px; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  font-weight:700; font-size:14px; color:#04120F;
}
.avatar-1{ background:var(--avatar-1); } .avatar-2{ background:var(--avatar-2); color:#fff; }
.avatar-3{ background:var(--avatar-3); } .avatar-4{ background:var(--avatar-4); color:#fff; }
.avatar-5{ background:var(--avatar-5); color:#fff; } .avatar-6{ background:var(--avatar-6); }
.peer-name{ font-weight:700; font-size:14.5px; letter-spacing:-.005em; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.peer-name a{ color:var(--text); }
.peer-name a:hover{ text-decoration:none; color:var(--accent); }
.peer-sub{ color:var(--muted-2); font-size:12px; margin-top:1px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.peer-stats{ display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:14px; }
.peer-stat{ background:var(--panel-2); border:1px solid var(--border-soft); border-radius:10px; padding:9px 11px; }
.peer-stat-label{ color:var(--muted-2); font-size:10.5px; text-transform:uppercase; letter-spacing:.05em; margin-bottom:3px; display:flex; align-items:center; gap:5px; }
.peer-stat-label svg{ width:11px; height:11px; fill:none; stroke:currentColor; stroke-width:2; }
.peer-stat-value{ font-family:'IBM Plex Mono',monospace; font-size:13px; font-weight:600; }
.peer-actions{ display:flex; gap:6px; flex-wrap:wrap; }
.peer-corner{ position:absolute; top:16px; right:18px; z-index:2; }

/* ------------------------------------------------------------------ table */
table{ width:100%; border-collapse:collapse; }
th{
  text-align:left; font-size:10.5px; text-transform:uppercase; letter-spacing:.06em;
  color:var(--muted-2); font-weight:700; padding:11px 14px; border-bottom:1px solid var(--border-soft);
}
td{ padding:13px 14px; border-bottom:1px solid var(--border-soft); font-size:13.5px; vertical-align:middle; }
tr:last-child td{ border-bottom:none; }
tr{ transition:background .12s ease; }
tr:hover td{ background:rgba(255,255,255,.018); }

/* ------------------------------------------------------------------ badges */
.badge{
  display:inline-flex; align-items:center; gap:6px;
  padding:4px 10px; border-radius:99px; font-size:11.5px; font-weight:700;
}
.badge.on{ background:var(--ok-bg); color:var(--accent); }
.badge.off{ background:var(--danger-bg); color:var(--danger); }
.badge .dot{ width:6px; height:6px; border-radius:50%; background:currentColor; box-shadow:0 0 6px currentColor; }
.badge.on .dot{ animation:pulse 2s ease-in-out infinite; }
@keyframes pulse{ 0%,100%{ opacity:1; } 50%{ opacity:.35; } }

.wan-badge{
  display:inline-flex; align-items:center;
  font-family:'IBM Plex Mono',monospace; font-size:16px; font-weight:700;
  padding:5px 14px; border-radius:99px; background:var(--panel-2); border:1px solid var(--border);
  color:var(--text);
}

.route-grid{ display:grid; grid-template-columns:repeat(auto-fit, minmax(240px,1fr)); gap:14px; }
.route-block{ background:var(--panel-2); border:1px solid var(--border-soft); border-radius:12px; padding:16px 18px; }
.route-block-label{
  display:flex; align-items:center; gap:8px;
  font-size:11.5px; font-weight:700; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); margin-bottom:6px;
}
.route-dot{ width:7px; height:7px; border-radius:50%; background:currentColor; flex-shrink:0; }
.route-block-arrow{ font-size:13px; color:var(--muted-2); margin-bottom:10px; }
.route-block-value{ font-size:19px; font-weight:700; overflow-wrap:break-word; word-break:break-word; }
.route-block.route-ru .route-block-label, .route-block.route-ru .route-dot{ color:var(--ru); }
.route-block.route-foreign .route-block-label, .route-block.route-foreign .route-dot{ color:var(--accent); }

/* ------------------------------------------------------------------ buttons */
.btn{
  display:inline-flex; align-items:center; gap:6px;
  background:var(--panel-hover); color:var(--text);
  border:1px solid var(--border); border-radius:10px; padding:8px 15px;
  font-family:'Inter',sans-serif; font-size:13px; font-weight:600;
  cursor:pointer;
  transition:border-color .15s ease, background .15s ease, transform .08s ease, filter .15s ease;
}
.btn:hover{ border-color:#333B4E; background:#1B202B; text-decoration:none; }
.btn:active{ transform:translateY(1px); }
.btn.primary{ background:var(--grad); color:#04120F; border-color:transparent; font-weight:700; }
.btn.primary:hover{ filter:brightness(1.08); }
.btn.danger{ background:transparent; color:var(--danger); border-color:var(--danger-bg); }
.btn.danger:hover{ background:var(--danger-bg); }
.btn.small{ padding:5px 11px; font-size:12px; border-radius:8px; }
.btn svg{ width:14px; height:14px; fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; }

.toolbar{ display:flex; justify-content:space-between; align-items:center; margin-bottom:20px; gap:16px; flex-wrap:wrap; }

form.inline{ display:inline; }

/* -------------------------------------------------------------------- forms */
input[type=text], input[type=password], textarea, select{
  width:100%; background:var(--panel-2); border:1px solid var(--border); color:var(--text);
  border-radius:10px; padding:10px 13px; font-family:'Inter',sans-serif; font-size:14px;
  transition:border-color .15s ease, box-shadow .15s ease;
}
input[type=text]:focus, input[type=password]:focus, textarea:focus, select:focus{
  outline:none; border-color:var(--accent); box-shadow:0 0 0 3px rgba(34,211,184,.15);
}
textarea{ font-family:'IBM Plex Mono',monospace; font-size:13px; min-height:260px; resize:vertical; }
label{ display:block; font-size:12px; color:var(--muted); font-weight:600; margin:16px 0 6px; text-transform:uppercase; letter-spacing:.04em; }
label:first-child{ margin-top:0; }

.panel{ background:var(--panel); border:1px solid var(--border); border-radius:var(--radius); padding:26px; max-width:640px; box-shadow:var(--shadow); }

.search-box{ position:relative; max-width:340px; }
.search-box svg{ position:absolute; left:13px; top:50%; transform:translateY(-50%); width:15px; height:15px; stroke:var(--muted-2); fill:none; stroke-width:2; }
.search-box input{ padding-left:36px; }

/* -------------------------------------------------------------------- login */
.login-wrap{ min-height:100vh; display:flex; align-items:center; justify-content:center; background:var(--bg); background-image:var(--bg-hero); }
.login-card{ width:360px; background:var(--panel); border:1px solid var(--border); border-radius:20px; padding:36px; box-shadow:var(--shadow-lg); }
.login-card h1{ margin-bottom:6px; display:flex; align-items:center; gap:10px; }
.login-card h1 .brand-dot{ width:12px; height:12px; border-radius:5px; }
.error{ background:var(--danger-bg); color:var(--danger); padding:11px 14px; border-radius:10px; font-size:13px; margin-bottom:16px; font-weight:500; white-space:pre-wrap; }
.success{ background:var(--ok-bg); color:var(--accent); padding:11px 14px; border-radius:10px; font-size:13px; margin-bottom:16px; font-weight:500; white-space:pre-wrap; }

.pill{ display:inline-block; padding:3px 9px; border-radius:99px; font-size:11px; font-weight:600; background:var(--panel-2); color:var(--muted); border:1px solid var(--border); }
.pill.active{ background:var(--ok-bg); color:var(--accent); border-color:transparent; }
.pill.info{ background:rgba(59,130,246,.13); color:var(--accent-2); border-color:transparent; }
.pill.warn{ background:var(--ru-bg); color:var(--ru); border-color:transparent; }

.filter-bar{ display:flex; align-items:center; gap:18px; flex-wrap:wrap; margin-bottom:20px; }
.filter-group{ display:flex; align-items:center; gap:6px; }
.filter-group-label{ color:var(--muted-2); font-size:11.5px; font-weight:600; text-transform:uppercase; letter-spacing:.05em; margin-right:2px; }
.chip{
  display:inline-flex; align-items:center; gap:5px;
  padding:6px 13px; border-radius:99px; border:1px solid var(--border);
  background:var(--panel); color:var(--muted); font-size:12.5px; font-weight:600;
  cursor:pointer; transition:all .15s ease; user-select:none;
}
.chip:hover{ border-color:#333B4E; color:var(--text); }
.chip.selected{ background:var(--grad); border-color:transparent; color:#04120F; }

.muted{ color:var(--muted); }
.qr-box{ background:#fff; padding:14px; border-radius:14px; display:inline-block; }
.actions-row{ display:flex; gap:10px; margin-top:20px; flex-wrap:wrap; }
.tabs{ display:flex; gap:4px; margin-bottom:18px; border-bottom:1px solid var(--border-soft); }
.tabs a{ padding:8px 4px; margin-right:20px; color:var(--muted); font-size:13px; border-bottom:2px solid transparent; font-weight:600; }
.tabs a.active{ color:var(--text); border-bottom-color:var(--accent); }

.empty-state{ text-align:center; padding:48px 20px; color:var(--muted); }
.empty-state svg{ width:40px; height:40px; stroke:var(--muted-2); fill:none; stroke-width:1.5; margin-bottom:14px; }

.mini-bar{ height:5px; border-radius:99px; background:var(--panel-2); overflow:hidden; margin-top:8px; }
.mini-bar-fill{ height:100%; background:var(--grad); border-radius:99px; transition:width .4s ease; }

.live-dot{
  display:inline-block; width:7px; height:7px; border-radius:50%;
  background:var(--accent); box-shadow:0 0 6px var(--accent);
  animation:pulse 2s ease-in-out infinite; vertical-align:middle; margin-left:4px;
}

.table-scroll{ overflow-x:auto; -webkit-overflow-scrolling:touch; }
.table-scroll table{ min-width:600px; }

/* ===================================================================== */
/* Мобильная адаптация                                                    */
/* ===================================================================== */
.mobile-nav-toggle{
  display:none; align-items:center; justify-content:center;
  width:34px; height:34px; border-radius:9px; background:var(--panel-hover);
  border:1px solid var(--border); color:var(--text); cursor:pointer; flex-shrink:0;
}
.mobile-nav-toggle svg{ width:18px; height:18px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; }

@media (max-width: 860px){
  .layout{ flex-direction:column; }
  .sidebar{
    width:100%; padding:0; position:sticky; top:0; z-index:30;
    background:var(--panel-2); border-right:none; border-bottom:1px solid var(--border-soft);
  }
  .brand{
    padding:12px 16px; border-bottom:none; margin-bottom:0;
    justify-content:space-between; flex-wrap:nowrap;
  }
  .brand small{ display:none; }
  .mobile-nav-toggle{ display:flex; }
  .nav{ display:none; flex-direction:column; padding:4px 10px 14px; }
  .nav.open{ display:flex; }
  .main{ padding:20px 16px 40px; }
  h1{ font-size:19px; }
  .stat-row{ gap:10px; }
  .stat-row .card{ min-width:148px; padding:14px 16px; }
  .stat-value{ font-size:18px; }
  .peer-grid{ grid-template-columns:1fr; }
  .grid{ grid-template-columns:1fr; }
  .route-grid{ grid-template-columns:1fr; }
  .toolbar{ flex-direction:column; align-items:flex-start; gap:12px; }
  .toolbar > a, .toolbar > .btn{ width:100%; justify-content:center; }
  .filter-bar{ flex-direction:column; align-items:flex-start; gap:10px; }
  .search-box{ max-width:100%; }
  .panel{ max-width:100%; }
  .login-card{ width:calc(100vw - 40px); max-width:360px; }
}
