*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, sans-serif; background: #f0f2f5; color: #222; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

/* ── App shell ─────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-rows: 48px 1fr;
  grid-template-columns: 280px 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  min-height: 100vh;
}
.app-shell--noauth {
  grid-template-columns: 1fr;
  grid-template-areas: "header" "main";
}

/* ── Header ──────────────────────────────────────────────────────────── */
.app-header {
  grid-area: header;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 1.25rem;
  background: #1a1a2e; color: #fff;
  position: sticky; top: 0; z-index: 100;
}
.app-logo { color: #adf; text-decoration: none; font-weight: 700; font-size: 1rem; letter-spacing: .03em; }
.app-logo:hover { color: #cef; }
.header-meta { display: flex; align-items: center; gap: 1.25rem; }
.disk-stat { color: #aac8ff; font-size: .8rem; white-space: nowrap; }
.disk-stat span { color: #fff; font-weight: 600; margin-left: .3rem; }
.version-badge { color: #7a9cc8; font-size: .75rem; opacity: .8; font-variant-numeric: tabular-nums; }
.header-logout { color: #adf; text-decoration: none; font-size: .85rem; }
.header-logout:hover { color: #cef; }

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: #1e2235;
  padding: .5rem 0;
  overflow-y: auto;
  height: calc(100vh - 48px);
  position: sticky; top: 48px;
  width: 280px;
}

.nav-group { border-bottom: 1px solid #2a2f4a; }

.nav-group-title {
  display: flex; align-items: center; gap: .45rem;
  width: 100%; padding: .55rem .9rem;
  background: none; border: none; color: #8899bb;
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; cursor: pointer; text-align: left;
  line-height: 1.3;
}
.nav-group-title:hover { background: #252c47; color: #adc4f0; }
.nav-icon { font-size: .95rem; flex-shrink: 0; }
.nav-arrow { margin-left: auto; font-size: .65rem; transition: transform .2s; flex-shrink: 0; }

.nav-items { display: none; list-style: none; padding: .1rem 0 .35rem; }
.nav-group--open .nav-items { display: block; }
.nav-group--open .nav-arrow { transform: rotate(0deg); }
.nav-group:not(.nav-group--open) .nav-arrow { transform: rotate(-90deg); }

.nav-link {
  display: block; padding: .34rem .9rem .34rem 2rem;
  color: #8faad4; text-decoration: none; font-size: .82rem;
  line-height: 1.35; word-break: break-word;
}
.nav-link:hover { color: #d0e4ff; background: #252c47; }
.nav-link--active { color: #fff !important; background: #2f3b62 !important; border-left: 3px solid #5b8cf5; padding-left: calc(2rem - 3px); }
.nav-link--stub { opacity: .6; }
.nav-link--stub:hover { opacity: .85; }
.nav-link--planned::after { content: " ·"; color: #5b7db3; font-size: .7rem; }

/* Подгруппа навигации (напр. Telegram Bot) */
.nav-subgroup { list-style: none; }
.nav-subgroup-title {
  display: block; padding: .34rem .9rem .34rem 2rem;
  color: #6b88b8; font-size: .82rem; font-weight: 600;
  letter-spacing: .02em; cursor: default;
}
.nav-subitems { list-style: none; padding: 0; }
.nav-subitems .nav-link { padding-left: 2.8rem; font-size: .8rem; }
.nav-subitems .nav-link--active { padding-left: calc(2.8rem - 3px); }

/* ── Hamburger toggle (mobile only) ─────────────────────────────────── */
.sidebar-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: none; border: none; color: #adf;
  cursor: pointer; font-size: 1.4rem; padding: 0;
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0; top: 48px;
  background: rgba(0,0,0,.55); z-index: 199;
}
.sidebar-overlay--open { display: block; }

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "header" "main";
  }
  .sidebar {
    position: fixed;
    left: -280px;
    top: 48px;
    z-index: 200;
    height: calc(100vh - 48px);
    transition: left .22s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.45);
  }
  .sidebar--open { left: 0; }
  .sidebar-toggle { display: flex; }
}

/* ── Main content ────────────────────────────────────────────────────── */
.app-main { grid-area: main; padding: 1.5rem 1.75rem; min-width: 0; }

/* Legacy selectors kept for backward compat */
header { display: none; }
main { padding: 0; }
form#filters, form#url-filters, form#credential-filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end;
               background: #fff; padding: 1rem; border-radius: 8px;
               box-shadow: 0 1px 4px rgba(0,0,0,.1); margin-bottom: 1.5rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: 1rem; }
label { display: flex; flex-direction: column; font-size: .85rem; gap: .25rem; }
input, select { padding: .4rem .6rem; border: 1px solid #ccc; border-radius: 4px; font-size: .9rem; }
button { padding: .45rem 1rem; background: #1a1a2e; color: #fff; border: none;
         border-radius: 4px; cursor: pointer; font-size: .9rem; }
button:hover { background: #2d2d5e; }
.button-link { display: inline-block; padding: .45rem 1rem; color: #fff; border-radius: 4px;
               text-decoration: none; font-size: .9rem; line-height: normal; }
.btn-secondary { background: #888; }
.btn-secondary:hover { background: #666; }
.btn-danger { background: #b42318; }
.btn-danger:hover { background: #8f1d15; }
.btn-active { background: #2563eb !important; }
.btn-active:hover { background: #1d4ed8 !important; }
.btn-chip { padding: .25rem .55rem; background: #eef1f4; color: #222; border: 1px solid #d4d8dd;
            font-size: .78rem; line-height: 1.2; }
.btn-chip:hover { background: #dde4ea; }
.grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
section { background: #fff; padding: 1.25rem; border-radius: 8px;
          box-shadow: 0 1px 4px rgba(0,0,0,.1); }
h2 { font-size: 1rem; margin-bottom: 1rem; color: #555; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .75rem; border-bottom: 1px solid #eee; }
th { background: #f0f0f0; font-weight: 600; }
ol { padding-left: 1.25rem; }
li { padding: .35rem 0; font-size: .9rem; }
.login-box { max-width: 340px; margin: 4rem auto; background: #fff;
             padding: 2rem; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.login-box h2 { margin-bottom: 1.25rem; }
.login-box label { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.error { color: #c00; margin-bottom: 1rem; font-size: .9rem; }
/* Time range slider */
.time-range { display: flex; flex-direction: column; gap: .35rem; min-width: 260px; flex: 1; }
.chart-select-wrap { position: relative; min-height: 260px; height: 260px; }
.chart-select-wrap canvas { cursor: crosshair; }
.chart-selection {
  position: absolute; pointer-events: none; z-index: 5;
  border: 1px solid rgba(26,26,46,.55);
  background: rgba(26,26,46,.12);
}
.quick-ranges { display: flex; gap: .35rem; flex-wrap: wrap; }
.time-labels { display: flex; justify-content: space-between; font-size: .8rem; color: #555; }
.slider-wrap { position: relative; height: 28px; }
.slider-wrap input[type=range] {
  position: absolute; left: 0; right: 0; width: 100%;
  -webkit-appearance: none; appearance: none;
  background: transparent; pointer-events: none;
}
.slider-wrap input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: #1a1a2e; cursor: pointer; pointer-events: auto;
  border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.slider-wrap input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #1a1a2e; cursor: pointer; pointer-events: auto; border: none;
}
.slider-wrap::before {
  content: ''; position: absolute; top: 50%; transform: translateY(-50%);
  left: 0; right: 0; height: 4px; background: #ddd; border-radius: 2px;
}
@media (max-width: 700px) { .grid { grid-template-columns: 1fr; } }
@media (max-width: 1100px) {
  header { align-items: flex-start; flex-direction: column; gap: .65rem; }
  .disk-stat { margin-left: 0; }
  header nav { flex-wrap: wrap; gap: .85rem !important; }
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #e4e4e4; }
.hint { color: #666; font-size: .85rem; margin: -.35rem 0 1rem; }
.url-cell { max-width: 680px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.url-cell a { color: #1a4f8b; text-decoration: none; }
.url-cell a:hover { text-decoration: underline; }
.url-referer { color: #777; font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.url-flags { white-space: nowrap; min-width: 90px; }
.badge { display: inline-block; font-size: .7rem; padding: .1rem .4rem; border-radius: 3px;
         font-weight: 600; vertical-align: middle; margin-left: .3rem; }
.badge-auto_system { background: #e8e0f7; color: #6b35cc; }
.badge-manual_system { background: #fde8c8; color: #b36000; }
.badge-normal { background: #d4f0d4; color: #267326; }
.badge-manual { background: #fde8c8; color: #b36000; }
.badge-password { background: #fde2e1; color: #a21c13; }
.badge-tracker { background: #fde2e2; color: #a12a2a; }
.category-badge {
  display: inline-block; min-width: 64px; padding: .14rem .42rem;
  border-radius: 3px; font-size: .72rem; font-weight: 650;
  text-align: center; text-transform: uppercase;
}
.category-news { background: #dbeafe; color: #1d4ed8; }
.category-adult { background: #fee2e2; color: #991b1b; }
.category-dating { background: #fce7f3; color: #9d174d; }
.category-office { background: #dcfce7; color: #166534; }
.category-ads { background: #fef3c7; color: #92400e; }
.category-unknown { background: #f1f5f9; color: #64748b; font-weight: 500; }
.muted { color: #666; font-size: .85rem; }
.btn-sm { padding: .2rem .5rem; font-size: .8rem; }
.btn-link { color: #1a1a2e; font-size: .9rem; }
.btn-xs { padding: .1rem .35rem; font-size: .75rem; line-height: 1.2; }
/* multi-select dropdown */
.ms-wrap { position: relative; display: block; }
.ms-btn { display: flex; justify-content: space-between; align-items: center;
  width: 100%; padding: .4rem .6rem; font-size: .9rem; cursor: pointer;
  background: #fff; color: #222; border: 1px solid #ccc; border-radius: 4px;
  user-select: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ms-btn:hover { background: #f5f5f5; }
.ms-panel { display: none; position: absolute; top: calc(100% + 2px); left: 0; z-index: 500;
  background: #fff; border: 1px solid #ccc; border-radius: 4px; min-width: 150px;
  max-height: 240px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.ms-wrap.ms-open .ms-panel { display: block; }
.ms-panel label { display: flex; align-items: center; gap: .5rem; padding: .4rem .7rem;
  font-size: .88rem; cursor: pointer; white-space: nowrap; font-weight: normal; }
.ms-panel label:hover { background: #f0f4ff; }
.ms-panel input[type=checkbox] { margin: 0; cursor: pointer; accent-color: #1a1a2e; }
.maintenance-panel { margin: -0.5rem 0 1.5rem; border-left: 4px solid #b42318; }
.maintenance-panel summary { cursor: pointer; font-weight: 600; color: #555; }
.delete-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-top: .75rem; }
.delete-tools p { color: #666; font-size: .85rem; flex-basis: 100%; }
.delete-status { font-size: .9rem; color: #444; min-width: 260px; flex: 1; }
.delete-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
#delete-confirm { width: 130px; }

/* Column facet filter button in table headers */
th { position: relative; }
.col-filter-btn {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: .7rem;
  padding: .1rem .25rem;
  margin-left: .25rem;
  border-radius: 3px;
  vertical-align: middle;
  opacity: .6;
  line-height: 1;
}
.col-filter-btn:hover, .col-filter-btn.col-filter-active { opacity: 1; background: rgba(255,255,255,.15); }
.col-filter-active { color: #7dd3fc; }
.col-filter-badge {
  display: inline-block;
  background: #facc15;
  color: #1a1a2e;
  border-radius: 8px;
  font-size: .65rem;
  padding: 0 .3rem;
  margin-right: .2rem;
  font-weight: 700;
  line-height: 1.4;
  vertical-align: middle;
}

/* Column filter dropdown */
.col-filter-dropdown {
  position: absolute;
  z-index: 2000;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.15);
  min-width: 180px;
  max-height: 340px;
  overflow-y: auto;
  padding: .5rem 0;
}
.col-filter-dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .4rem .75rem;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: .25rem;
}
.col-filter-clear { font-size: .8rem; color: #6b7280; text-decoration: none; }
.col-filter-clear:hover { color: #b42318; }
.col-filter-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .3rem .75rem;
  cursor: pointer;
  font-size: .85rem;
  font-weight: normal;
}
.col-filter-item:hover { background: #f3f4f6; }
.col-filter-item input[type=checkbox] { margin: 0; accent-color: #2563eb; }
.col-filter-count { margin-left: auto; color: #9ca3af; font-size: .78rem; }
.col-filter-empty { padding: .5rem .75rem; color: #9ca3af; font-size: .85rem; }

/* Filterable cells */
.filterable-cell { cursor: pointer; }
.filterable-cell:hover { background: #f0f9ff; }
.cell-filter-active { background: #dbeafe !important; font-weight: 600; }
