/* ── Тема по умолчанию: тёмная («Мускул») ────────────────────────────────────
   Палитра задаётся RGB-каналами (--rgb-*): их использует и Tailwind
   (tailwind.config.js), и производные --color-*. Вторая тема переопределяет
   только переменные — разметка и сборка Tailwind общие для обоих сайтов. */
:root {
  /* Backgrounds — lighter, cool-neutral */
  --rgb-bg:             19 19 21;      /* #131315 */
  --rgb-surface:        29 29 35;      /* #1D1D23 */
  --rgb-surface-alt:    37 37 50;      /* #252532 */
  --rgb-border:         56 56 76;      /* #38384C */

  /* Accent — Scarlet Red */
  --rgb-accent:         217 53 53;     /* #D93535 */
  --rgb-accent-h:       232 72 72;     /* #E84848 */

  /* Semantic — красный/жёлтый/зелёный статусов одинаковы по смыслу в обеих темах */
  --rgb-success:        76 175 122;    /* #4CAF7A */
  --rgb-error:          204 34 34;     /* #CC2222 */
  --rgb-warning:        212 146 42;    /* #D4922A */
  --rgb-info:           91 142 224;    /* #5B8EE0 */

  /* Text */
  --rgb-text:           240 236 239;   /* #F0ECEF */
  --rgb-text-muted:     144 136 160;   /* #9088A0 */

  /* Chrome — непалитровые цвета (шапка, оверлеи, плейсхолдеры картинок) */
  --navbar-bg:          rgba(16, 16, 18, 0.95);
  --glass-bg:           rgba(20, 20, 26, 0.93);
  --overlay-bg:         rgba(0, 0, 0, 0.75);
  --chat-lock-overlay:  rgba(10, 14, 26, 0.78);
  --img-placeholder:    #1C2440;
  --shadow-fab:         0 2px 12px rgba(0, 0, 0, 0.5);
  --shadow-card-hover:  0 8px 24px rgb(var(--rgb-accent) / 0.08);
  --table-row-border:   rgba(58, 69, 96, 0.4);

  /* Typography */
  --font-heading:       'Outfit', system-ui, sans-serif;
  --font-body:          'Outfit', system-ui, sans-serif;
  --font-mono:          'JetBrains Mono', monospace;

  /* Radius */
  --radius-sm:          6px;
  --radius-md:          12px;
  --radius-full:        999px;

  /* Transitions */
  --transition-fast:    160ms ease;
  --transition-modal:   240ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Светлая тема («Фарма»): белый фон, синий акцент ────────────────────────── */
:root[data-theme="light"] {
  --rgb-bg:             255 255 255;   /* #FFFFFF */
  --rgb-surface:        251 252 254;   /* #FBFCFE */
  --rgb-surface-alt:    240 244 250;   /* #F0F4FA */
  --rgb-border:         216 224 236;   /* #D8E0EC */

  --rgb-accent:         30 111 216;    /* #1E6FD8 — синий */
  --rgb-accent-h:       21 93 186;     /* #155DBA — hover темнее на светлом фоне */

  --rgb-success:        22 138 80;     /* #168A50 */
  --rgb-error:          209 38 38;     /* #D12626 */
  --rgb-warning:        176 106 0;     /* #B06A00 */
  --rgb-info:           14 116 164;    /* #0E74A4 */

  --rgb-text:           24 34 51;      /* #182233 */
  --rgb-text-muted:     95 108 130;    /* #5F6C82 */

  --navbar-bg:          rgba(255, 255, 255, 0.92);
  --glass-bg:           rgba(255, 255, 255, 0.94);
  --overlay-bg:         rgba(15, 23, 42, 0.45);
  --chat-lock-overlay:  rgba(255, 255, 255, 0.80);
  --img-placeholder:    #E9EFF7;
  --shadow-fab:         0 2px 12px rgba(15, 23, 42, 0.18);
  --shadow-card-hover:  0 8px 24px rgb(var(--rgb-accent) / 0.10);
  --table-row-border:   rgba(216, 224, 236, 0.6);

  --font-heading:       'Manrope', system-ui, sans-serif;
  --font-body:          'Manrope', system-ui, sans-serif;
}

/* Производные от каналов цвета — общие для обеих тем */
:root {
  --color-bg:           rgb(var(--rgb-bg));
  --color-surface:      rgb(var(--rgb-surface));
  --color-surface-alt:  rgb(var(--rgb-surface-alt));
  --color-border:       rgb(var(--rgb-border));
  --color-accent:       rgb(var(--rgb-accent));
  --color-accent-hover: rgb(var(--rgb-accent-h));
  --color-accent-muted: rgb(var(--rgb-accent) / 0.13);
  --color-success:      rgb(var(--rgb-success));
  --color-error:        rgb(var(--rgb-error));
  --color-warning:      rgb(var(--rgb-warning));
  --color-info:         rgb(var(--rgb-info));
  --color-text:         rgb(var(--rgb-text));
  --color-text-muted:   rgb(var(--rgb-text-muted));
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  overflow-x: hidden;
}

/* Sticky footer layout — applied via .page-layout class on non-admin body */
body.page-layout {
  display: flex;
  flex-direction: column;
}
body.page-layout > main {
  flex: 1;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0;
}

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

/* Inline content links (without their own class) get a clear underline so
   they are visibly clickable. Bumped specificity to override Tailwind preflight,
   which resets <a> to `color: inherit; text-decoration: inherit`. */
a:not([class]) {
  color: var(--color-accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
a:not([class]):hover {
  color: var(--color-accent-hover);
  text-decoration-thickness: 2px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 24px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition-fast);
  letter-spacing: 0.01em;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--color-accent);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--color-accent-hover);
  color: #ffffff;
}

.btn-secondary {
  background: transparent;
  color: var(--color-accent);
  border: 1px solid var(--color-accent);
}
.btn-secondary:hover {
  background: var(--color-accent-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover { color: var(--color-text); border-color: rgb(var(--rgb-accent) / 0.35); }

.btn-danger {
  background: var(--color-error);
  color: #fff;
}
.btn-danger:hover { background: rgb(var(--rgb-error) / 0.85); }

.btn-sm { padding: 7px 16px; font-size: 0.8125rem; }

/* Quantity stepper (catalog card) */
.qty-stepper {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: stretch;
  width: 100%;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  overflow: hidden;
  font-family: var(--font-body);
}
.qty-stepper button {
  background: transparent;
  border: none;
  color: var(--color-text);
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.qty-stepper button:hover { background: rgb(var(--rgb-accent) / 0.15); color: var(--color-accent); }
.qty-stepper button:active { transform: scale(0.94); }
.qty-stepper span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
  border-left: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  min-width: 0;
}
.btn-lg { padding: 14px 32px; font-size: 1rem; }

/* ── Inputs ──────────────────────────────────────────────────────────────── */
.input {
  width: 100%;
  padding: 11px 14px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  transition: border-color var(--transition-fast);
  outline: none;
}
.input::placeholder { color: var(--color-text-muted); }
.input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-muted);
}
.input.error {
  border-color: var(--color-error);
}

label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}
.card:hover {
  border-color: rgb(var(--rgb-accent) / 0.40);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1.3;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.badge-accent  { background: var(--color-accent-muted); color: var(--color-accent); }
.badge-success { background: rgb(var(--rgb-success) / 0.13); color: var(--color-success); }
.badge-error   { background: rgb(var(--rgb-error) / 0.13);  color: var(--color-error); }
.badge-warning { background: rgb(var(--rgb-warning) / 0.15); color: var(--color-warning); }
.badge-info    { background: rgb(var(--rgb-info) / 0.13); color: var(--color-info); }
.badge-muted   { background: rgb(var(--rgb-text-muted) / 0.13); color: var(--color-text-muted); }

/* ── Skeleton ────────────────────────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
.skeleton {
  background: linear-gradient(90deg,
    var(--color-surface-alt) 25%,
    var(--color-border) 50%,
    var(--color-surface-alt) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
  border-radius: var(--radius-sm);
}

/* ── Glass ───────────────────────────────────────────────────────────────── */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--color-border);
}

/* ── Utilities ───────────────────────────────────────────────────────────── */
.text-muted   { color: var(--color-text-muted); }
.text-accent  { color: var(--color-accent); }
.text-success { color: var(--color-success); }
.text-error   { color: var(--color-error); }
.text-info    { color: var(--color-info); }
.mono         { font-family: var(--font-mono); }
.divider      { border: none; border-top: 1px solid var(--color-border); margin: 24px 0; }

/* ── Navbar ──────────────────────────────────────────────────────────────── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 62px;
  display: flex;
  align-items: center;
  padding: 0 40px;
  background: var(--navbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  gap: 32px;
}

.navbar-logo {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.navbar-logo em {
  font-style: normal;
  color: var(--color-accent);
}
.navbar-logo-img {
  height: 28px;
  width: auto;
  display: block;
  flex-shrink: 0;
}

.navbar-links {
  display: flex;
  gap: 28px;
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
}
.navbar-links a {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: color var(--transition-fast);
  position: relative;
  text-decoration: none;
}
.navbar-links a::after {
  content: '';
  position: absolute;
  bottom: -3px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--color-accent);
  transition: width var(--transition-fast);
  border-radius: 2px;
}
.navbar-links a:hover,
.navbar-links a.active {
  color: var(--color-text);
}
.navbar-links a:hover::after,
.navbar-links a.active::after {
  width: 100%;
}

.navbar-actions { display: flex; align-items: center; gap: 16px; margin-left: auto; }

/* ── Chat FABs ───────────────────────────────────────────────────────────── */
.chat-fabs {
  position: fixed;
  bottom: 28px;
  right: 12px;
  z-index: 200;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  align-items: flex-end;
}
.chat-fab {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-fab);
  position: relative;
}
.chat-fab:hover { transform: translateY(-2px); }
.chat-fab-public  { background: var(--color-surface-alt); color: var(--color-text-muted); border: 1px solid var(--color-border); }
.chat-fab-public:hover { color: var(--color-text); border-color: rgb(var(--rgb-accent) / 0.35); }
.chat-fab-support { background: var(--color-accent); color: #fff; }
.chat-fab-support:hover { background: var(--color-accent-hover); }

.chat-unread {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 17px;
  height: 17px;
  background: var(--color-warning);
  color: #fff;
  border-radius: var(--radius-full);
  font-size: 0.625rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* ── Chat Window ─────────────────────────────────────────────────────────── */
.chat-window {
  position: fixed;
  bottom: 92px;
  right: 80px;
  width: 420px;
  height: 560px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 199;
  transform-origin: bottom right;
  animation: chat-open var(--transition-modal) forwards;
  user-select: none;
}
@keyframes chat-open {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.chat-header {
  padding: 11px 16px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-border);
  cursor: grab;
}
.chat-header:active { cursor: grabbing; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  user-select: text;
}

.chat-msg-row {
  display: flex;
  gap: 7px;
  align-items: flex-end;
}
.chat-msg-row.own { flex-direction: row-reverse; }

.chat-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}
.chat-avatar img { width: 100%; height: 100%; display: block; }

.chat-msg-body { display: flex; flex-direction: column; max-width: 72%; }
.chat-msg-row.own .chat-msg-body { align-items: flex-end; }

.chat-author {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  margin-bottom: 2px;
  padding: 0 4px;
}

.chat-message {
  padding: 6px 11px;
  border-radius: 14px;
  font-size: 0.8125rem;
  line-height: 1.45;
  word-break: break-word;
}
.chat-message.own {
  background: var(--color-accent);
  color: #ffffff;
  border-bottom-right-radius: 3px;
}
.chat-message.other {
  color: var(--color-text);
  border-bottom-left-radius: 3px;
}

.chat-input-row {
  padding: 9px 12px;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 8px;
}
.chat-input-row .input { flex: 1; padding: 7px 11px; font-size: 0.8125rem; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal {
  width: min(480px, 95vw);
  border-radius: var(--radius-md);
  padding: 32px;
  animation: modal-open var(--transition-modal) forwards;
}
@keyframes modal-open {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Tree caret ──────────────────────────────────────────────────────────── */
.tree-caret {
  display: inline-block;
  transition: transform 0.22s ease;
}
.tree-caret.open {
  transform: rotate(90deg);
}

/* ── Catalog layout ──────────────────────────────────────────────────────── */
.catalog-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 28px;
  align-items: start;
}
.catalog-sidebar-card { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow-y: auto; }
.catalog-filter-toggle { display: none; }

@media (max-width: 900px) {
  .catalog-layout { grid-template-columns: 1fr; gap: 16px; }
  .catalog-filter-toggle { display: inline-flex; margin-bottom: 12px; }
  .catalog-sidebar { display: none; }
  .catalog-sidebar.is-open { display: block; }
  .catalog-sidebar-card { position: static; max-height: none; }
}

/* ── Mobile nav drawer ───────────────────────────────────────────────────── */
.navbar-burger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text);
  font-size: 1.4rem;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}
.navbar-burger:hover { background: var(--color-surface); }

.mobile-nav-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  z-index: 200;
}

.mobile-nav-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 85vw;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}
.mobile-nav-drawer.is-open { transform: translateX(0); }

.mobile-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px;
  border-bottom: 1px solid var(--color-border);
}
.mobile-nav-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  padding: 4px;
}
.mobile-nav-links, .mobile-nav-footer {
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
}
.mobile-nav-footer {
  border-top: 1px solid var(--color-border);
  margin-top: auto;
}
.mobile-nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.mobile-nav-link i { font-size: 1.2rem; }
.mobile-nav-link:hover, .mobile-nav-link.active {
  background: var(--color-bg);
  color: var(--color-text);
}
.mobile-nav-link.active { color: var(--color-accent); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .navbar { padding: 0 12px; gap: 12px; }
  .navbar-burger { display: flex; }
  .navbar-links { display: none; }
  .navbar-actions { gap: 8px; }
  /* Auth controls live in the burger drawer on mobile, keep only the cart here */
  .navbar-auth { display: none; }
  .chat-window {
    width: 100vw;
    /* Use the visualViewport height set by app.js so keyboard doesn't cover the input */
    height: var(--vv-height, 100dvh) !important;
    max-height: var(--vv-height, 100dvh) !important;
    top: var(--vv-top, 0) !important;
    left: 0 !important;
    right: 0 !important;
    /* Override inline bottom:156px on the support chat — on mobile both chats are fullscreen */
    bottom: auto !important;
    border-radius: 0;
    z-index: 300;
  }
  .chat-window .chat-header {
    cursor: default;
    /* Sticky so it stays visible even if VV shifts mid-animation */
    position: sticky;
    top: 0;
    background: var(--color-surface);
    z-index: 2;
  }
  .chat-window .chat-input-row {
    /* Respect iPhone home indicator */
    padding-bottom: max(9px, env(safe-area-inset-bottom));
  }
  .chat-fabs { z-index: 201; }

  .catalog-page { padding: 16px 12px 24px; }
  .catalog-page .card .product-image { height: 140px !important; }
  .catalog-page .card .p-4 { padding: 10px; }
  .catalog-page #product-grid { gap: 10px; }
  .catalog-topbar { flex-direction: column; align-items: stretch !important; gap: 10px; }
  .catalog-topbar-controls { display: flex; gap: 8px; width: 100%; }
  .catalog-topbar-controls .input { width: 100% !important; flex: 1; }
}
