:root,
html[data-theme="dark"] {
  --bg: #0e1117;
  --bg-elevated: #161b22;
  --bg-card: #1c2128;
  --bg-hover: #22272e;
  --border: #30363d;
  --border-soft: #21262d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #6e7681;
  --accent: #2f81f7;
  --accent-soft: rgba(47, 129, 247, 0.15);
  --green: #3fb950;
  --green-soft: rgba(63, 185, 80, 0.15);
  --orange: #d29922;
  --orange-soft: rgba(210, 153, 34, 0.15);
  --red: #f85149;
  --purple: #a371f7;
  --purple-soft: rgba(163, 113, 247, 0.15);
  --cyan: #39d2c0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --nav-h: 60px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --nav-bg: rgba(22, 27, 34, 0.92);
  --input-bg: #0e1117;
  --code-bg: #0e1117;
}

html[data-theme="light"] {
  --bg: #f6f8fa;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eef2f6;
  --border: #d0d7de;
  --border-soft: #eaeef2;
  --text: #1f2328;
  --text-muted: #656d76;
  --text-dim: #8b949e;
  --accent: #0969da;
  --accent-soft: rgba(9, 105, 218, 0.12);
  --green: #1a7f37;
  --green-soft: rgba(26, 127, 55, 0.12);
  --orange: #9a6700;
  --orange-soft: rgba(154, 103, 0, 0.12);
  --red: #cf222e;
  --purple: #8250df;
  --purple-soft: rgba(130, 80, 223, 0.12);
  --cyan: #1192aa;
  --shadow: 0 8px 24px rgba(31, 35, 40, 0.08);
  --nav-bg: rgba(255, 255, 255, 0.92);
  --input-bg: #f6f8fa;
  --code-bg: #eef2f6;
}

html[data-theme="light"] .topnav {
  background: var(--nav-bg);
}

html[data-theme="light"] .input,
html[data-theme="light"] .select {
  background: var(--input-bg);
  color: var(--text);
}

html[data-theme="light"] .brand-sub {
  color: var(--text-muted);
}

html[data-theme="light"] .theme-icon-moon { display: none; }
html[data-theme="light"] .theme-icon-sun { display: inline; }
html[data-theme="dark"] .theme-icon-moon { display: inline; }
html[data-theme="dark"] .theme-icon-sun { display: none; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  transition: 0.15s ease;
}

.theme-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--text-dim);
}

.theme-icon {
  pointer-events: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 15px;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
}

button,
.btn,
.nav-link,
.nav-toggle,
.theme-toggle {
  touch-action: manipulation;
}

/* ===== NAV ===== */
.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 max(1.25rem, env(safe-area-inset-right)) 0 max(1.25rem, env(safe-area-inset-left));
  background: var(--nav-bg, rgba(22, 27, 34, 0.92));
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topnav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: -0.01em;
  min-width: 0;
  flex: 0 1 auto;
}

.topnav-brand:hover {
  text-decoration: none;
  color: #fff;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2f81f7, #a371f7);
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.brand-mark .nav-ico {
  width: 18px;
  height: 18px;
  color: #fff;
}

.brand-text {
  min-width: 0;
}

.brand-sub {
  display: block;
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: -2px;
}

.topnav-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.topnav-menu {
  display: flex;
  align-items: center;
  gap: 0.35rem 0.15rem;
  min-width: 0;
}

.topnav-menu-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-left: 0.35rem;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.nav-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--text-dim);
}

.nav-toggle-bar {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

body.nav-open .nav-toggle-bar:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

body.nav-open .nav-toggle-bar:nth-child(2) {
  opacity: 0;
}

body.nav-open .nav-toggle-bar:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.nav-backdrop {
  display: none;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.nav-link:hover {
  color: var(--text);
  background: var(--bg-hover);
  text-decoration: none;
}

.nav-link.active {
  color: #fff;
  background: var(--accent-soft);
}

html[data-theme="light"] .nav-link.active {
  color: var(--accent);
}

.nav-ico {
  width: 1.05em;
  height: 1.05em;
  flex: 0 0 auto;
  display: block;
  color: currentColor;
}

.nav-caret {
  width: 0.72em;
  height: 0.72em;
  flex: 0 0 auto;
  margin-left: 0.05rem;
  opacity: 0.72;
  transition: transform 0.15s ease;
}

.nav-drop {
  position: relative;
}

.nav-drop-toggle {
  appearance: none;
  -webkit-appearance: none;
}

.nav-drop.is-open > .nav-drop-toggle .nav-caret,
.nav-drop:hover > .nav-drop-toggle .nav-caret {
  transform: rotate(180deg);
}

.nav-drop-menu {
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 0.12rem;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 220px;
  padding: 0.4rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 130;
}

.nav-drop.is-open > .nav-drop-menu {
  display: flex;
}

.nav-drop-menu .nav-link {
  width: 100%;
  justify-content: flex-start;
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
}

@media (hover: hover) and (pointer: fine) and (min-width: 1401px) {
  .nav-drop:hover > .nav-drop-menu,
  .nav-drop:focus-within > .nav-drop-menu {
    display: flex;
  }
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ===== LAYOUT ===== */
.page {
  max-width: 1280px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  padding: 1.5rem 1.25rem max(3rem, env(safe-area-inset-bottom));
  overflow-x: clip;
}

.page-wide {
  max-width: 1400px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: 0.3rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ===== BUTTONS ===== */
[hidden] {
  display: none !important;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.2;
}

.btn:hover {
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover {
  background: #388bfd;
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: #fff;
  border-color: var(--text-dim);
}

.btn-soft {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.btn-soft:hover {
  background: rgba(47, 129, 247, 0.25);
  color: #79b8ff;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
}

.btn-danger {
  background: rgba(248, 81, 73, 0.15);
  color: #ff7b72;
  border-color: rgba(248, 81, 73, 0.35);
}

.btn-danger:hover {
  background: rgba(248, 81, 73, 0.28);
  color: #ffa198;
  border-color: rgba(248, 81, 73, 0.5);
}

/* ===== SETTINGS ===== */
.settings-section {
  margin-bottom: 2rem;
}

.settings-form {
  margin-bottom: 0;
}

.settings-form-card {
  max-width: 920px;
}

.settings-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  align-items: start;
  min-width: 0;
}

.settings-form-grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.85rem 1rem;
  align-items: start;
}

.settings-form-grid-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.settings-form-grid-bind {
  grid-template-columns: 8rem minmax(0, 1fr) auto auto;
}

.settings-form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-soft);
}

.field-hint {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.field-checks {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.15rem;
}

.field-label-like {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

.check-label input {
  accent-color: var(--accent);
}

.code-inline {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.alert-ok {
  background: var(--green-soft);
  border: 1px solid rgba(63, 185, 80, 0.35);
  color: var(--green);
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}

.data-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.2);
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.td-strong {
  font-weight: 600;
}

.td-muted {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}

.td-entity {
  max-width: 220px;
  word-break: break-all;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.td-flags {
  white-space: nowrap;
}

.td-actions {
  white-space: nowrap;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  justify-content: flex-end;
}

.inline-form {
  display: inline;
}

.settings-legend {
  margin-top: 0.85rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.settings-danger-zone {
  margin-top: 2rem;
  max-width: 920px;
  padding: 1rem 1.1rem;
  border: 1px solid rgba(248, 81, 73, 0.3);
  border-radius: var(--radius);
  background: rgba(248, 81, 73, 0.06);
}

.settings-danger-zone h3 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  color: #ff7b72;
}

@media (max-width: 1100px) {
  .settings-form-grid-5 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 900px) {
  .settings-form-grid,
  .settings-form-grid-2,
  .settings-form-grid-bind {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  }
}

@media (max-width: 600px) {
  .settings-form-grid,
  .settings-form-grid-2,
  .settings-form-grid-5,
  .settings-form-grid-bind {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/* ===== CARDS / STATS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.75rem;
  min-width: 0;
}

.stats-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats-grid-6 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.stat-card::after {
  content: "";
  position: absolute;
  inset: 0 0 auto auto;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  opacity: 0.12;
  transform: translate(30%, -30%);
}

.stat-card.blue::after { background: var(--accent); }
.stat-card.green::after { background: var(--green); }
.stat-card.orange::after { background: var(--orange); }
.stat-card.purple::after { background: var(--purple); }
.stat-card.cyan::after { background: var(--cyan); }

a.stat-card-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

a.stat-card-link:hover {
  border-color: #484f58;
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
}

a.stat-card-link .stat-hint {
  color: var(--orange);
  font-weight: 600;
}

a.stat-card-link.cyan .stat-hint {
  color: var(--cyan);
}

.storage-card {
  border-color: rgba(57, 210, 192, 0.25);
}

.storage-card::after {
  background: var(--cyan);
}

.storage-bar {
  position: relative;
  margin-top: 0.65rem;
  height: 6px;
  border-radius: 99px;
  background: rgba(139, 148, 158, 0.18);
  overflow: hidden;
}

.storage-bar-disk {
  position: absolute;
  inset: 0 auto 0 0;
  background: rgba(139, 148, 158, 0.35);
  border-radius: 99px;
}

.storage-bar-media {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(90deg, var(--cyan), var(--accent));
  border-radius: 99px;
  min-width: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.stat-value {
  margin-top: 0.35rem;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.stat-hint {
  margin-top: 0.25rem;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ===== GROUP GRID ===== */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.section-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
  gap: 1rem;
}

.group-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  color: inherit;
}

.group-card:hover {
  border-color: #484f58;
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.group-card-priority {
  border-color: rgba(210, 153, 34, 0.55);
  box-shadow: 0 0 0 1px rgba(210, 153, 34, 0.15);
}

.group-card-priority:hover {
  border-color: rgba(210, 153, 34, 0.8);
}

.group-card-main {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  color: inherit;
  text-decoration: none;
}

.group-card-main:hover {
  text-decoration: none;
  color: inherit;
}

.group-card-top {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
}

.group-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent-soft), var(--purple-soft));
  color: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.group-name {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
}

.group-entity {
  margin: 0.2rem 0 0;
  color: var(--text-dim);
  font-size: 0.75rem;
  word-break: break-all;
}

.group-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.3;
}

.badge-blue { background: var(--accent-soft); color: #79b8ff; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-orange { background: var(--orange-soft); color: var(--orange); }
.badge-purple { background: var(--purple-soft); color: #d2a8ff; }
.badge-gray { background: rgba(139, 148, 158, 0.15); color: var(--text-muted); }

html[data-theme="light"] .badge-blue { color: #0969da; }
html[data-theme="light"] .badge-purple { color: #8250df; }
html[data-theme="light"] .badge-gray { background: rgba(175, 184, 193, 0.25); }

.group-stats-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border-soft);
}

.group-stats-row-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.gs-val-sm {
  font-size: 0.92rem !important;
}

.gs-item {
  text-align: center;
  color: inherit;
  text-decoration: none;
  border-radius: 8px;
  padding: 0.25rem 0.15rem;
}

a.gs-item:hover {
  background: var(--bg-hover);
  text-decoration: none;
  color: inherit;
}

a.gs-media:hover .gs-val {
  color: var(--orange);
}

.gs-val {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
}

.gs-lab {
  display: block;
  font-size: 0.68rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-top: 0.1rem;
}

.group-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.group-footer-actions {
  flex-wrap: wrap;
}

.group-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  justify-content: flex-end;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
}

.td-groups {
  max-width: 280px;
  font-size: 0.8rem;
  color: var(--text-muted);
  word-break: break-word;
}

.filters-grid-users {
  grid-template-columns: 1.6fr repeat(4, minmax(0, 1fr)) auto;
}

.users-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem 0.6rem;
  margin-bottom: 0.75rem;
}
.users-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.users-search {
  flex: 1 1 180px;
  min-width: 140px;
}
.users-toolbar .select {
  flex: 0 1 140px;
  min-width: 120px;
}
.users-source {
  flex: 1 1 220px !important;
  min-width: 180px !important;
}
.users-per-page {
  flex: 0 0 7.2rem !important;
  min-width: 7.2rem !important;
}
.users-chip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
}
.users-chip-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-right: 0.15rem;
}
.users-chip-sep {
  width: 1px;
  height: 1.1rem;
  background: var(--border);
  margin: 0 0.35rem;
}
.users-chip {
  display: inline-flex;
  cursor: pointer;
  margin: 0;
}
.users-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.users-chip span {
  display: inline-flex;
  align-items: center;
  padding: 0.14rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.35;
}
.users-chip input:checked + span {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}
.users-chip:hover span { border-color: var(--accent); }
.users-results-count {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
}
@media (max-width: 720px) {
  .users-toolbar .select { flex: 1 1 140px; }
  .users-chip-sep { display: none; }
}

.group-meta-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.25rem;
}

.group-about {
  margin: 0.45rem 0 0.55rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.msg-forward,
.msg-reply,
.msg-links {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin: 0.2rem 0 0.35rem;
}

.msg-forward {
  color: var(--orange);
}

.user-profile-head {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
  min-width: 0;
}

.user-avatar-lg {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  object-fit: cover;
  background: var(--bg-hover);
  border: 1px solid var(--border);
}

.user-avatar-lg.placeholder,
.user-avatar-sm.placeholder {
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
}

.user-avatar-sm {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
  display: inline-grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--bg-hover);
  border: 1px solid var(--border-soft);
}

.msg-card-album .msg-side {
  min-width: min(100%, 320px);
}

.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.4rem;
  margin: 0.45rem 0;
  max-width: 360px;
}

.album-cell {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  display: grid;
  place-items: center;
}

.album-cell img,
.album-cell video.album-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.album-file {
  font-size: 0.7rem;
  padding: 0.35rem;
  text-align: center;
  word-break: break-all;
}

.stats-grid-jobs {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.job-payload,
.job-result {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.75rem;
}

.text-err {
  color: #ff7b72;
}

.msg-links a {
  color: var(--cyan);
  word-break: break-all;
  font-size: 0.78rem;
}

.msg-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.jobs-live-bar {
  position: sticky;
  top: var(--nav-h);
  z-index: 90;
  background: rgba(47, 129, 247, 0.12);
  border-bottom: 1px solid rgba(47, 129, 247, 0.35);
  padding: 0.35rem 1.25rem;
  font-size: 0.8rem;
  text-align: center;
}

.jobs-live-bar a {
  color: #79b8ff;
  font-weight: 600;
  text-decoration: none;
}

.jobs-live-bar a:hover {
  text-decoration: underline;
}

.jobs-live-bar.is-busy {
  background: rgba(210, 153, 34, 0.12);
  border-color: rgba(210, 153, 34, 0.4);
}

.jobs-live-bar.is-busy a {
  color: var(--orange);
}

@media (max-width: 1100px) {
  .stats-grid[style*="repeat(5"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

.gallery-album-badge {
  position: absolute;
  top: 0.45rem;
  left: 0.45rem;
  z-index: 2;
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

/* ===== FILTERS ===== */
.filters {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1.25rem;
}

.filters-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) repeat(5, minmax(0, 1fr));
  gap: 0.65rem;
  align-items: end;
  min-width: 0;
}

.field {
  min-width: 0;
}

.field label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.input,
.select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  font: inherit;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus,
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input::placeholder {
  color: var(--text-dim);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b949e'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  padding-right: 2rem;
}

.filters-actions {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.25rem;
  grid-column: 1 / -1;
  justify-content: flex-start;
}

/* ===== MESSAGES ===== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.result-count {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.result-count strong {
  color: var(--text);
}

.live-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}

.live-dot.on {
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
  animation: pulse 1.6s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.msg-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem 1rem;
  transition: border-color 0.15s;
}

.msg-card:hover {
  border-color: #3d444d;
}

.msg-card.is-new {
  border-color: rgba(63, 185, 80, 0.45);
  box-shadow: 0 0 0 1px var(--green-soft);
}

.msg-card.is-highlight {
  border-color: rgba(47, 129, 247, 0.65);
  box-shadow: 0 0 0 2px var(--accent-soft);
  animation: highlight-pulse 1.4s ease 2;
}

@keyframes highlight-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--accent-soft); }
  50% { box-shadow: 0 0 0 6px rgba(47, 129, 247, 0.2); }
}

.msg-main {
  min-width: 0;
}

.msg-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.75rem;
  margin-bottom: 0.55rem;
}

.msg-author {
  font-weight: 600;
  font-size: 0.92rem;
}

.msg-author-id {
  color: var(--text-dim);
  font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.msg-date {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-left: auto;
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9rem;
  line-height: 1.55;
  color: #d0d7de;
}

.msg-text:empty::after {
  content: "—";
  color: var(--text-dim);
}

.msg-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  min-width: min(140px, 100%);
}

.media-box {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-width: min(220px, 100%);
}

.media-box img {
  display: block;
  max-height: 180px;
  width: auto;
  max-width: 220px;
  object-fit: cover;
  cursor: zoom-in;
}

.media-box video {
  display: block;
  max-height: 180px;
  max-width: 220px;
  background: #000;
}

.media-file {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 220px;
}

.media-file a {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-id {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ===== PAGINATION ===== */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 1.5rem;
}

.page-link {
  min-width: 36px;
  height: 36px;
  padding: 0 0.65rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.85rem;
  text-decoration: none;
}

.page-link:hover {
  background: var(--bg-hover);
  text-decoration: none;
  color: #fff;
}

.page-link.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.page-link.disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ===== LIGHTBOX (simple photo) ===== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(1, 4, 9, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  cursor: zoom-out;
}

.lightbox.open {
  display: flex;
}

.lightbox img,
.lightbox video {
  max-width: min(calc(100vw - 3rem), 1100px);
  max-height: calc(100dvh - 3rem);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: var(--shadow);
  cursor: default;
}

.lightbox video {
  display: none;
  width: min(calc(100vw - 3rem), 1100px);
  height: auto;
  max-height: calc(100dvh - 3rem);
  background: #000;
}

/* ===== GALLERY GRID ===== */
.page-gallery {
  padding-top: 1rem;
}

.gallery-page-header {
  margin-bottom: 0.7rem;
  align-items: center;
}

.page-gallery .page-title {
  font-size: 1.2rem;
}

.page-gallery .page-subtitle {
  margin-top: 0.15rem;
  font-size: 0.78rem;
}

.gallery-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
  margin-bottom: 0.75rem;
  padding: 0.4rem 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.gallery-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  flex: 1 1 520px;
  min-width: 0;
}

.gallery-filters .input,
.gallery-filters .select,
.gallery-filters .btn {
  height: 32px;
  padding: 0 0.55rem;
  font-size: 0.8rem;
  border-radius: 7px;
}

.gallery-search {
  flex: 1 1 180px;
  min-width: 140px;
}

.gallery-filters .select {
  flex: 0 1 132px;
  min-width: 108px;
  width: auto;
}

.gallery-per-page {
  flex: 0 0 92px !important;
  min-width: 92px !important;
}

.gallery-sort {
  flex: 0 0 158px !important;
  min-width: 148px !important;
}

.gallery-bar-right {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-left: auto;
  flex-shrink: 0;
}

.gallery-select-all {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.gallery-select-all input {
  margin: 0;
  accent-color: var(--accent);
}

#gallery-delete-selected {
  height: 32px;
}

.gallery-bar-right .result-count {
  font-size: 0.75rem;
  white-space: nowrap;
}

.gallery-view-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}

.gallery-view-btn {
  width: 32px;
  height: 30px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
}

.gallery-view-btn + .gallery-view-btn {
  border-left: 1px solid var(--border);
}

.gallery-view-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.gallery-view-btn.active,
html[data-gallery-view="list"] .gallery-view-btn[data-gallery-view="list"],
html:not([data-gallery-view="list"]) .gallery-view-btn[data-gallery-view="tiles"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr));
  gap: 0.65rem;
  width: 100%;
  min-width: 0;
}

.gallery-grid.is-list,
html[data-gallery-view="list"] .gallery-grid {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.gallery-list-extra {
  display: none;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.gallery-filename {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.gallery-size {
  flex-shrink: 0;
  color: var(--text-dim);
}

.gallery-grid.is-list .gallery-list-extra,
html[data-gallery-view="list"] .gallery-grid .gallery-list-extra {
  display: flex;
}

.gallery-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.gallery-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.gallery-check {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  z-index: 3;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  background: rgba(1, 4, 9, 0.62);
  border-radius: 5px;
  cursor: pointer;
}

.gallery-check input {
  margin: 0;
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}

.gallery-del {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  z-index: 3;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: rgba(248, 81, 73, 0.88);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.gallery-card:hover .gallery-del,
.gallery-card.is-selected .gallery-del,
.gallery-del:focus {
  opacity: 1;
}

@media (hover: none) {
  .gallery-del {
    opacity: 1;
  }
}

.gallery-card:hover {
  border-color: #484f58;
  transform: translateY(-2px);
}

.gallery-grid.is-list .gallery-card,
html[data-gallery-view="list"] .gallery-grid .gallery-card {
  flex-direction: row;
  align-items: stretch;
  transform: none;
}

.gallery-grid.is-list .gallery-card:hover,
html[data-gallery-view="list"] .gallery-grid .gallery-card:hover {
  transform: none;
}

.gallery-grid.is-list .gallery-thumb-wrap,
html[data-gallery-view="list"] .gallery-grid .gallery-thumb-wrap {
  width: 88px;
  min-width: 88px;
  flex-shrink: 0;
}

.gallery-grid.is-list .gallery-thumb,
html[data-gallery-view="list"] .gallery-grid .gallery-thumb {
  width: 88px;
  min-width: 88px;
  aspect-ratio: 1;
}

.gallery-grid.is-list .gallery-fav,
html[data-gallery-view="list"] .gallery-grid .gallery-fav {
  width: 24px;
  height: 24px;
  font-size: 0.85rem;
  right: 0.25rem;
  bottom: 0.25rem;
  opacity: 1;
}

.gallery-grid.is-list .gallery-type-badge,
html[data-gallery-view="list"] .gallery-grid .gallery-type-badge {
  left: 0.3rem;
  bottom: 0.3rem;
  font-size: 0.6rem;
}

.gallery-grid.is-list .gallery-duration-badge,
html[data-gallery-view="list"] .gallery-grid .gallery-duration-badge {
  left: 0.3rem;
  bottom: 1.45rem;
  font-size: 0.6rem;
}

.gallery-grid.is-list .gallery-meta,
html[data-gallery-view="list"] .gallery-grid .gallery-meta {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.65rem;
  justify-content: center;
}

.gallery-grid.is-list .gallery-placeholder .ph-label,
html[data-gallery-view="list"] .gallery-grid .gallery-placeholder .ph-label {
  display: none;
}

.gallery-thumb-wrap {
  position: relative;
}

.gallery-thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  background: #0d1117;
  cursor: pointer;
  overflow: hidden;
  min-height: 80px;
}

.gallery-fav {
  position: absolute;
  right: 0.4rem;
  bottom: 0.4rem;
  z-index: 4;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(1, 4, 9, 0.62);
  color: rgba(255, 255, 255, 0.88);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0.92;
  transition: transform 0.12s, color 0.12s, background 0.12s, opacity 0.12s;
}

.gallery-fav:hover {
  transform: scale(1.08);
  background: rgba(1, 4, 9, 0.82);
}

.gallery-fav.is-on,
.gallery-card.is-faved .gallery-fav {
  color: #ff6b9d;
  opacity: 1;
  background: rgba(1, 4, 9, 0.78);
  text-shadow: 0 0 10px rgba(255, 107, 157, 0.55);
}

.gviewer-fav.is-on {
  color: #ff6b9d;
  border-color: rgba(255, 107, 157, 0.45);
  background: rgba(255, 107, 157, 0.12);
}

.gallery-fav-filter.is-on {
  box-shadow: 0 0 0 1px rgba(255, 107, 157, 0.35);
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-thumb .gallery-video-preview {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.gallery-play-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.person-media-item .gallery-play-badge {
  z-index: 3;
}

.gallery-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  color: var(--text-muted);
  background: linear-gradient(145deg, #161b22, #0d1117);
}

.gallery-placeholder .ph-icon {
  font-size: 1.6rem;
  opacity: 0.9;
}

.gallery-placeholder .ph-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.gallery-placeholder.video .ph-icon { color: var(--accent); }
.gallery-placeholder.audio .ph-icon { color: var(--purple); }
.gallery-placeholder.missing { opacity: 0.7; }

.gallery-type-badge {
  position: absolute;
  left: 0.45rem;
  bottom: 0.45rem;
  z-index: 3;
  background: rgba(1, 4, 9, 0.72);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  text-transform: uppercase;
}

.gallery-duration-badge {
  position: absolute;
  left: 0.45rem;
  bottom: 1.75rem;
  z-index: 3;
  background: rgba(1, 4, 9, 0.72);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.gallery-meta {
  padding: 0.35rem 0.5rem 0.45rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.gallery-meta-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.gallery-author {
  font-size: 0.8rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-msg-link {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  font-size: 0.95rem;
}

.gallery-msg-link:hover {
  background: rgba(47, 129, 247, 0.3);
  color: #79b8ff;
  text-decoration: none;
}

.gallery-meta-bottom {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.55rem;
  font-size: 0.7rem;
  color: var(--text-dim);
}

.gallery-group {
  color: var(--text-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== PERSON GALLERY TOOLBAR ===== */
.gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  padding: 0.5rem;
  background: var(--bg-hover);
  border-radius: var(--radius);
}

.gallery-view-controls {
  display: flex;
  gap: 0.25rem;
}

.gallery-view-controls .btn {
  padding: 0.4rem 0.6rem;
  font-size: 0.95rem;
  min-width: 36px;
}

.gallery-view-controls .btn.active {
  background: var(--accent);
  color: #fff;
}

/* Hide captions in tiles view, show in list view */
html:not([data-gallery-view="list"]) .gallery-grid .gallery-meta {
  display: none;
}

html[data-gallery-view="list"] .gallery-grid .gallery-meta {
  display: flex;
}

/* Gallery columns variations */
.gallery-grid[data-columns="4"] {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.gallery-grid[data-columns="6"] {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.gallery-grid[data-columns="8"] {
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

@media (max-width: 1200px) {
  .gallery-grid[data-columns="8"] {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
  .gallery-grid[data-columns="6"] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .gallery-grid[data-columns="8"],
  .gallery-grid[data-columns="6"],
  .gallery-grid[data-columns="4"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .gallery-grid[data-columns="8"],
  .gallery-grid[data-columns="6"],
  .gallery-grid[data-columns="4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ===== GALLERY VIEWER ===== */
.gviewer {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.gviewer[hidden] {
  display: none !important;
}

.gviewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(1, 4, 9, 0.9);
  backdrop-filter: blur(4px);
}

.gviewer-panel {
  position: relative;
  z-index: 1;
  width: min(1100px, 100%);
  height: min(94vh, calc(100dvh - 2rem));
  max-height: calc(100dvh - 2rem);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.gviewer-top,
.gviewer-bottom {
  flex: 0 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border-soft);
}

.gviewer-bottom {
  border-bottom: 0;
  border-top: 1px solid var(--border-soft);
  flex-direction: column;
  align-items: stretch;
}

.gviewer-info {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  min-width: 0;
}

.gviewer-counter {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.gviewer-author {
  font-weight: 600;
  font-size: 0.9rem;
}

.gviewer-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.gviewer-stage {
  position: relative;
  isolation: isolate;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #010409;
  overflow: hidden;
  z-index: 1;
}

.gviewer-content {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 3.4rem;
  box-sizing: border-box;
}

.gviewer-content img,
.gviewer-content video {
  position: relative;
  z-index: 1;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
}

.gviewer-content video {
  width: 100%;
  height: 100%;
  background: #000;
}

.gviewer-content audio {
  width: min(480px, 90%);
}

.gviewer-content .gv-file {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
}

.gviewer-content .gv-file a {
  display: inline-block;
  margin-top: 0.75rem;
}

.gviewer-nav {
  position: absolute;
  top: auto;
  bottom: 5.75rem;
  transform: none;
  z-index: 4;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(22, 27, 34, 0.92);
  color: #fff;
  font-size: 1.7rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  line-height: 1;
  pointer-events: auto;
}

.gviewer-nav::before {
  content: "";
  position: absolute;
  inset: -8px;
  bottom: 0;
}

.gviewer-nav:hover {
  background: var(--bg-hover);
  border-color: var(--text-dim);
}

.gviewer-nav:disabled {
  opacity: 0.35;
  cursor: default;
}

.gviewer-nav.prev { left: 0.65rem; }
.gviewer-nav.next { right: 0.65rem; }

.gviewer-top,
.gviewer-bottom,
.gviewer-actions {
  position: relative;
  z-index: 2;
}

.gviewer-hint {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 0.72rem;
}

.gviewer-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.gviewer-text {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: #d0d7de;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 4.5em;
  overflow: auto;
}

body.gviewer-open {
  overflow: hidden;
}

.gviewer:fullscreen,
.gviewer:-webkit-full-screen {
  padding: 0;
  background: #000;
}

.gviewer:fullscreen .gviewer-panel,
.gviewer:-webkit-full-screen .gviewer-panel {
  width: 100%;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
  border: 0;
  background: #010409;
}

.gviewer:fullscreen .gviewer-stage,
.gviewer:-webkit-full-screen .gviewer-stage {
  min-height: 0;
  max-height: none;
}

.gviewer:fullscreen .gviewer-content img,
.gviewer:fullscreen .gviewer-content video,
.gviewer:-webkit-full-screen .gviewer-content img,
.gviewer:-webkit-full-screen .gviewer-content video {
  max-height: 100%;
  max-width: 100%;
}

.gviewer:fullscreen .gviewer-nav,
.gviewer:-webkit-full-screen .gviewer-nav {
  width: 56px;
  height: 80px;
  background: rgba(22, 27, 34, 0.78);
}

/* ===== SLIDESHOW SETTINGS ===== */
.ss-modal {
  position: fixed;
  inset: 0;
  z-index: 420;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.ss-modal[hidden] {
  display: none !important;
}

.ss-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(1, 4, 9, 0.72);
  backdrop-filter: blur(3px);
}

.ss-modal-panel {
  position: relative;
  z-index: 1;
  width: min(740px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem 1.25rem;
}

.ss-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.ss-modal-head .section-title {
  margin: 0;
}

.ss-modal .settings-form-grid {
  grid-template-columns: 1fr 1fr;
}

.ss-preset-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.75rem;
  align-items: end;
}

.ss-preset-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.gviewer .ss-modal {
  position: absolute;
}

@media (max-width: 720px) {
  .ss-preset-row {
    grid-template-columns: 1fr;
  }
}

/* ===== LOGIN ===== */
.login-page {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(47, 129, 247, 0.18), transparent 55%),
    radial-gradient(900px 400px at 100% 0%, rgba(163, 113, 247, 0.14), transparent 50%),
    var(--bg);
}

.login-theme-toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
}

html[data-theme="light"] .login-page {
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(9, 105, 218, 0.10), transparent 55%),
    radial-gradient(900px 400px at 100% 0%, rgba(130, 80, 223, 0.08), transparent 50%),
    var(--bg);
}

html[data-theme="light"] .alert-error {
  color: #cf222e;
}

html[data-theme="light"] .alert-info {
  color: #0969da;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow);
}

.login-brand {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-brand .brand-mark {
  margin: 0 auto 0.85rem;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  font-size: 1.25rem;
}

.login-brand .brand-mark .nav-ico {
  width: 26px;
  height: 26px;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.login-brand p {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.login-field {
  margin-bottom: 1rem;
}

.login-field label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.alert {
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.alert-error {
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid rgba(248, 81, 73, 0.35);
  color: #ff7b72;
}

.alert-info {
  background: var(--accent-soft);
  border: 1px solid rgba(47, 129, 247, 0.3);
  color: #79b8ff;
}

/* ===== GROUP HEADER CHIPS ===== */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.65rem;
}

.back-link:hover {
  color: var(--text);
  text-decoration: none;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  .filters-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) !important;
  }
  .filters-actions {
    grid-column: 1 / -1;
  }

  .topnav {
    padding: 0 0.85rem;
  }

  .topnav-right {
    gap: 0.45rem;
  }

  .nav-link {
    padding: 0.3rem 0.4rem;
    font-size: 0.8rem;
  }

  .stats-grid-6,
  .stats-grid-jobs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1400px) {
  .nav-toggle {
    display: inline-flex;
  }

  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(1, 4, 9, 0.55);
  }

  .nav-backdrop[hidden] {
    display: none;
  }

  .topnav-menu {
    display: none;
    position: absolute;
    top: var(--nav-h);
    left: 0;
    right: 0;
    z-index: 101;
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
    max-height: calc(100dvh - var(--nav-h));
    overflow-y: auto;
    padding: 0.55rem 0.7rem calc(0.75rem + env(safe-area-inset-bottom));
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
  }

  body.nav-open {
    overflow: hidden;
  }

  body.nav-open .topnav-menu {
    display: flex;
  }

  .topnav-menu .nav-link {
    padding: 0.75rem 0.85rem;
    font-size: 0.95rem;
    border-radius: 8px;
  }

  .nav-drop {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .nav-drop-toggle {
    width: 100%;
    justify-content: flex-start;
  }

  .nav-drop-toggle .nav-caret {
    margin-left: auto;
  }

  .nav-drop-menu {
    position: static;
    display: none;
    min-width: 0;
    margin: 0.1rem 0 0.2rem 0.55rem;
    padding: 0.15rem 0 0.15rem 0.45rem;
    background: transparent;
    border: 0;
    border-left: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
  }

  .nav-drop.is-open > .nav-drop-menu,
  .nav-drop.is-current > .nav-drop-menu {
    display: flex;
  }

  .nav-drop.is-open > .nav-drop-toggle .nav-caret,
  .nav-drop.is-current > .nav-drop-toggle .nav-caret {
    transform: rotate(180deg);
  }

  .nav-drop-menu .nav-link {
    padding: 0.62rem 0.75rem;
    font-size: 0.9rem;
  }

  .topnav-menu-user {
    margin: 0.45rem 0 0;
    padding: 0.65rem 0.85rem 0.15rem;
    border-top: 1px solid var(--border-soft);
    justify-content: space-between;
  }

  .topnav-right .user-chip span:last-child {
    display: inline;
  }
}

@media (max-width: 900px) {
  .stats-grid,
  .stats-grid-3,
  .stats-grid-6,
  .stats-grid-jobs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filters-grid-users {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .filters-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .msg-card {
    grid-template-columns: 1fr;
  }

  .msg-side,
  .msg-card-album .msg-side {
    align-items: flex-start;
    min-width: 0;
    width: 100%;
  }

  .media-box,
  .media-box img,
  .media-box video,
  .media-file,
  .album-grid {
    max-width: 100%;
    width: 100%;
  }

  .media-box img,
  .media-box video {
    max-height: 240px;
  }

  .msg-date {
    margin-left: 0;
  }

  .page {
    padding: 1rem 0.85rem max(2rem, env(safe-area-inset-bottom));
  }

  .page-title {
    font-size: 1.3rem;
    overflow-wrap: anywhere;
  }

  .page-header,
  .header-actions,
  .parser-control,
  .parser-control-actions,
  .person-group-toolbar,
  .person-batch-bar,
  .person-batch-actions,
  .person-list-import-actions {
    align-items: stretch;
  }

  .header-actions,
  .parser-control-actions {
    width: 100%;
  }

  .header-actions .btn,
  .header-actions .inline-form,
  .parser-control-actions .inline-form,
  .parser-control-actions .btn {
    flex: 0 1 auto;
  }

  .parser-control-actions .select,
  .header-actions .select {
    min-width: 0 !important;
    width: 100% !important;
    flex: 1 1 140px;
  }

  .group-footer,
  .group-footer-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .group-actions {
    justify-content: stretch;
  }

  .group-actions .btn {
    flex: 1 1 auto;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr));
  }

  .gallery-bar {
    align-items: stretch;
  }

  .gallery-filters {
    flex: 1 1 100%;
  }

  .gallery-search,
  .gallery-filters .select,
  .gallery-per-page {
    min-width: 0 !important;
    flex: 1 1 100% !important;
    width: 100%;
  }

  .gallery-bar-right {
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
  }

  .gallery-grid.is-list .gallery-thumb-wrap,
  html[data-gallery-view="list"] .gallery-grid .gallery-thumb-wrap,
  .gallery-grid.is-list .gallery-thumb,
  html[data-gallery-view="list"] .gallery-grid .gallery-thumb {
    width: 72px;
    min-width: 72px;
  }

  .gviewer {
    padding: 0;
  }

  .gviewer-panel {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: 0;
  }

  .gviewer-stage {
    min-height: 0;
    max-height: none;
  }

  .gviewer-content {
    padding: 0.35rem 2.6rem 0.35rem;
  }

  .gviewer-content img,
  .gviewer-content video {
    max-height: 100%;
    max-width: 100%;
  }

  .gviewer-nav {
    width: 36px;
    height: 36px;
    bottom: 4.75rem;
  }

  .gviewer-nav.prev { left: 0.35rem; }
  .gviewer-nav.next { right: 0.35rem; }

  .input,
  .select,
  textarea.input,
  .login-field .input {
    font-size: 16px;
  }

  .brand-sub {
    display: none;
  }

  .board-parser-status,
  .parser-control {
    flex-direction: column;
    align-items: stretch;
  }

  .board-parser-err {
    max-width: 100%;
    white-space: normal;
  }

  .person-group-create,
  .person-group-rename {
    width: 100%;
    margin-left: 0;
  }

  .person-group-create .input,
  .person-group-rename .input,
  .person-batch-actions .select,
  .person-card-assign .select {
    min-width: 0;
    max-width: none;
    flex: 1 1 auto;
  }

  .sites-tabs {
    width: 100%;
  }

  .lightbox {
    padding: 0.75rem;
  }

  .lightbox img,
  .lightbox video {
    max-width: calc(100vw - 1.5rem);
    max-height: calc(100dvh - 1.5rem);
  }
}

@media (max-width: 520px) {
  .stats-grid,
  .stats-grid-4,
  .stats-grid-5,
  .stats-grid-6,
  .stats-grid-board-stats,
  .stats-grid[style*="repeat("] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .filters-grid,
  .filters-grid-users,
  .filters-grid-board {
    grid-template-columns: 1fr !important;
  }

  .group-stats-row,
  .group-stats-row-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-value {
    font-size: 1.35rem;
  }

  .login-page {
    padding: 1rem;
  }

  .login-card {
    padding: 1.4rem 1.1rem;
  }

  .pagination {
    gap: 0.3rem;
  }

  .page-link {
    min-width: 34px;
    height: 34px;
    padding: 0 0.45rem;
  }
}

/* ===== Sessions wizard ===== */
.session-wizard {
  max-width: 720px;
}

.wizard-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.wizard-step {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--bg-elevated);
}

.wizard-step.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.wizard-pane {
  margin-top: 0.5rem;
}

.check-inline {
  display: inline-flex !important;
  margin-right: 0.65rem;
  margin-bottom: 0.25rem;
}

.roles-cell {
  min-width: 12rem;
}

.td-actions {
  white-space: nowrap;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.field-label-text {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stats-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 900px) {
  .stats-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .stats-grid-4 {
    grid-template-columns: 1fr;
  }
  .td-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

.alert-ok {
  background: var(--green-soft);
  border: 1px solid rgba(63, 185, 80, 0.35);
  color: var(--green);
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

/* ===== SITES / BOARD ===== */
.sites-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 1.25rem;
  padding: 0.25rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: fit-content;
  max-width: 100%;
}

.sites-tab {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.95rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
}

.sites-tab:hover {
  color: var(--text);
  background: var(--bg-hover);
  text-decoration: none;
}

.sites-tab.active {
  color: #fff;
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(47, 129, 247, 0.25);
}

html[data-theme="light"] .sites-tab.active {
  color: var(--accent);
}

.stats-grid-5 {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 1100px) {
  .stats-grid-5 {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .stats-grid-5 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.filters-grid-board {
  grid-template-columns: 2fr 1.4fr 1fr 1fr 0.8fr auto;
}

@media (max-width: 1100px) {
  .filters-grid-board {
    grid-template-columns: 1fr 1fr;
  }
}

.board-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.board-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.95rem 1.1rem;
  transition: border-color 0.15s;
}

.board-card:hover {
  border-color: #484f58;
}

.board-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.board-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.82rem;
}

.board-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.board-card-title {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

.board-card-title a {
  color: var(--text);
  text-decoration: none;
}

.board-card-title a:hover {
  color: var(--accent);
}

.board-card-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.25rem;
  font-size: 0.85rem;
  margin-bottom: 0.45rem;
}

.board-card-text {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.board-detail-grid {
  display: grid;
  grid-template-columns: 3fr 0.67fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 900px) {
  .board-detail-grid {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}

.board-detail-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  font-size: 0.95rem;
}

.meta-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.meta-list > div {
  display: grid;
  gap: 0.15rem;
}

.meta-list dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 600;
}

.meta-list dd {
  margin: 0;
  font-size: 0.92rem;
  word-break: break-word;
}

/* ===== BOARD EXTRACT CHIPS ===== */
.extract-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.35rem 0 0.55rem;
}

.extract-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.3;
  background: rgba(139, 148, 158, 0.12);
  color: var(--text-muted);
  border: 1px solid transparent;
  text-decoration: none;
  max-width: 100%;
  word-break: break-all;
}

a.extract-chip:hover {
  text-decoration: none;
  border-color: var(--border);
  color: var(--text);
}

.extract-chip-tg {
  background: rgba(47, 129, 247, 0.14);
  color: #79b8ff;
}

.extract-chip-phone {
  background: rgba(63, 185, 80, 0.14);
  color: var(--green);
}

.extract-chip-place,
.extract-chip-metro {
  background: rgba(210, 153, 34, 0.14);
  color: var(--orange);
}

.extract-chip-params {
  background: rgba(163, 113, 247, 0.14);
  color: #d2a8ff;
  font-variant-numeric: tabular-nums;
}

.extract-chip-role {
  background: rgba(57, 210, 192, 0.14);
  color: var(--cyan);
}

.extract-chip-pref {
  background: rgba(139, 148, 158, 0.14);
  color: var(--text-muted);
}

.extract-chip-ok {
  background: rgba(63, 185, 80, 0.14);
  color: var(--green);
}

.extract-chip-warn {
  background: rgba(210, 153, 34, 0.14);
  color: var(--orange);
}

.board-parser-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 1rem;
  margin: 0 0 1rem;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-size: 0.85rem;
}
.board-parser-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex: 0 0 auto;
}
.board-parser-status.is-online .board-parser-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}
.board-parser-status.is-offline .board-parser-dot {
  background: var(--orange);
}
.board-parser-status.is-online strong { color: var(--green); }
.board-parser-status.is-offline strong { color: var(--orange); }
.board-parser-err {
  color: var(--red);
  max-width: 28rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-grid-board-stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 1100px) {
  .stats-grid-board-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .stats-grid-board-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.filters-grid-board {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1100px) {
  .filters-grid-board {
    grid-template-columns: 1fr 1fr;
  }
}

/* ===== PARSER CONTROL ===== */
.parser-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin: 0 0 1.15rem;
  padding: 0.7rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}
.parser-control-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.parser-control.is-paused { border-color: var(--orange); }
.parser-control.is-focus { border-color: var(--accent); }
.parser-control.is-paused strong { color: var(--orange); }
.parser-control.is-focus strong { color: var(--accent); }
.parser-control.is-all strong { color: var(--green); }

/* ===== PERSONS / TOPICS ===== */
.person-grid, .topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr));
  gap: 0.65rem;
  margin: 1rem 0;
  width: 100%;
  min-width: 0;
}
.person-card, .topic-card {
  display: flex;
  gap: 0.75rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: inherit;
  text-decoration: none;
  position: relative;
  min-width: 0;
  overflow: hidden;
}
.person-card:hover, .topic-card:hover { background: var(--bg-hover); }
.person-card-link {
  display: flex;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.person-card-link:hover { text-decoration: none; }
.person-card-link > div {
  min-width: 0;
  overflow: hidden;
}
.person-check {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  padding-top: 0.15rem;
}
.person-card-actions {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.35rem;
  min-width: 0;
}
.person-card-assign {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  min-width: 0;
}
.person-card-assign .select {
  max-width: 140px;
  min-width: 0;
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
}
.person-avatar {
  width: 48px; height: 48px; border-radius: 50%; object-fit: cover; flex: 0 0 auto;
  background: var(--bg-elevated);
}
.person-avatar.placeholder {
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: var(--text-muted);
}
.person-card h3, .topic-card h3 {
  margin: 0 0 0.2rem;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.person-card .td-muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Person grid columns: shrink-to-fit, vertical tiles */
.person-grid[data-columns="4"] {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.person-grid[data-columns="6"] {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
.person-grid[data-columns="8"] {
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

.person-grid[data-columns] .person-card {
  flex-direction: column;
  align-items: stretch;
  padding: 0.55rem;
  gap: 0.4rem;
}
.person-grid[data-columns] .person-check {
  position: absolute;
  top: 0.45rem;
  left: 0.45rem;
  z-index: 2;
  padding: 0.1rem;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 5px;
}
.person-grid[data-columns] .person-card-link {
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
}
.person-grid[data-columns] .person-avatar {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-radius: 10px;
}
.person-grid[data-columns] .person-avatar.placeholder {
  aspect-ratio: 1;
  height: auto;
  font-size: 1.55rem;
}
.person-grid[data-columns] .chip-row {
  margin-top: 0.2rem;
  gap: 0.22rem;
}
.person-grid[data-columns] .person-card-actions {
  width: 100%;
}
.person-grid[data-columns] .person-card-assign {
  width: 100%;
  flex-wrap: wrap;
}
.person-grid[data-columns] .person-card-assign .select {
  flex: 1 1 auto;
  max-width: none;
  width: 100%;
}

.person-grid[data-columns="6"] .person-card h3,
.person-grid[data-columns="8"] .person-card h3 {
  font-size: 0.82rem;
}
.person-grid[data-columns="8"] .td-muted {
  display: none;
}
.person-grid[data-columns="8"] .chip-row {
  max-height: 1.55em;
  overflow: hidden;
}
.person-grid[data-columns="8"] .person-card-actions {
  display: none;
}

@media (max-width: 1200px) {
  .person-grid[data-columns="8"] {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
  .person-grid[data-columns="6"] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .person-grid[data-columns="8"],
  .person-grid[data-columns="6"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .person-grid[data-columns="4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .person-grid[data-columns="8"],
  .person-grid[data-columns="6"],
  .person-grid[data-columns="4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.person-media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100px, 100%), 1fr));
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.person-media-item { margin: 0; position: relative; }
.person-media-item img, .person-media-item video {
  width: 100%; height: 90px; object-fit: cover; border-radius: 8px;
}
.person-media-item audio {
  width: 100%;
  margin-top: 1.4rem;
}
.person-media-item figcaption { font-size: 0.75rem; color: var(--text-muted); }
.person-media-item .person-check {
  position: absolute;
  top: 0.3rem;
  left: 0.3rem;
  z-index: 2;
  padding: 0;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 4px;
}
.person-media-item.is-saved img,
.person-media-item.is-saved video {
  outline: 2px solid var(--green);
}
.plain-list { margin: 0; padding-left: 1.1rem; }
.plain-list li { margin: 0.25rem 0; }

.person-section-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin: 0 0 1rem;
  padding: 0.3rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: fit-content;
  max-width: 100%;
}

.contacts-table-wrap {
  max-width: 100%;
}

.contacts-table {
  font-size: 0.8rem;
}

.contacts-table th,
.contacts-table td {
  padding: 0.45rem 0.55rem;
  white-space: nowrap;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contacts-table .contacts-notes {
  white-space: normal;
  max-width: 12rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.contacts-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.person-contact-box {
  margin-top: 0.35rem;
}

.person-group-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin: 0 0 1rem;
  padding: 0.35rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.person-group-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.8rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.person-group-tab:hover {
  color: var(--text);
  background: var(--bg-hover);
  text-decoration: none;
}
.person-group-tab.active {
  color: #fff;
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(47, 129, 247, 0.25);
}
html[data-theme="light"] .person-group-tab.active { color: var(--accent); }
.person-group-tab span {
  font-weight: 500;
  opacity: 0.75;
  font-size: 0.75rem;
}
.person-group-create,
.person-group-rename {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  margin-left: auto;
}
.person-group-create .input,
.person-group-rename .input {
  min-width: 160px;
  max-width: 220px;
  padding: 0.3rem 0.55rem;
  font-size: 0.85rem;
}
.person-group-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 0.75rem;
}

.person-list-import {
  margin: 0 0 1rem;
  padding: 0.45rem 0.7rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}

.person-list-import > summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  list-style: none;
}

.person-list-import > summary::-webkit-details-marker {
  display: none;
}

.person-list-import[open] > summary {
  margin-bottom: 0.5rem;
  color: var(--text);
}

.person-list-import textarea {
  min-height: 7.5rem;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.4;
}

.person-list-import-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  margin-top: 0.5rem;
}

.person-list-import-actions .field-hint {
  margin: 0;
  flex: 1 1 260px;
}
.person-batch-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 0.85rem;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}
.person-batch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.person-batch-actions .select { min-width: 160px; }
.person-group-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.person-group-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border-soft);
}
.person-tg-section { margin-top: 0.5rem; }
.person-tg-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin: 0.75rem 0;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 720px) {
  .stats-grid[style*="repeat(5"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .person-group-create,
  .person-group-rename { margin-left: 0; width: 100%; }
  .person-card { flex-wrap: wrap; }
  .person-card-actions { width: 100%; }
}

/* ===== DATASET ===== */
.dataset-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 1.25rem;
}

/* ===== GROUPS CATALOG ===== */
.filters-grid-catalog {
  grid-template-columns: 1.6fr repeat(5, minmax(0, 1fr)) auto;
}

.catalog-count {
  margin: 0 0 0.65rem;
}

.catalog-table .td-num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.catalog-table th.td-num {
  text-align: right;
}

.catalog-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.35rem;
}

.catalog-table .td-entity {
  max-width: 280px;
}

@media (max-width: 1100px) {
  .filters-grid-catalog {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .filters-grid-catalog {
    grid-template-columns: 1fr 1fr !important;
  }
}

.actress-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr));
  gap: 0.85rem;
}
.actress-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow: hidden;
  color: inherit;
  text-decoration: none;
}
.actress-card:hover { background: var(--bg-hover); text-decoration: none; }
.actress-cover {
  width: 100%;
  height: 220px;
  object-fit: cover;
  background: var(--bg-elevated);
}
.actress-cover.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--text-muted);
}
.actress-card-body { padding: 0.7rem 0.8rem 0.85rem; }
.actress-card-body h3 { margin: 0 0 0.2rem; font-size: 1rem; }

.catalog-bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin: 0 0 0.65rem;
}

.catalog-table .td-check {
  width: 2rem;
  vertical-align: middle;
}

.catalog-table tr.is-in-parser td {
  background: rgba(63, 185, 80, 0.04);
}

.catalog-table .td-actions {
  white-space: nowrap;
  vertical-align: middle;
}

.links-table tr.links-row {
  cursor: pointer;
}

.links-table tr.links-row:hover td {
  background: var(--bg-hover);
}

.actress-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr));
  gap: 0.85rem;
}
.actress-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow: hidden;
  color: inherit;
  text-decoration: none;
}
.actress-card:hover { background: var(--bg-hover); text-decoration: none; }
.actress-cover {
  width: 100%;
  height: 220px;
  object-fit: cover;
  background: var(--bg-elevated);
}
.actress-cover.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--text-muted);
}
.actress-card-body { padding: 0.7rem 0.8rem 0.85rem; }
.actress-card-body h3 { margin: 0 0 0.2rem; font-size: 1rem; }

/* ===== ACTRESS CARD DETAIL ===== */
.actress-hero {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.1rem;
  min-height: 200px;
}
.actress-banner {
  position: absolute;
  inset: 0;
  background: center/cover no-repeat;
}
.actress-banner-empty {
  background: linear-gradient(135deg, #1b2230 0%, #2a1a33 55%, #16202c 100%);
}
.actress-hero-overlay {
  position: relative;
  z-index: 1;
  min-height: 200px;
  padding: 1.4rem 1.2rem 1.1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.8rem;
  background: linear-gradient(180deg, rgba(8,10,14,0.15) 0%, rgba(8,10,14,0.78) 100%);
  color: #fff;
}
.actress-hero-overlay .page-title { color: #fff; margin: 0; }
.actress-banner-upload {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  z-index: 2;
}
.actress-layout {
  display: grid;
  grid-template-columns: minmax(min(200px, 100%), 280px) minmax(0, 1fr);
  gap: 1.15rem;
  align-items: start;
}
.actress-fullbody-col {
  position: sticky;
  top: calc(var(--nav-h) + 12px);
}
.actress-fullbody {
  width: 100%;
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  object-fit: cover;
  object-position: top center;
  min-height: 420px;
  max-height: 720px;
  background: var(--bg-elevated);
  margin-bottom: 0.5rem;
}
.actress-fullbody.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: 700;
  color: var(--text-muted);
}
.actress-socials { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.genre-primary { box-shadow: 0 0 0 1px rgba(163, 113, 247, 0.45); }
.genre-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr));
  gap: 0.45rem;
}
.genre-pick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.55rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-size: 0.85rem;
}
.genre-primary-flag {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.actress-media-actions {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  margin-top: 0.3rem;
}
.actress-media-actions .select { padding: 0.2rem 0.35rem; font-size: 0.75rem; }
.actress-video-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 90px;
  padding: 0.6rem;
  background: var(--bg-elevated);
  border-radius: 8px;
  text-align: center;
  font-weight: 600;
}
.actress-partners {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.actress-partner {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  font-size: 0.85rem;
}
.actress-films th, .actress-films td { vertical-align: top; }
.actress-awards { font-size: 0.88rem; }
@media (max-width: 860px) {
  .actress-layout { grid-template-columns: 1fr; }
  .actress-fullbody-col { position: static; }
  .actress-fullbody { max-height: 480px; }
}

/* ===== ACTRESSES LIST TOOLBAR ===== */
.actress-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem 0.7rem;
  margin-bottom: 1rem;
}
.actress-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.actress-search {
  flex: 1 1 220px;
  min-width: 160px;
}
.actress-toolbar .select {
  flex: 0 1 150px;
  min-width: 132px;
}
.actress-age {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.actress-age .input {
  width: 4.4rem;
  padding-left: 0.45rem;
  padding-right: 0.45rem;
}
.actress-genre-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.actress-genre-chip {
  display: inline-flex;
  cursor: pointer;
  margin: 0;
}
.actress-genre-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.actress-genre-chip span {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
}
.actress-genre-chip input:checked + span {
  background: var(--purple-soft);
  border-color: transparent;
  color: #d2a8ff;
}
html[data-theme="light"] .actress-genre-chip input:checked + span {
  color: #8250df;
}
.actress-genre-chip:hover span {
  border-color: var(--accent);
}

.actress-per-page {
  flex: 0 0 7.2rem !important;
  min-width: 7.2rem !important;
}
.actress-results-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem 0.85rem;
  margin: 0 0 0.75rem;
}
.actress-results-count { margin: 0; }
.actress-view-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}
.actress-view-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.32rem 0.7rem;
  line-height: 1.2;
}
.actress-view-btn + .actress-view-btn { border-left: 1px solid var(--border); }
.actress-view-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.actress-view-btn.active,
html[data-actress-view="cards"] .actress-view-btn[data-actress-view="cards"],
html[data-actress-view="list"] .actress-view-btn[data-actress-view="list"],
html[data-actress-view="blocks"] .actress-view-btn[data-actress-view="blocks"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.actress-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr));
  gap: 0.85rem;
}
.actress-card-extra { display: none; margin: 0.15rem 0 0; font-size: 0.78rem; }
.actress-card-genre-more { display: none; }
.actress-results[data-view="cards"] .actress-card-extra { display: none; }

.actress-results[data-view="list"],
html[data-actress-view="list"] .actress-results {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
html[data-actress-view="list"] .actress-results .actress-card,
.actress-results[data-view="list"] .actress-card {
  flex-direction: row;
  align-items: center;
}
html[data-actress-view="list"] .actress-results .actress-cover,
.actress-results[data-view="list"] .actress-cover {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  font-size: 1.2rem;
}
html[data-actress-view="list"] .actress-results .actress-card-body,
.actress-results[data-view="list"] .actress-card-body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.85rem;
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.75rem;
}
html[data-actress-view="list"] .actress-results .actress-card-body h3,
.actress-results[data-view="list"] .actress-card-body h3 {
  margin: 0;
  min-width: 9rem;
}
html[data-actress-view="list"] .actress-results .actress-card-meta,
.actress-results[data-view="list"] .actress-card-meta { margin: 0; }
html[data-actress-view="list"] .actress-results .chip-row,
.actress-results[data-view="list"] .chip-row {
  margin-top: 0;
  margin-left: auto;
}
html[data-actress-view="list"] .actress-results .actress-card-extra,
.actress-results[data-view="list"] .actress-card-extra { display: none; }

.actress-results[data-view="blocks"],
html[data-actress-view="blocks"] .actress-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(420px, 100%), 1fr));
  gap: 0.85rem;
}
html[data-actress-view="blocks"] .actress-results .actress-card,
.actress-results[data-view="blocks"] .actress-card {
  flex-direction: row;
  align-items: stretch;
  min-height: 168px;
}
html[data-actress-view="blocks"] .actress-results .actress-cover,
.actress-results[data-view="blocks"] .actress-cover {
  width: 148px;
  height: auto;
  min-height: 168px;
  max-height: 220px;
  flex-shrink: 0;
  align-self: stretch;
}
html[data-actress-view="blocks"] .actress-results .actress-card-body,
.actress-results[data-view="blocks"] .actress-card-body {
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
html[data-actress-view="blocks"] .actress-results .actress-card-extra,
.actress-results[data-view="blocks"] .actress-card-extra { display: block; }
html[data-actress-view="blocks"] .actress-results .actress-card-genre-more,
.actress-results[data-view="blocks"] .actress-card-genre-more { display: inline-flex; }
html[data-actress-view="blocks"] .actress-results .chip-row,
.actress-results[data-view="blocks"] .chip-row { margin-top: auto; padding-top: 0.45rem; }

@media (max-width: 640px) {
  html[data-actress-view="blocks"] .actress-results .actress-card,
  .actress-results[data-view="blocks"] .actress-card { flex-direction: column; }
  html[data-actress-view="blocks"] .actress-results .actress-cover,
  .actress-results[data-view="blocks"] .actress-cover {
    width: 100%;
    height: 200px;
    min-height: 0;
    max-height: 220px;
  }
}

/* ===== ACTRESS FOLD / EDIT ===== */
.actress-fold {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  padding: 0;
}
.actress-fold-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  list-style: none;
  cursor: pointer;
  padding: 0.7rem 0.9rem;
  user-select: none;
}
.actress-fold-head::-webkit-details-marker { display: none; }
.actress-fold-head::before {
  content: "▸";
  color: var(--text-muted);
  font-size: 0.8rem;
  width: 0.9rem;
}
.actress-fold[open] > .actress-fold-head::before { content: "▾"; }
.actress-fold-head .section-title { margin: 0; flex: 1; }
.actress-fold-body { padding: 0 0.9rem 0.9rem; }
.actress-save-bar {
  position: sticky;
  bottom: 0.6rem;
  display: flex;
  justify-content: flex-end;
  margin: 0.4rem 0 0.9rem;
  z-index: 3;
}
.actress-inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}
.actress-film-edit {
  display: grid;
  grid-template-columns: 4.5rem 1.4fr 1fr 1.2fr 1fr auto;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
  align-items: center;
}
.actress-link-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
}
.actress-link-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1;
  align-items: center;
}
.actress-link-edit .input { flex: 1 1 140px; min-width: 120px; }
.actress-link-edit .select { flex: 0 0 110px; }
.actress-video-grid { grid-template-columns: repeat(auto-fill, minmax(min(160px, 100%), 1fr)); }
.actress-video-tile { position: relative; }
.actress-video-tile img,
.actress-video-tile video {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg-elevated);
}
.actress-video-link {
  position: relative;
  display: block;
  min-height: 90px;
  background: var(--bg-elevated);
  border-radius: 8px;
  overflow: hidden;
  text-align: center;
}
.actress-play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  pointer-events: none;
}
.actress-video-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.25rem 0.4rem;
  font-size: 0.72rem;
  background: linear-gradient(transparent, rgba(0,0,0,.72));
  color: #fff;
}
@media (max-width: 900px) {
  .actress-film-edit { grid-template-columns: 1fr 1fr auto; }
  .actress-toolbar .select { flex: 1 1 140px; }
}

.actress-batch-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
  margin: 0 0 0.85rem;
  padding: 0.55rem 0.7rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.actress-local-badge {
  position: absolute;
  right: 0.3rem;
  top: 0.3rem;
  z-index: 2;
}
.person-media-item.is-selected {
  outline: 2px solid var(--accent);
  border-radius: 8px;
}
.actress-link-check {
  display: inline-flex;
  align-items: center;
  margin-right: 0.15rem;
}
tr.is-muted { opacity: 0.55; }

.ig-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 1rem;
  margin: 0 0 1.25rem;
  padding: 0.65rem 0.9rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.ig-status.is-online .board-parser-dot { background: var(--green); }
.ig-status.is-offline .board-parser-dot { background: var(--text-dim); }
.ig-profile-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.ig-types {
  grid-column: span 2;
}
.ig-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 0.35rem;
}
@media (max-width: 900px) {
  .ig-profile-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .ig-types { grid-column: span 2; }
}
.td-actions {
  display: flex;
  gap: 0.3rem;
  justify-content: flex-end;
  white-space: nowrap;
  flex-wrap: wrap;
}

/* ───────────────────── Накопитель (storage) ───────────────────── */

.stat-card.red::after {
  background: var(--red);
}

/* категорийные слоты — валидированы для обеих тем (см. dataviz: all-pairs PASS) */
html[data-theme="dark"] .sto-scope {
  --sto-c-media: #3987e5;
  --sto-c-db: #d95926;
  --sto-c-code: #199e70;
  --sto-c-other: #57606a;
  --sto-ring: var(--bg);
}
html[data-theme="light"] .sto-scope {
  --sto-c-media: #2a78d6;
  --sto-c-db: #eb6834;
  --sto-c-code: #1baf7a;
  --sto-c-other: #99a1a8;
  --sto-ring: var(--bg);
}

.sto-flash {
  margin: 0 0 1rem;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--green-soft);
  color: var(--text);
  font-size: 0.9rem;
}
.sto-flash.sto-flash-err {
  background: rgba(248, 81, 73, 0.14);
}

/* метр занятости диска: заливка — статусный цвет, дорожка — светлый шаг того же цвета */
.sto-meter {
  height: 14px;
  border-radius: 7px;
  background: var(--bg-hover);
  overflow: hidden;
}
.sto-meter.sto-sev-green { background: var(--green-soft); }
.sto-meter.sto-sev-orange { background: var(--orange-soft); }
.sto-meter.sto-sev-red { background: rgba(248, 81, 73, 0.14); }
.sto-meter-fill {
  height: 100%;
  min-width: 2px;
  border-radius: 7px 4px 4px 7px;
  transition: width 0.4s ease;
}
.sto-meter-fill.sto-sev-green { background: var(--green); }
.sto-meter-fill.sto-sev-orange { background: var(--orange); }
.sto-meter-fill.sto-sev-red { background: var(--red); }
.sto-meter-legend {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* состав данных: горизонтальный part-to-whole бар, 2px зазоры в цвет поверхности */
.sto-stack {
  display: flex;
  gap: 2px;
  height: 22px;
  border-radius: 6px;
  overflow: hidden;
  margin: 10px 0 12px;
  background: transparent;
}
.sto-seg {
  min-width: 2px;
  height: 100%;
}
.sto-seg:first-child { border-radius: 6px 0 0 6px; }
.sto-seg:last-child { border-radius: 0 6px 6px 0; }
.sto-seg:only-child { border-radius: 6px; }
.sto-seg-media { background: var(--sto-c-media); }
.sto-seg-db { background: var(--sto-c-db); }
.sto-seg-code { background: var(--sto-c-code); }
.sto-seg-other { background: var(--sto-c-other); }

.sto-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-bottom: 10px;
}
.sto-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.88rem;
}
.sto-legend-name { color: var(--text-muted); }
.sto-legend-val { color: var(--text); font-weight: 600; }
.sto-legend-sub {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.sto-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 0 2px var(--sto-ring);
}
.sto-dot-media { background: var(--sto-c-media); }
.sto-dot-db { background: var(--sto-c-db); }
.sto-dot-code { background: var(--sto-c-code); }
.sto-dot-other { background: var(--sto-c-other); }

/* дерево блоков */
.sto-tree {
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: opacity 0.2s ease;
}
.sto-tree.sto-dim { opacity: 0.55; }
.sto-node {
  border-radius: var(--radius-sm);
  padding: 2px 0;
}
.sto-node-root {
  background: var(--bg-hover);
  border: 1px solid var(--border-soft);
  padding-bottom: 8px;
  margin-bottom: 6px;
}
.sto-node-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  min-height: 34px;
}
.sto-node-head.sto-clickable { cursor: pointer; }
.sto-node-head:hover { background: var(--bg-hover); }
.sto-caret {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.8rem;
  padding: 0;
}
.sto-caret:hover { background: var(--bg-hover); color: var(--text); }
.sto-caret-leaf { cursor: default; }
.sto-caret-leaf:hover { background: transparent; color: var(--text-muted); }
.sto-name {
  color: var(--text);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}
.sto-name-dir { font-weight: 600; }
.sto-type {
  color: var(--text-dim);
  font-size: 0.78rem;
  white-space: nowrap;
}
.sto-right {
  margin-left: auto;
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
}
.sto-size {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.sto-pct {
  color: var(--text-dim);
  font-size: 0.82rem;
  white-space: nowrap;
}
.sto-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.74rem;
  color: var(--text-dim);
  padding: 0 10px 6px;
  word-break: break-all;
  line-height: 1.35;
}
.sto-path-err { color: var(--red); }
.sto-more, .sto-loading {
  color: var(--text-dim);
  font-style: italic;
}
.sto-children {
  margin: 2px 0 8px;
  padding-left: 12px;
  border-left: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sto-share {
  padding: 0 10px 7px;
  margin-bottom: 2px;
  max-width: 560px;
}
.sto-share-fill {
  height: 6px;
  border-radius: 0 3px 3px 0;
  min-width: 2px;
}
.sto-share-media { background: var(--sto-c-media); }
.sto-share-db { background: var(--sto-c-db); }
.sto-share-code { background: var(--sto-c-code); }
.sto-share-other { background: var(--sto-c-other); }
.sto-table-meta {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}

@media (max-width: 700px) {
  .sto-pct { display: none; }
  .sto-path { font-size: 0.7rem; }
  .sto-stack { height: 16px; }
}

/* ─────────────── Настройки: правила загрузки файлов (media_rules) ─────────────── */

.badge-red { background: var(--red-soft, rgba(248, 81, 73, 0.15)); color: var(--red, #f85149); }
html[data-theme="light"] .badge-red { background: rgba(207, 34, 46, 0.12); color: #cf222e; }

.input-sm { padding: 0.28rem 0.5rem; font-size: 0.85rem; }

.rules-block {
  margin: 0.9rem 0 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 0.9rem;
  background: var(--bg-card);
}

.rules-block-title { font-weight: 600; margin-bottom: 0.6rem; }

.rules-grid { display: flex; flex-direction: column; gap: 0.35rem; }

.rules-row {
  display: grid;
  grid-template-columns: 13rem 11rem 1fr;
  align-items: center;
  gap: 0.7rem;
  padding: 0.3rem 0.4rem;
  border-radius: 8px;
}

.rules-row:nth-child(even):not(.rules-head) { background: rgba(139, 148, 158, 0.06); }

.rules-head {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding-bottom: 0.25rem;
}

.rules-row.is-skip .rules-criteria { opacity: 0.45; }
.rules-row.is-skip .rules-name .badge-gray { text-decoration: line-through; }

.rules-field { display: inline-flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }

.rules-mode .select { width: 100%; }

.settings-bulk-bar { align-items: center; }

.settings-bulk-bar .bulk-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.settings-groups-table .td-check { width: 2rem; text-align: center; vertical-align: middle; }

.settings-groups-table tr.is-stopped td { background: rgba(248, 81, 73, 0.05); }

.group-name-link { color: var(--text); text-decoration: none; border-bottom: 1px dashed var(--border-strong, #666); }
.group-name-link:hover { color: var(--accent, #58a6ff); }

.pending-link { text-decoration: none; color: var(--text); }
.pending-link:hover { color: var(--accent, #58a6ff); }

/* ─────────────── Загрузки: прогресс-бары ─────────────── */

.dl-group-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.4rem 0 0.8rem; }

.dl-bar {
  position: relative;
  height: 8px;
  min-width: 5rem;
  border-radius: 6px;
  background: rgba(139, 148, 158, 0.25);
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
}

.dl-bar-fill {
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, #2f81f7, #58a6ff);
  transition: width 0.6s ease;
}

html[data-theme="light"] .dl-bar-fill { background: linear-gradient(90deg, #1f6feb, #2a78d6); }

.dl-bar-text { margin-left: 0.45rem; font-size: 0.82rem; color: var(--text-muted); }

@media (max-width: 900px) {
  .rules-row { grid-template-columns: 1fr; gap: 0.3rem; }
  .rules-head { display: none; }
}

/* ─────────────── Галерея: теги ─────────────── */

/* вкладки галереи (Все файлы / Видео TG / Фото / Короткие) */
.gallery-tabs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.2rem;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 0.3rem 0.4rem;
  margin: 0 0 0.9rem;
}

.gallery-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.85rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.gallery-tab:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}

.gallery-tab.is-on {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(47, 129, 247, 0.25);
}

html[data-theme="light"] .gallery-tab.is-on { color: var(--accent); }

.gallery-tab-hint {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-dim);
}

@media (max-width: 720px) {
  .gallery-tab-hint { display: none; }
}

.gallery-tag-cloud {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  margin: 0 0 0.9rem;
}

.gallery-tag-cloud-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 0.55rem;
  font-size: 0.85rem;
}

.gallery-tag-cloud-head .td-muted { font-size: 0.78rem; }

.gallery-tag-cloud-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.gallery-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.22rem 0.6rem;
  border: 2px solid #111827;
  border-radius: 999px;
  background: hsl(var(--tag-h, 210), 78%, 58%);
  color: #111827;
  font-weight: 700;
  text-decoration: none;
  line-height: 1.35;
  box-shadow: 0 1px 3px rgba(0,0,0,.38);
  text-shadow: 0 1px 0 rgba(255,255,255,.24);
  transition: border-color 0.12s, background 0.12s, color 0.12s, filter 0.12s;
}

html[data-theme="light"] .gallery-tag-chip {
  background: hsl(var(--tag-h, 210), 82%, 62%);
  color: #0b1220;
  border-color: #111827;
}

.gallery-tag-chip span {
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: rgba(255,255,255,.4);
  border: 1px solid rgba(17,24,39,.55);
  color: inherit;
}

.gallery-tag-chip:hover {
  border-color: #020617;
  filter: saturate(1.2) brightness(1.04);
  text-decoration: none;
}

.gallery-tag-chip.is-on {
  border-color: #020617;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.52), 0 0 0 1px #020617;
}

/* кнопка # на карточке — над ♥ */
.gallery-tag-btn {
  position: absolute;
  right: 0.4rem;
  bottom: 2.55rem;
  z-index: 4;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(1, 4, 9, 0.62);
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.12s, transform 0.12s, background 0.12s;
}

.gallery-card:hover .gallery-tag-btn,
.gallery-card.has-tags .gallery-tag-btn,
.gallery-tag-btn:focus {
  opacity: 0.92;
}

.gallery-tag-btn:hover {
  transform: scale(1.08);
  background: rgba(1, 4, 9, 0.82);
  color: #fff;
}

@media (hover: none) {
  .gallery-tag-btn { opacity: 1; }
}

.gallery-grid.is-list .gallery-tag-btn,
html[data-gallery-view="list"] .gallery-grid .gallery-tag-btn {
  width: 24px;
  height: 24px;
  font-size: 0.8rem;
  right: 0.25rem;
  bottom: 1.95rem;
  opacity: 1;
}

/* мини-теги на карточке */
.gallery-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
  margin-top: 0.3rem;
}

.gallery-mini-tag {
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.4;
  padding: 0.08rem 0.45rem;
  border: 1.5px solid #111827;
  border-radius: 999px;
  background: hsl(var(--tag-h, 210), 78%, 58%);
  color: #111827;
  text-shadow: 0 1px 0 rgba(255,255,255,.24);
  white-space: nowrap;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

html[data-theme="light"] .gallery-mini-tag {
  background: hsl(var(--tag-h, 210), 82%, 62%);
  color: #0b1220;
  border-color: #111827;
}

.contact-preview { display:flex; align-items:center; gap:.8rem; margin:.5rem 0 1rem; }
.contact-avatar, .contact-avatar-sm { object-fit:cover; border-radius:50%; background:var(--bg-elevated); border:1px solid var(--border); display:inline-grid; place-items:center; }
.contact-avatar { width:72px; height:72px; font-size:1.5rem; }
.contact-avatar-sm { width:34px; height:34px; }
.contact-relation-row { display:grid; grid-template-columns:minmax(12rem,1fr) minmax(10rem,1fr) auto; gap:.5rem; margin-bottom:.5rem; }
.contact-media-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(110px,1fr)); gap:.6rem; margin-bottom:1rem; }
.contact-media-grid img, .contact-media-placeholder { width:100%; height:110px; object-fit:cover; border-radius:var(--radius); background:var(--bg-elevated); display:grid; place-items:center; }
.contacts-batch-toolbar { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:.75rem; margin:.75rem 0; }
.contacts-batch-toolbar .catalog-count { margin:0; }
.contacts-table input[type="checkbox"] { width:1rem; height:1rem; cursor:pointer; accent-color:var(--accent); }
@media (max-width:700px) { .contact-relation-row { grid-template-columns:1fr; } }

/* попап тегов */
.gallery-tag-pop {
  position: fixed;
  z-index: 450;
  width: 280px;
  max-width: calc(100vw - 1rem);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.6rem 0.7rem;
}

.gallery-tag-pop[hidden] { display: none; }

.gallery-tag-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

.gallery-tag-batch {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.gallery-tag-batch[hidden] { display: none; }

.gallery-tag-batch .btn.is-on {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

#gallery-tag-form {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

#gallery-tag-form .input {
  flex: 1;
  min-width: 0;
}

.gallery-tag-pop-list {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.gallery-tag-empty {
  font-size: 0.78rem;
  color: var(--text-dim);
  padding: 0.35rem 0.45rem;
}

.gallery-tag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.32rem 0.45rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
}

.gallery-tag-row:hover { background: var(--bg-hover); }

.gallery-tag-row .tag-row-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-tag-row.is-on { color: var(--accent); }

.gallery-tag-row.is-on .tag-row-name::before { content: "✓ "; }

.gallery-tag-row .cnt {
  flex: 0 0 auto;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.gallery-tag-row.is-on .cnt { color: var(--accent); }

/* теги в просмотрщике */
.gviewer-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
  width: 100%;
}

.gviewer-tags:empty { display: none; }

.gviewer-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.14rem 0.6rem;
  border: 2px solid #111827;
  border-radius: 999px;
  background: hsl(var(--tag-h, 210), 78%, 58%);
  color: #111827;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.35;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.38);
  text-shadow: 0 1px 0 rgba(255,255,255,.24);
}

html[data-theme="light"] .gviewer-tag {
  background: hsl(var(--tag-h, 210), 82%, 62%);
  color: #0b1220;
  border-color: #111827;
}

.gviewer-tag:hover {
  text-decoration: line-through;
  border-color: var(--red);
  color: var(--red);
  background: transparent;
}

.gviewer-tag.gviewer-tag-add {
  border-style: dashed;
  border-color: var(--border);
  background: transparent;
  color: var(--text-muted);
}

.gviewer-tag.gviewer-tag-add {
  border-style: dashed;
  border-color: var(--border);
  background: transparent;
  color: var(--text-muted);
}

.gviewer-tag.gviewer-tag-add:hover {
  text-decoration: none;
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ── палитра тегов: 20 оттенков, цвет стабилен по слагу (djb2, gallery_tags.py) ── */
.tagc-0 { --tag-h: 0; }
.tagc-1 { --tag-h: 18; }
.tagc-2 { --tag-h: 36; }
.tagc-3 { --tag-h: 54; }
.tagc-4 { --tag-h: 72; }
.tagc-5 { --tag-h: 90; }
.tagc-6 { --tag-h: 108; }
.tagc-7 { --tag-h: 126; }
.tagc-8 { --tag-h: 144; }
.tagc-9 { --tag-h: 162; }
.tagc-10 { --tag-h: 180; }
.tagc-11 { --tag-h: 198; }
.tagc-12 { --tag-h: 216; }
.tagc-13 { --tag-h: 234; }
.tagc-14 { --tag-h: 252; }
.tagc-15 { --tag-h: 270; }
.tagc-16 { --tag-h: 288; }
.tagc-17 { --tag-h: 306; }
.tagc-18 { --tag-h: 324; }
.tagc-19 { --tag-h: 342; }

/* точка цвета тега в списке попапа */
.tag-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: hsl(var(--tag-h, 210), 70%, 60%);
}

html[data-theme="light"] .tag-dot { background: hsl(var(--tag-h, 210), 65%, 45%); }

/* Спокойные унифицированные кнопки тегов галереи — метрики .btn.btn-primary.btn-sm. */
.gallery-tag-chip,
.gallery-mini-tag,
.gviewer-tag {
  box-sizing: border-box;
  width: 8.5rem;
  min-width: 8.5rem;
  max-width: 8.5rem;
  padding: 0.35rem 0.7rem;
  justify-content: center;
  gap: 0.4rem;
  cursor: pointer;
  border: 1px solid var(--tag-ui-border, #1f6feb);
  border-radius: var(--radius-sm);
  background: var(--tag-ui-bg, #1f6feb);
  color: #fff;
  box-shadow: none;
  text-shadow: none;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.2;
  transition: 0.15s ease;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

html[data-theme="light"] .gallery-tag-chip,
html[data-theme="light"] .gallery-mini-tag,
html[data-theme="light"] .gviewer-tag {
  border-color: var(--tag-ui-border, #0969da);
  background: var(--tag-ui-bg, #0969da);
  color: #fff;
}

.gallery-tag-chip:hover,
.gallery-mini-tag:hover,
.gviewer-tag:hover {
  border-color: var(--tag-ui-hover, #388bfd);
  background: var(--tag-ui-hover, #388bfd);
  color: #fff;
  filter: none;
  text-decoration: none;
}

.gallery-tag-chip.is-on,
.gallery-mini-tag.is-on,
.gviewer-tag.is-on {
  border-color: #fff;
  background: var(--tag-ui-hover, #388bfd);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.75);
}

.gallery-tag-chip span {
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: .8;
}

/* Шесть UI-палитр, стабильно распределённых по 20 цветовым классам тегов. */
.tagc-0, .tagc-6, .tagc-12, .tagc-18 {
  --tag-ui-bg: #b62324; --tag-ui-border: #b62324; --tag-ui-hover: #d03533;
}
.tagc-1, .tagc-7, .tagc-13, .tagc-19 {
  --tag-ui-bg: #9a6700; --tag-ui-border: #9a6700; --tag-ui-hover: #bc8500;
}
.tagc-2, .tagc-8, .tagc-14 {
  --tag-ui-bg: #238636; --tag-ui-border: #238636; --tag-ui-hover: #2ea043;
}
.tagc-3, .tagc-9, .tagc-15 {
  --tag-ui-bg: #087e8b; --tag-ui-border: #087e8b; --tag-ui-hover: #0a9aac;
}
.tagc-4, .tagc-10, .tagc-16 {
  --tag-ui-bg: #1f6feb; --tag-ui-border: #1f6feb; --tag-ui-hover: #388bfd;
}
.tagc-5, .tagc-11, .tagc-17 {
  --tag-ui-bg: #8250df; --tag-ui-border: #8250df; --tag-ui-hover: #a371f7;
}

.gviewer-tag.gviewer-tag-add {
  border-style: solid;
  border-color: var(--border);
  background: transparent;
  color: var(--text-muted);
}

.gviewer-tag.gviewer-tag-add:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
