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

:root {
  --bg: #0b0d12;
  --bg-elev: #131720;
  --bg-elev-2: #1a1f2c;
  --fg: #e7eaf0;
  --fg-mut: #8b94a6;
  --fg-dim: #5a6275;
  --line: #232838;
  --line-soft: #1c2030;
  --acc: #6f8cff;
  --acc-glow: rgba(111,140,255,.18);
  --ok: #3ddc97;
  --ok-bg: rgba(61,220,151,.13);
  --warn: #ffb454;
  --warn-bg: rgba(255,180,84,.13);
  --bad: #ff5d6c;
  --bad-bg: rgba(255,93,108,.14);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 'Inter', -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* Layout: sidebar + main */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

aside.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #6f8cff, #b56bff);
  display: grid; place-items: center; font-weight: 700; color: white; font-size: 14px;
  box-shadow: 0 4px 14px var(--acc-glow);
}
.brand .name { font-weight: 600; font-size: 15px; letter-spacing: .2px; }
.brand .sub { font-size: 11px; color: var(--fg-mut); }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.nav .group-title { color: var(--fg-dim); font-size: 11px; font-weight: 600; padding: 14px 10px 6px; text-transform: uppercase; letter-spacing: .8px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  color: var(--fg-mut); text-decoration: none; padding: 9px 10px;
  border-radius: var(--radius-sm); font-weight: 500;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--bg-elev-2); color: var(--fg); }
.nav a.active { background: var(--acc-glow); color: var(--acc); }
.nav a .ico { width: 18px; height: 18px; opacity: .9; flex-shrink: 0; }

.sidebar-foot {
  position: sticky; bottom: 0; padding-top: 10px; margin-top: 14px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px; color: var(--fg-mut); display: flex; justify-content: space-between; align-items: center;
}
.sidebar-foot a { color: var(--fg-mut); text-decoration: none; }
.sidebar-foot a:hover { color: var(--fg); }

main.content { padding: 24px 28px 60px; max-width: 100%; min-width: 0; }
@media (max-width: 900px) { main.content { padding: 18px; } }

/* Typography */
h1 { font-size: 22px; font-weight: 600; margin: 0 0 14px; letter-spacing: -.2px; }
h2 { font-size: 17px; font-weight: 600; margin: 22px 0 10px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 10px; color: var(--fg); }
.muted, small { color: var(--fg-mut); }
.kbd, code { font-family: 'JetBrains Mono', ui-monospace, Menlo, monospace; background: var(--bg-elev-2); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; color: #c4cad6; }

/* Cards */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 0 0 16px;
  box-shadow: var(--shadow);
}
.card h3 { margin-top: 0; }

/* Tables */
.table-wrap { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; overflow-y: visible; box-shadow: var(--shadow); -webkit-overflow-scrolling: touch; }
table { width: 100%; min-width: max-content; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 14px; text-align: left; vertical-align: middle; }
th {
  color: var(--fg-mut); font-weight: 500; font-size: 12px;
  background: var(--bg-elev-2); text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1;
}
tbody tr { border-top: 1px solid var(--line-soft); transition: background .12s; }
tbody tr:hover { background: rgba(255,255,255,.02); }
tbody tr:first-child { border-top: 0; }

/* Forms */
input[type=text], input[type=password], input[type=email], input[type=file], textarea, select {
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font: inherit;
  width: 100%;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--acc); box-shadow: 0 0 0 3px var(--acc-glow); }
textarea { min-height: 130px; font-family: 'JetBrains Mono', monospace; font-size: 13px; }
input[type=file] { padding: 7px 10px; }
label { display: block; font-size: 12px; color: var(--fg-mut); margin-bottom: 6px; font-weight: 500; }
.field { margin-bottom: 12px; }

/* Buttons */
button, .btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(180deg, #7693ff, #5e7eff);
  color: white; border: 1px solid #4f6ee0;
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer;
  font: inherit; font-weight: 500; line-height: 1;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.12);
  transition: transform .08s, filter .15s;
}
button:hover, .btn:hover { filter: brightness(1.07); }
button:active { transform: translateY(1px); }
button.ghost, .btn.ghost {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--line);
  box-shadow: none;
}
button.ghost:hover { background: var(--bg-elev-2); border-color: #2f3548; }
button.danger { background: linear-gradient(180deg, #ff7585, #e95564); border-color: #c84050; }
form.inline { display: inline; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--bg-elev-2);
  color: var(--fg-mut);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: .2px;
  border: 1px solid var(--line);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.acc { background: var(--acc-glow); color: var(--acc); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

/* Layout helpers */
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 180px; }
.row.tight { gap: 8px; }
.spacer { flex: 1; }
.right { margin-left: auto; }

/* Stats / totals */
.totals {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px;
}
.stat {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--fg-mut); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; font-weight: 600; }
.stat .value { font-size: 22px; font-weight: 600; margin-top: 4px; letter-spacing: -.5px; }
.stat .hint { font-size: 11.5px; color: var(--fg-dim); margin-top: 2px; }

/* Header inside main */
.page-header { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.page-header h1 { margin: 0; }
.page-header .crumb { color: var(--fg-mut); }
.page-header a { color: var(--fg-mut); text-decoration: none; }
.page-header a:hover { color: var(--fg); }

/* Pre / details */
pre {
  background: #07090d; color: #d6dae3; border: 1px solid var(--line);
  padding: 12px; border-radius: var(--radius-sm); overflow: auto; font-size: 12px;
  font-family: 'JetBrains Mono', monospace; max-height: 480px;
}
details summary { cursor: pointer; color: var(--acc); user-select: none; padding: 6px 0; }
details[open] summary { margin-bottom: 8px; }

/* Login page */
.login-shell {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -20%, rgba(111,140,255,.12), transparent 60%), var(--bg);
}
.login-card { width: 360px; max-width: calc(100vw - 32px); }

/* Empty states */
.empty {
  text-align: center; padding: 40px 20px; color: var(--fg-mut);
  background: var(--bg-elev); border: 1px dashed var(--line); border-radius: var(--radius);
}
a { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─────────────────────────────────────────────────────────────
   Мобильные стили (планшет / телефон).
   Логику не трогаем — только перекладываем верстку.
   ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  /* Сайдбар становится верхней панелью с горизонтальной прокруткой меню.
     Главное — убрать height:100vh, иначе он закрывает контент. */
  aside.sidebar {
    position: sticky; top: 0; z-index: 50;
    height: auto;
    padding: 10px 12px;
    border-right: none;
    border-bottom: 1px solid var(--line);
    overflow: visible;
    box-shadow: 0 2px 10px rgba(0,0,0,.3);
  }
  .brand { padding: 0 0 8px; gap: 8px; }
  .brand .logo { width: 28px; height: 28px; font-size: 12px; }
  .brand .name { font-size: 14px; }
  .brand .sub { font-size: 10px; }

  /* Меню — горизонтальный скролл с чипами */
  .nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    margin-top: 0;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }
  .nav::-webkit-scrollbar { height: 4px; }
  .nav::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }
  .nav .group-title { display: none; }
  .nav a {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 12.5px;
    border: 1px solid var(--line);
    white-space: nowrap;
  }
  .nav a .ico { width: 15px; height: 15px; }

  .sidebar-foot {
    position: static;
    margin: 8px 0 0;
    padding: 6px 0 0;
    font-size: 11px;
  }

  /* Main: тоньше padding'и */
  main.content { padding: 14px 12px 80px; max-width: 100%; }

  /* Типографика — чуть мельче */
  h1 { font-size: 19px; margin-bottom: 10px; }
  h2 { font-size: 15px; margin: 16px 0 8px; }
  body { font-size: 13.5px; }

  /* Card: менее объёмный */
  .card { padding: 12px 14px; margin-bottom: 12px; }

  /* Таблицы: горизонтальный скролл (override `overflow:hidden`) */
  .table-wrap { overflow-x: auto; overflow-y: visible; -webkit-overflow-scrolling: touch; }
  th, td { padding: 8px 10px; font-size: 12.5px; }
  th { position: static; }  /* sticky+overflow-x = баг на iOS, отключаем */

  /* .row: на телефоне всё стэкается вертикально */
  .row { flex-direction: column; gap: 8px; }
  .row > * { min-width: 0; width: 100%; flex: 1 1 auto; }

  /* Кнопки — крупнее для тапа */
  button, .btn { padding: 11px 14px; font-size: 13.5px; min-height: 40px; }
  button.ghost, .btn.ghost { padding: 9px 12px; min-height: 36px; }

  /* Шапка раздела — перенос на 2 строки */
  .page-header { flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

  /* Stats: компактнее */
  .totals { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-bottom: 12px; }
  .stat { padding: 10px 12px; }
  .stat .value { font-size: 18px; }

  /* Pre / pre logs — ограничиваем высоту, иначе телефон будет бесконечно скроллить */
  pre { max-height: 260px; font-size: 11px; padding: 8px; }

  /* Логин-страница: карточка во всю ширину минус padding */
  .login-card { width: 100%; max-width: 360px; padding: 18px; }
}

/* Совсем узкий телефон (портрет до 480px) */
@media (max-width: 480px) {
  main.content { padding: 12px 8px 80px; }
  h1 { font-size: 17px; }
  .card { padding: 10px 12px; }
  .totals { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .stat { padding: 8px 10px; }
  .stat .value { font-size: 16px; }
  .stat .label { font-size: 10px; }
  th, td { padding: 7px 8px; font-size: 12px; }
  .badge { padding: 2px 7px; font-size: 11px; }
  /* Гасим title-крошки в шапке, чтобы заголовок не съезжал */
  .page-header .crumb { font-size: 11px; }
}
