:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1c2431;
  --muted: #6c7685;
  --border: #dbe1ea;
  --accent: #4361ee;
  --accent-contrast: #ffffff;
  --danger: #c62828;
  --success: #1b6b3b;
  --success-bg: rgba(34, 139, 84, 0.12);
  --warning: #a35a00;
  --warning-bg: rgba(212, 136, 6, 0.14);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10131a;
  --card: #171d27;
  --text: #ebf0f8;
  --muted: #93a0b4;
  --border: #2a3343;
  --accent: #5d7bff;
  --accent-contrast: #f4f7ff;
  --danger: #ff7f7f;
  --success: #7ddf9a;
  --success-bg: rgba(95, 212, 146, 0.14);
  --warning: #ffc46b;
  --warning-bg: rgba(255, 196, 107, 0.12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}
.brand h1 { margin: 0; font-size: 1.4rem; }
.brand p { margin: 0.2rem 0 0; color: var(--muted); }

.topbar-actions { display: flex; gap: 0.5rem; }
.form-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.form-actions .btn {
  flex: 1 1 190px;
}

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

.auth-card { max-width: 420px; margin: 2rem auto; }
.section { margin-bottom: 1rem; }
.section-head h2 { margin: 0 0 0.8rem; }
.section-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
}

.stack { display: grid; gap: 0.6rem; }
.field { display: grid; gap: 0.3rem; }
.filters {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) repeat(6, minmax(130px, 1fr)) auto;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: center;
}
.image-search-form {
  display: grid;
  grid-template-columns: minmax(240px, 2fr) minmax(140px, 180px) auto auto;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.65rem;
}
.image-search-form .btn {
  width: 100%;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.5rem;
  align-items: end;
  width: 100%;
}
.inline-form select, .inline-form input { min-width: 0; width: 100%; }
.inline-form .btn { width: 100%; min-width: 0; }
.sync-field {
  display: grid;
  gap: 0.3rem;
  min-width: 0;
}
.sync-field span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.2;
}
.inline-check {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  background: transparent;
}
.inline-check input {
  min-width: auto;
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border);
  border-radius: 5px;
  margin: 0;
  display: grid;
  place-content: center;
  background: transparent;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.inline-check input::before {
  content: "";
  width: 10px;
  height: 10px;
  transform: scale(0);
  transition: transform 0.12s ease;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  background: var(--accent-contrast);
}
.inline-check input:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.inline-check input:checked::before {
  transform: scale(1);
}
.inline-check span {
  line-height: 1.2;
}

input, select, textarea, button {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  background: transparent;
  color: var(--text);
}
textarea { resize: vertical; }

.btn {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
}
.btn-secondary {
  background: transparent;
  color: var(--text);
}

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.backups-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.backup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.35rem 0;
  border-top: 1px solid var(--border);
}

.backup-item:first-child {
  border-top: none;
  padding-top: 0;
}

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

.backup-download {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.75rem;
}

.resource-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: grid;
  grid-template-rows: 150px auto;
}
.resource-thumb {
  width: 100%;
  height: 150px;
  object-fit: cover;
  background: #d5dbe6;
}
.resource-body { padding: 0.6rem; display: grid; gap: 0.35rem; }
.resource-title {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.2;
  height: 2.4em;
  overflow: hidden;
}
.resource-meta { color: var(--muted); font-size: 0.82rem; }
.pill-row { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.pill {
  font-size: 0.78rem;
  border-radius: 999px;
  padding: 0.18rem 0.45rem;
  border: 1px solid var(--border);
}
.pill-type { background: rgba(67, 97, 238, 0.15); }
.pill-license { background: rgba(52, 168, 83, 0.15); }
.pill-license-premium { background: rgba(255, 214, 102, 0.45); border-color: #f4c95d; }
.pill-license-freemium { background: rgba(52, 168, 83, 0.15); }
.action-row { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.action-link {
  font-size: 0.82rem;
  border: 0;
  background: transparent;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.1rem 0;
}
.action-link:hover { opacity: 0.85; }
.license-action-group {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
}
.action-link-license-ok { color: #2d6a4f; }
.action-link-license-del { color: var(--danger); }
.action-link-license-miss { color: #b45309; }
.action-link-thumb-miss { color: #b91c1c; }
.action-row .action-link {
  flex: 0 1 auto;
}
.btn-license-ok { background: #b7efc5; color: #1b4332; border-color: #95d5b2; }
.btn-license-miss { background: #ffd6a5; color: #7f5539; border-color: #ffb4a2; }
.btn-thumb-miss { background: #ffd6d6; color: #7f1d1d; border-color: #fecaca; }

.pagination {
  margin-top: 0.75rem;
  display: flex;
  justify-content: center;
  gap: 0.65rem;
  align-items: center;
}

.list { margin-top: 0.6rem; display: grid; gap: 0.45rem; }
.list-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

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

/* Статус синхронизации под формой */
.sync-live-meta {
  margin: 0.65rem 0 0;
  font-size: 0.88rem;
  line-height: 1.45;
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
  border: 1px solid transparent;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}
.sync-live-meta.sync-live-meta--running {
  color: var(--accent);
  background: rgba(67, 97, 238, 0.08);
  border-color: rgba(67, 97, 238, 0.22);
  font-weight: 500;
}
body[data-theme="dark"] .sync-live-meta.sync-live-meta--running {
  background: rgba(93, 123, 255, 0.12);
  border-color: rgba(93, 123, 255, 0.28);
}
.sync-live-meta.sync-live-meta--success {
  color: var(--success);
  background: var(--success-bg);
  border-color: rgba(34, 139, 84, 0.35);
  font-weight: 600;
}
body[data-theme="dark"] .sync-live-meta.sync-live-meta--success {
  border-color: rgba(125, 223, 154, 0.35);
}
.sync-live-meta.sync-live-meta--failed {
  color: var(--danger);
  background: rgba(198, 40, 40, 0.08);
  border-color: rgba(198, 40, 40, 0.28);
  font-weight: 600;
}
body[data-theme="dark"] .sync-live-meta.sync-live-meta--failed {
  background: rgba(255, 127, 127, 0.1);
  border-color: rgba(255, 127, 127, 0.35);
}
.sync-live-meta.sync-live-meta--cancelled {
  color: var(--warning);
  background: var(--warning-bg);
  border-color: rgba(163, 90, 0, 0.28);
  font-weight: 500;
}
body[data-theme="dark"] .sync-live-meta.sync-live-meta--cancelled {
  border-color: rgba(255, 196, 107, 0.35);
}
.sync-live-meta.sync-live-meta--idle {
  color: var(--muted);
  font-weight: 400;
}
.sync-live-meta.sync-live-meta--admin {
  color: var(--muted);
  font-style: italic;
}
.error { color: var(--danger); }
.logbox {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
  min-height: 90px;
  background: transparent;
}

.hidden { display: none !important; }
dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  width: min(420px, 92vw);
  padding: 1rem;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}
.modal-title {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}
.modal-text {
  margin: 0 0 0.75rem;
  color: var(--muted);
}
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}
.modal-actions .btn,
.modal-footer .btn {
  width: 100%;
}
.modal-footer {
  margin-top: 0.65rem;
}

@media (max-width: 1000px) {
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .image-search-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-grid { grid-template-columns: 1fr; }
  .inline-form { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
}

@media (max-width: 760px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .filters { grid-template-columns: 1fr; }
  .image-search-form { grid-template-columns: 1fr; }
  .inline-form { grid-template-columns: 1fr; }
  .pagination {
    justify-content: space-between;
  }
  .modal-actions {
    grid-template-columns: 1fr;
  }
}
