/* ═══════════════════════════════════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════════════════════════════════ */
:root {
  --color-bg:        #f8f8f7;
  --color-surface:   #ffffff;
  --color-text:      #111111;
  --color-muted:     #6b6b6b;
  --color-border:    #e8e8e8;
  --color-sidebar:   #111111;
  --color-sidebar-t: #a8a8a8;
  --color-primary:   #111111;
  --color-primary-t: #ffffff;
  --color-danger:    #dc2626;
  --color-success:   #16a34a;
  --color-warn-bg:   #fffbeb;
  --color-warn-bdr:  #fde68a;
  --color-warn-t:    #92400e;

  --radius: 8px;
  --radius-sm: 5px;
  --sidebar-w: 220px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ─── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* Гарантируем что hidden всегда работает, даже если у элемента display: flex/grid */
[hidden] { display: none !important; }
body {
  font-family: var(--font);
  font-size: 14px;
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: inherit; }

/* ═══════════════════════════════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--color-sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 10;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  font-size: 15px;
  font-weight: 600;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar__nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--color-sidebar-t);
  transition: color .15s, background .15s;
  cursor: pointer;
}
.sidebar__link:hover,
.sidebar__link.active { color: #fff; background: rgba(255,255,255,.1); }

.sidebar__settings {
  padding: 8px;
  border-top: 1px solid rgba(255,255,255,.08);
}

/* ═══════════════════════════════════════════════════════════════════
   MAIN
═══════════════════════════════════════════════════════════════════ */
.admin-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 32px;
  max-width: 1100px;
}

/* ─── Settings panel ─────────────────────────────────────────────── */
.settings-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
}
.settings-panel__inner {
  padding: 24px;
}
.settings-panel__inner h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}
.settings-hint {
  font-size: 12px;
  color: var(--color-muted);
  margin-bottom: 20px;
}
.settings-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.connection-status {
  font-size: 13px;
}
.connection-status.ok  { color: var(--color-success); }
.connection-status.err { color: var(--color-danger); }

/* ─── Page header ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
}
.page-title    { font-size: 22px; font-weight: 700; }
.page-subtitle { font-size: 13px; color: var(--color-muted); margin-top: 2px; }

/* ─── Alert ──────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}
.alert.success { background: #f0fdf4; border: 1px solid #bbf7d0; color: var(--color-success); }
.alert.error   { background: #fef2f2; border: 1px solid #fecaca; color: var(--color-danger); }

/* ─── No config warning ──────────────────────────────────────────── */
.no-config-warn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  background: var(--color-warn-bg);
  border: 1px solid var(--color-warn-bdr);
  border-radius: var(--radius);
  color: var(--color-warn-t);
  font-size: 13px;
  margin-bottom: 20px;
}

/* ─── Table ──────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.products-table {
  width: 100%;
  border-collapse: collapse;
}
.products-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.products-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.products-table tbody tr:last-child td { border-bottom: none; }
.products-table tbody tr:hover { background: #fafafa; }

.col-img     { width: 52px; padding-right: 0 !important; }
.col-price   { white-space: nowrap; }
.col-actions { width: 100px; text-align: right; }

.table-loading {
  text-align: center;
  color: var(--color-muted);
  padding: 48px !important;
}

/* Product thumbnail */
.thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  background: #f0f0f0;
  display: block;
}
.thumb-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #ccc;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}
.badge-green { background: #f0fdf4; color: var(--color-success); }
.badge-red   { background: #fef2f2; color: var(--color-danger); }

/* Sizes list */
.sizes-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.size-chip {
  padding: 2px 6px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 11px;
  color: var(--color-muted);
}

/* Action buttons */
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.action-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-muted);
  transition: background .15s, color .15s;
}
.action-btn:hover         { background: #f0f0f0; color: var(--color-text); }
.action-btn.delete:hover  { background: #fef2f2; color: var(--color-danger); }

/* ═══════════════════════════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--color-primary); color: var(--color-primary-t); border: 1px solid transparent; }
.btn-primary:hover    { opacity: .85; }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }

.btn-outline { background: #fff; color: var(--color-text); border: 1px solid var(--color-border); }
.btn-outline:hover { border-color: #aaa; }

.btn-danger  { background: var(--color-danger); color: #fff; border: 1px solid transparent; }
.btn-danger:hover { opacity: .85; }

.btn-sm { height: 32px; padding: 0 12px; font-size: 12px; }

.link-btn {
  color: #2563eb;
  text-decoration: underline;
  font-size: inherit;
  cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════════
   FIELDS
═══════════════════════════════════════════════════════════════════ */
.field-row { display: flex; flex-direction: column; gap: 6px; }
.field-row--full { grid-column: 1 / -1; }

.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-muted);
}
.field-label .required { color: var(--color-danger); }
.field-hint {
  font-size: 11px;
  color: var(--color-muted);
  margin-top: 6px;
}

.field-input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
  background: #fff;
}
.field-input:focus   { border-color: #aaa; }
.field-input.invalid { border-color: var(--color-danger); }

.field-textarea { height: auto; padding: 10px 12px; resize: vertical; }

.reveal-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
}

/* ─── Checkbox ───────────────────────────────────────────────────── */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
}
.checkbox-label input[type=checkbox] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--color-primary);
}

/* ─── Size tags ──────────────────────────────────────────────────── */
.size-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.size-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px 3px 10px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-size: 12px;
  background: #fff;
}
.size-tag {
  cursor: pointer;
  user-select: none;
}
.size-tag button {
  display: flex;
  align-items: center;
  color: var(--color-muted);
  font-size: 14px;
  line-height: 1;
}
.size-tag button:hover { color: var(--color-danger); }
.size-tag--unavail {
  background: #fff5f5;
  border-color: #fca5a5;
  color: #e53e3e;
  text-decoration: line-through;
}

/* ─── Color tags ─────────────────────────────────────────────────── */
.color-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.color-picker {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: none;
}
.color-picker::-webkit-color-swatch-wrapper { padding: 3px; }
.color-picker::-webkit-color-swatch { border: none; border-radius: 3px; }

.color-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.color-tag {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-size: 12px;
  background: #fff;
}
.color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.1);
  flex-shrink: 0;
}
.color-tag button {
  color: var(--color-muted);
  font-size: 14px;
  line-height: 1;
}
.color-tag button:hover { color: var(--color-danger); }

/* ─── Image tags ─────────────────────────────────────────────────── */
.images-input-wrap { display: flex; flex-direction: column; gap: 10px; }

.image-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.image-tag {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: #f0f0f0;
  flex-shrink: 0;
}
.image-tag img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image-tag__remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: 13px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s;
}
.image-tag:hover .image-tag__remove { opacity: 1; }

.image-tag--broken img { display: none; }
.image-tag--broken::after {
  content: '?';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #ccc;
}

/* ═══════════════════════════════════════════════════════════════════
   MODALS
═══════════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal--sm { max-width: 360px; padding: 32px; text-align: center; }
.modal--sm .modal__title { margin-bottom: 10px; }
.modal--sm .modal__body  { color: var(--color-muted); font-size: 13px; margin-bottom: 24px; }

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.modal__title { font-size: 16px; font-weight: 600; }
.modal__close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.modal__close:hover { background: #f0f0f0; }

/* Product form */
.product-form { padding: 24px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .admin-main { margin-left: 0; padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .products-table th:nth-child(4),
  .products-table td:nth-child(4),
  .products-table th:nth-child(5),
  .products-table td:nth-child(5) { display: none; }
}
