:root {
  --bg: #0f1117;
  --bg-card: #181b24;
  --bg-elev: #1f2330;
  --border: #2a2f3d;
  --text: #e7e9ee;
  --text-dim: #9aa1b1;
  --accent: #7c5cff;
  --accent-2: #4d8bff;
  --grad: linear-gradient(135deg, #7c5cff, #4d8bff);
  --green: #35c86b;
  --red: #ff5c6a;
  --amber: #ffb020;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  background: var(--bg-elev);
  color: var(--text);
  transition: transform 0.05s, filter 0.15s, background 0.15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--grad); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-danger { background: rgba(255, 92, 106, 0.12); color: var(--red); }
.btn-sm { padding: 6px 10px; font-size: 13px; }

/* --- Экран входа --- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(124, 92, 255, 0.25), transparent), var(--bg);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-logo { font-size: 44px; text-align: center; }
.login-card h1 { margin: 0; text-align: center; font-size: 26px; }
.login-sub { margin: 0 0 8px; text-align: center; color: var(--text-dim); }
.login-card label, .modal-body label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}
.login-card input, .modal-body input, .modal-body textarea, .modal-body select {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.login-card input:focus, .modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus {
  border-color: var(--accent);
}
.login-error { color: var(--red); font-size: 13px; text-align: center; min-height: 18px; }

/* --- Каркас приложения --- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-size: 20px; font-weight: 700; padding: 4px 8px 16px; display: flex; align-items: center; gap: 8px; }
.brand-logo { font-size: 24px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
}
.nav-item:hover { background: var(--bg-elev); color: var(--text); }
.nav-item.active { background: var(--bg-elev); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.logout { background: transparent; border: 1px solid var(--border); color: var(--text-dim); padding: 10px; border-radius: 10px; }
.logout:hover { color: var(--red); border-color: var(--red); }

.content { flex: 1; padding: 28px 32px; overflow-x: hidden; max-width: 1200px; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.view-head h2 { margin: 0; font-size: 24px; }

/* --- Карточки статистики --- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-label { color: var(--text-dim); font-size: 13px; margin-bottom: 8px; }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-value.accent { background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.stat-sub { color: var(--text-dim); font-size: 12px; margin-top: 4px; }

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.panel h3 { margin: 0 0 14px; font-size: 17px; }

/* --- Таблицы --- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; font-size: 14px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-green { background: rgba(53, 200, 107, 0.15); color: var(--green); }
.badge-amber { background: rgba(255, 176, 32, 0.15); color: var(--amber); }
.badge-red { background: rgba(255, 92, 106, 0.15); color: var(--red); }
.badge-dim { background: var(--bg-elev); color: var(--text-dim); }

.btn-issue { background: rgba(53, 200, 107, 0.15); color: var(--green); }
.btn-issue:hover { background: var(--green); color: #fff; }
.prod-link { color: var(--text); font-weight: 700; cursor: pointer; border-bottom: 1px dashed var(--border); }
.prod-link:hover { color: var(--accent); border-color: var(--accent); }
.click-row { cursor: pointer; }
.click-row:hover td { background: var(--bg-elev); }

/* --- Страница товара --- */
.product-page { display: flex; gap: 24px; margin-bottom: 20px; flex-wrap: wrap; }
.pp-gallery { display: flex; flex-wrap: wrap; gap: 10px; align-content: flex-start; width: 320px; flex-shrink: 0; }
.pp-thumb { width: 150px; height: 150px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); cursor: pointer; transition: transform 0.1s; }
.pp-thumb:hover { transform: scale(1.02); }
.pp-thumb.cover { border-color: var(--accent); }
.pp-noimg { width: 320px; height: 200px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; font-size: 54px; background: var(--bg-card); border: 1px dashed var(--border); border-radius: 12px; }
.pp-info { flex: 1; min-width: 260px; }
.pp-info h2 { margin: 0 0 4px; font-size: 24px; }
.pp-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 14px; margin-top: 16px; }
.pp-stats > div { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.pp-stat { font-size: 20px; font-weight: 700; margin-top: 6px; }

/* --- Брони на странице товара --- */
.booking { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.booking:last-child { border-bottom: none; }
.booking-main { flex: 1; font-size: 14px; line-height: 1.5; }
.booking-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.booking-done { opacity: 0.55; }

/* --- Модалка выдачи --- */
.issue-prodname { font-size: 17px; font-weight: 700; padding: 4px 0; }
.issue-summary { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: 14px; line-height: 1.7; }

/* --- Превью в списке --- */
.thumb {
  width: 46px; height: 46px; border-radius: 9px; object-fit: cover;
  border: 1px solid var(--border); background: var(--bg-elev); display: inline-block; vertical-align: middle;
  cursor: pointer;
}
.thumb-empty { display: inline-flex; align-items: center; justify-content: center; font-size: 22px; cursor: default; }
.thumb-count {
  display: inline-block; margin-left: 4px; vertical-align: middle;
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 10px; padding: 1px 7px; font-size: 11px;
}

/* --- Галерея в форме товара --- */
.gallery { display: flex; flex-wrap: wrap; gap: 10px; }
.gitem { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.gitem img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-badge { position: absolute; left: 4px; top: 4px; background: var(--grad); color: #fff; font-size: 10px; padding: 2px 6px; border-radius: 8px; }
.gitem-actions { position: absolute; right: 4px; top: 4px; display: flex; gap: 4px; }
.gbtn { width: 22px; height: 22px; border: none; border-radius: 6px; background: rgba(0,0,0,0.55); color: #fff; font-size: 12px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.gbtn:hover { background: rgba(0,0,0,0.8); }
.gbtn-del:hover { background: var(--red); }
.gadd {
  width: 84px; height: 84px; border: 1.5px dashed var(--border); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 28px; color: var(--text-dim); cursor: pointer;
}
.gadd:hover { border-color: var(--accent); color: var(--accent); }

/* --- Лайтбокс --- */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 300; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 20px; }
.lightbox img { max-width: 90vw; max-height: 74vh; border-radius: 12px; object-fit: contain; }
.lightbox-thumbs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.lightbox-thumbs img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; opacity: 0.5; cursor: pointer; border: 2px solid transparent; }
.lightbox-thumbs img.active { opacity: 1; border-color: var(--accent); }
.lightbox-close { position: absolute; top: 18px; right: 22px; background: transparent; border: none; color: #fff; font-size: 28px; cursor: pointer; }

/* --- Каталог --- */
.cat-block { margin-bottom: 22px; }
.cat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cat-head .cat-title { font-size: 18px; font-weight: 700; }
.cat-head .cat-count { color: var(--text-dim); font-size: 14px; }
.cat-head .cat-actions { margin-left: auto; display: flex; gap: 6px; }
.prod-row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.muted-row { opacity: 0.5; }

.date-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.date-controls input { background: var(--bg-elev); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 7px 10px; }
.chip { background: var(--bg-elev); border: 1px solid var(--border); color: var(--text-dim); padding: 6px 12px; border-radius: 20px; font-size: 13px; }
.chip.active { background: var(--grad); color: #fff; border-color: transparent; }

/* --- График --- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.bar { width: 100%; max-width: 42px; background: var(--grad); border-radius: 6px 6px 0 0; min-height: 2px; transition: height 0.3s; }
.bar-label { font-size: 10px; color: var(--text-dim); white-space: nowrap; }
.empty { color: var(--text-dim); text-align: center; padding: 30px; }

/* --- Модалка --- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 18px;
  width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-close { background: transparent; border: none; color: var(--text-dim); font-size: 18px; }
.modal-body { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-body .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-body .switch-row { flex-direction: row; align-items: center; justify-content: space-between; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

/* Переключатель */
.switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { display: none; }
.switch .slider { position: absolute; inset: 0; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 26px; transition: 0.2s; }
.switch .slider::before { content: ""; position: absolute; width: 20px; height: 20px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: 0.2s; }
.switch input:checked + .slider { background: var(--grad); border-color: transparent; }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* Тост */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 12px; box-shadow: var(--shadow); z-index: 200; font-size: 14px;
}
.toast.err { border-color: var(--red); color: var(--red); }

@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav { flex-direction: row; flex: 1; }
  .brand { padding: 4px 8px; }
  .content { padding: 20px 16px; }
}
