:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --fg: #1c2430;
  --muted: #5c6b7a;
  --line: #d5dbe3;
  --accent: #1f6feb;
  --accent-fg: #fff;
  --danger: #b42318;
  --warn-bg: #fff8e6;
  --warn-fg: #7a5b00;
  --ok: #0f7b3a;
  --radius: 6px;
  --font: "Segoe UI", "Liberation Sans", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.45;
}

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

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--fg);
  text-decoration: none;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  font-size: 0.95rem;
}

.nav form { display: inline; margin: 0; }

.user-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.banner-vk {
  margin: 0;
  padding: 0.75rem 1.25rem;
  background: var(--warn-bg);
  color: var(--warn-fg);
  border-bottom: 1px solid #f0e0a8;
  font-size: 0.95rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(900px 420px at 10% -10%, #e8eef8, transparent),
    var(--bg);
}

.login-card {
  width: min(100%, 400px);
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.login-card .sub {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

label {
  display: block;
  font-size: 0.9rem;
  margin: 0.75rem 0 0.35rem;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  background: #fff;
  color: var(--fg);
}

button,
.btn {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-fg);
  font: inherit;
  cursor: pointer;
}

button.secondary,
.btn.secondary {
  background: #fff;
  color: var(--fg);
  border-color: var(--line);
}

button.linkish {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
}

.alert {
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.alert-error {
  background: #fef3f2;
  color: var(--danger);
  border: 1px solid #f5c2c0;
}

.muted { color: var(--muted); }

h1.page-title {
  margin: 0 0 0.75rem;
  font-size: 1.45rem;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  background: var(--surface);
}

table.data th,
table.data td {
  border: 1px solid var(--line);
  padding: 0.45rem 0.6rem;
  text-align: left;
  vertical-align: top;
}

table.data th { background: #eef2f6; }

@media (max-width: 720px) {
  .topbar { align-items: flex-start; }
  .wrap { padding: 0.75rem; }
  .media-grid { grid-template-columns: 1fr; }
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.toolbar .page-title { margin: 0; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: end;
  margin-bottom: 1rem;
}
.filters label { margin: 0; min-width: 10rem; flex: 1; }
.hint { margin: 0 0 0.75rem; font-size: 0.9rem; }

.row-problem { background: #fff6f0; }
.row-problem td:first-child { box-shadow: inset 3px 0 0 #d9480f; }

.badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.4rem;
  font-size: 0.75rem;
  background: #e7f0ff;
  color: #1f6feb;
  border-radius: 4px;
}
.badge-soft {
  background: #f0f3f7;
  color: #4a5568;
}
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
}
.greeting-popover {
  margin-top: 0.5rem;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  min-width: 16rem;
  max-width: 28rem;
}
.greeting-popover textarea {
  width: 100%;
  min-height: 7rem;
  margin-bottom: 0.4rem;
}
.audit-diff {
  font-size: 0.8rem;
  max-width: 28rem;
  word-break: break-word;
}
.audit-diff code { white-space: pre-wrap; }
.tags-cell code {
  display: inline-block;
  margin: 0.1rem 0.2rem 0.1rem 0;
  padding: 0.1rem 0.35rem;
  background: #f0f3f7;
  border-radius: 3px;
  font-size: 0.8rem;
}
.tag-off { opacity: 0.45; text-decoration: line-through; }
.tags-more { display: inline; }
.tags-more summary { cursor: pointer; color: var(--accent); }

.alert-ok {
  background: #eaf7ef;
  color: var(--ok);
  border: 1px solid #b7e0c2;
}

.form-narrow { max-width: 28rem; }
.form-grid label { margin-top: 0; }
.check { display: flex !important; align-items: center; gap: 0.4rem; margin: 0.75rem 0 !important; }
.check input { width: auto; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin: 0.25rem 0;
}
.inline-form input[type="text"],
.inline-form input[type="number"] { width: auto; min-width: 8rem; }
.add-tag { margin-top: 0.75rem; }

button.danger, .btn.danger {
  background: #fff;
  color: var(--danger);
  border-color: #f5c2c0;
}
button.danger:hover { background: #fef3f2; }

.upload-zone { margin-bottom: 1.25rem; }
.upload-zone .drop {
  display: block;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  background: #fafbfc;
  cursor: pointer;
  color: var(--muted);
}
.upload-zone .drop.dragover {
  border-color: var(--accent);
  background: #eef5ff;
  color: var(--fg);
}
.upload-zone .drop input[type="file"] {
  display: block;
  margin: 0.75rem auto 0;
  width: auto;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.media-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}
.media-preview {
  background: #111;
  aspect-ratio: 16 / 10;
  display: grid;
  place-items: center;
  position: relative;
}
.media-preview img,
.media-preview video {
  max-width: 100%;
  max-height: 220px;
  object-fit: contain;
}
.media-expand {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 4px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.media-expand:hover { background: rgba(0,0,0,0.75); }

.vk-thread { max-width: 28rem; margin: 1rem 0 2rem; }
.vk-msg { margin-bottom: 1.25rem; }
.vk-msg-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.vk-bubble {
  background: #e8f1ff;
  border-radius: 14px 14px 14px 4px;
  padding: 0.75rem 0.9rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.vk-text {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  line-height: 1.45;
}
.vk-media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.35rem;
}
.vk-media-thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: none;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: #111;
}
.vk-media-thumb img,
.vk-media-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.vk-media-badge {
  position: absolute;
  left: 0.35rem;
  bottom: 0.35rem;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
}
.vk-caption { margin: 0.5rem 0 0; font-size: 0.85rem; }

.media-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(10, 12, 16, 0.82);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.media-lightbox[hidden] { display: none !important; }
.media-lightbox-dialog {
  position: relative;
  max-width: min(96vw, 1100px);
  max-height: 92vh;
  background: #111;
  border-radius: 8px;
  padding: 0.5rem;
}
.media-lightbox-body {
  display: grid;
  place-items: center;
  max-height: 82vh;
}
.media-lightbox-body img,
.media-lightbox-body video {
  max-width: 94vw;
  max-height: 80vh;
  object-fit: contain;
}
.media-lightbox-close {
  position: absolute;
  top: -0.2rem;
  right: -0.2rem;
  width: 2.2rem;
  height: 2.2rem;
  border: none;
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
  z-index: 2;
}
.media-lightbox-caption {
  color: #ccc;
  text-align: center;
  margin: 0.4rem 0 0;
  font-size: 0.85rem;
}
body.lightbox-open { overflow: hidden; }
.pwd-visible {
  display: inline-block;
  margin-bottom: 0.35rem;
  padding: 0.15rem 0.4rem;
  background: #f4f6f8;
  border-radius: 3px;
  user-select: all;
}
.status-toggle {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.15rem 0.55rem;
  font-size: 0.85rem;
  cursor: pointer;
  background: #fff;
}
.status-toggle.is-on {
  background: #eaf7ef;
  border-color: #b7e0c2;
  color: var(--ok);
}
.status-toggle.is-off {
  background: #f4f4f5;
  color: var(--muted);
}
.status-toggle:disabled { opacity: 0.6; cursor: wait; }
.media-meta { padding: 0.75rem; font-size: 0.9rem; }
.media-meta strong { display: block; word-break: break-all; }
.att-status { margin: 0.5rem 0; padding-left: 1.1rem; font-size: 0.85rem; }
.st-not_uploaded { color: #9a6700; }
.st-ready { color: var(--ok); }
.st-failed { color: var(--danger); }
.st-uploading, .st-processing { color: var(--accent); }
.media-actions { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.5rem; }

.greeting-preview {
  white-space: pre-wrap;
  background: #f7f8fa;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.preview-list { margin: 0; padding-left: 1.25rem; }

h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
section.card { margin-bottom: 1rem; }
section.card + section.card { margin-top: 0; }

.page-lead { color: var(--muted); max-width: 52rem; margin: 0 0 1rem; }
.wrap-alert { margin: 0.5rem 1.25rem; }
.cabinet-bar {
  margin: 0;
  padding: 0.35rem 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  background: #eef2f6;
  border-bottom: 1px solid var(--line);
}
.role-pill {
  display: inline-block;
  margin-right: 0.35rem;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}
.role-admin { background: #1f6feb; color: #fff; }
.role-target { background: #0f7b3a; color: #fff; }
.inline-title { cursor: text; border-bottom: 1px dashed transparent; }
.inline-title:hover { border-bottom-color: var(--accent); }
.tags-wrap { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
.tag-chip {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  background: #f0f3f7;
  border-radius: 3px;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  cursor: text;
  max-width: 100%;
  word-break: break-all;
}
.tag-chip:hover { outline: 1px solid var(--accent); }
.tag-add-btn {
  margin: 0 !important;
  padding: 0.05rem 0.45rem !important;
  min-width: 1.6rem;
  border: 1px dashed var(--line) !important;
  background: #fff !important;
  color: var(--accent) !important;
  font-weight: 700;
  line-height: 1.4;
}
.tag-add-btn:hover { border-color: var(--accent) !important; background: #eef5ff !important; }
.inline-input {
  width: min(100%, 16rem) !important;
  margin: 0 !important;
  padding: 0.2rem 0.35rem !important;
  font: inherit;
}
.tag-input { width: min(100%, 14rem) !important; font-family: ui-monospace, monospace !important; font-size: 0.8rem !important; }

