/* =========================================================
   WorkQuest — единая адаптивная тема
   ========================================================= */

:root {
  --bg: #0F172A;
  --bg-soft: #0B1120;
  --surface: #1E293B;
  --surface-2: #172033;
  --surface-3: #0B1120;
  --border: #334155;
  --border-soft: #1f2a44;

  --primary: #8B5CF6;
  --primary-2: #7c3aed;
  --primary-soft: #c4b5fd;
  --primary-bg: rgba(139, 92, 246, 0.15);

  --accent: #F59E0B;
  --gold: #F59E0B;
  --gold-soft: #fcd34d;

  --success: #10B981;
  --success-soft: #6ee7b7;
  --danger: #EF4444;
  --danger-soft: #fca5a5;
  --warning: #F59E0B;
  --warning-soft: #fcd34d;

  --text: #f9fafb;
  --text-soft: #d1d5db;
  --text-muted: #94a3b8;
  --text-label: #a5b4fc;

  --radius-card: 12px;
  --radius-btn: 8px;
  --radius-modal: 16px;
  --radius-pill: 999px;

  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-pop:  0 12px 32px rgba(0, 0, 0, 0.45);

  --transition: 0.2s ease;

  --sidebar-w: 240px;
  --bottom-nav-h: 72px;
  --content-max: 1200px;

  --grad-primary: linear-gradient(135deg, #8B5CF6 0%, #F59E0B 100%);
  --grad-gold:    linear-gradient(135deg, #F59E0B 0%, #fbbf24 100%);
  --grad-bar:     linear-gradient(90deg, #8B5CF6 0%, #F59E0B 100%);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-soft); text-decoration: none; transition: color var(--transition); }
a:hover { color: #ddd6fe; text-decoration: none; }

h1 { margin: 0 0 8px; font-size: 26px; font-weight: 700; letter-spacing: -0.4px; }
h2 { margin: 0 0 16px; font-size: 20px; font-weight: 600; }
h3 { margin: 0 0 12px; font-size: 16px; font-weight: 600; color: var(--text-soft); }
.subtitle { margin: 0 0 22px; font-size: 14px; color: var(--text-muted); }

/* =========================================================
   Каркас: сайдбар + контент + нижняя навигация
   ========================================================= */

.app-shell {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 28px 32px;
  padding-left: calc(var(--sidebar-w) + 32px);
  padding-bottom: 32px;
  min-height: 100vh;
}
.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  z-index: 20;
}
.sidebar .brand { margin-bottom: 28px; padding: 0 8px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-btn);
  color: var(--text-soft);
  font-weight: 500;
  font-size: 14px;
  transition: background var(--transition), color var(--transition);
}
.sidebar-nav a .icon { font-size: 18px; width: 22px; text-align: center; }
.sidebar-nav a:hover { background: var(--primary-bg); color: var(--text); }
.sidebar-nav a.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-card); }
.sidebar-user {
  margin-top: auto;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  display: flex; align-items: center; gap: 12px;
}
.sidebar-user .avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--grad-primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; overflow: hidden; }
.sidebar-user-name { font-weight: 600; font-size: 14px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.sidebar-user-meta { font-size: 12px; color: var(--text-muted); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }

.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-inner { display: flex; height: var(--bottom-nav-h); }
.bottom-nav a, .bottom-nav button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  padding: 6px 4px;
  background: none; border: none;
  color: var(--text-muted);
  font-size: 11px; font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: color var(--transition);
  font-family: inherit;
  min-width: 0;
}
.bottom-nav a .icon, .bottom-nav button .icon { font-size: 22px; line-height: 1; }
.bottom-nav a.active, .bottom-nav button.active { color: var(--primary); }
.bottom-nav a:hover, .bottom-nav button:hover { color: var(--text); }
.bottom-nav a.active:hover, .bottom-nav button.active:hover { color: var(--primary); }

/* =========================================================
   Верхняя шапка контента
   ========================================================= */

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  margin-bottom: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--grad-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
  box-shadow: var(--shadow-card);
}
.app-header-right { display: flex; gap: 10px; align-items: center; }
.app-header-greet { color: var(--text-muted); font-size: 13px; }

/* =========================================================
   Кнопки
   ========================================================= */

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 18px; min-height: 44px;
  font-size: 14px; font-weight: 600;
  color: #fff; background: var(--primary);
  border: none; border-radius: var(--radius-btn);
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  transition: background var(--transition), transform var(--transition), opacity var(--transition), box-shadow var(--transition);
}
button:hover, .btn:hover { background: var(--primary-2); transform: translateY(-1px); box-shadow: var(--shadow-card); }
button:active, .btn:active { transform: translateY(0); }
button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

button.full, .btn.full { width: 100%; padding: 14px; min-height: 48px; margin-top: 18px; }

button.ghost, .btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-soft);
}
button.ghost:hover, .btn.ghost:hover { background: var(--bg-soft); color: var(--text); }
button.danger, .btn.danger { background: var(--accent); }
button.danger:hover { background: #d63a55; }
button.success, .btn.success { background: var(--success); }
button.success:hover { background: #15803d; }
button.small, .btn.small { padding: 8px 12px; min-height: 36px; font-size: 13px; }
button.gradient, .btn.gradient {
  background: var(--grad-primary);
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.35);
}
button.gradient:hover { box-shadow: 0 6px 18px rgba(139, 92, 246, 0.5); }

/* =========================================================
   Карточки и контейнеры
   ========================================================= */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 24px;
  box-shadow: var(--shadow-card);
}
.card-narrow { width: 100%; max-width: 420px; }

.row { display: flex; gap: 20px; flex-wrap: wrap; }
.col { flex: 1 1 320px; min-width: 0; }

/* =========================================================
   Поля ввода
   ========================================================= */

label {
  display: block;
  font-size: 11px;
  color: var(--text-label);
  margin: 16px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
}
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23a5b4fc' d='M0 0l6 8 6-8z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}

/* =========================================================
   Сообщения
   ========================================================= */

.message {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-btn);
  font-size: 14px;
  display: none;
}
.message.success { display: block; background: rgba(22,163,74,0.15); border: 1px solid rgba(22,163,74,0.4); color: var(--success-soft); }
.message.error   { display: block; background: rgba(233,69,96,0.15); border: 1px solid rgba(233,69,96,0.45); color: var(--danger-soft); }
.message.info    { display: block; background: var(--primary-bg); border: 1px solid rgba(139,92,246,0.4); color: var(--primary-soft); }

#toast {
  position: fixed !important;
  top: 20px; right: 20px;
  bottom: auto !important;
  left: auto;
  min-width: 240px; max-width: 360px;
  z-index: 100;
  margin: 0 !important;
  box-shadow: var(--shadow-pop);
  animation: slideInRight 0.25s ease-out;
}
@media (max-width: 767px) {
  #toast {
    top: 16px; right: 12px; left: 12px;
    min-width: 0; max-width: none;
  }
}

.helper { margin-top: 18px; text-align: center; font-size: 13px; color: var(--text-muted); }

/* =========================================================
   Статистика и счётчики
   ========================================================= */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition);
}
.stat:hover { transform: translateY(-2px); }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px; font-weight: 600; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Премиум-карточки баланса */
.balance-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.balance-card {
  border-radius: var(--radius-card);
  padding: 22px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  color: #fff;
  transition: transform var(--transition);
}
.balance-card:hover { transform: translateY(-2px); }
.balance-card.xp     { background: var(--grad-primary); }
.balance-card.coins  { background: var(--grad-gold); color: #1a1a2e; }
.balance-card.pending { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.balance-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; font-weight: 700; opacity: 0.85; }
.balance-value { font-size: 36px; font-weight: 800; margin-top: 6px; line-height: 1.1; }
.balance-sub { font-size: 12px; opacity: 0.85; margin-top: 6px; }

/* =========================================================
   Задания
   ========================================================= */

.task {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px;
  margin-bottom: 12px;
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition), border-color var(--transition);
}
.task:hover { transform: translateY(-1px); border-color: rgba(139,92,246,0.45); }
.task-info { flex: 1; min-width: 0; }
.task-title { font-weight: 600; font-size: 15px; }
.task-desc { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.task-meta { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

.chip {
  display: inline-flex; align-items: center;
  font-size: 11px; padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: var(--primary-bg);
  color: var(--primary-soft);
  text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600;
}
.chip.gold   { background: rgba(245,158,11,0.18); color: var(--gold-soft); }
.chip.green  { background: rgba(22,163,74,0.18); color: var(--success-soft); }
.chip.gray   { background: rgba(156,163,175,0.18); color: var(--text-soft); }
.chip.red    { background: rgba(233,69,96,0.18); color: var(--danger-soft); }
.chip.yellow { background: rgba(245,158,11,0.18); color: var(--gold-soft); }

.task-types, .nav-pills, .tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.task-types button, .tabs button {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-soft);
  padding: 8px 14px; font-size: 13px;
  border-radius: var(--radius-pill);
  min-height: 36px;
  font-weight: 500;
}
.task-types button:hover, .tabs button:hover { background: var(--primary-bg); color: var(--text); }
.task-types button.active, .tabs button.active {
  background: var(--primary); color: #fff; border-color: transparent;
  box-shadow: 0 4px 12px rgba(139,92,246,0.35);
}
.nav-pills .btn { padding: 8px 14px; min-height: 36px; font-size: 13px; }

/* =========================================================
   Таблицы
   ========================================================= */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
th, td {
  padding: 12px 14px; text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  background: var(--bg-soft); font-weight: 600; color: var(--text-label);
  text-transform: uppercase; font-size: 11px; letter-spacing: 0.6px;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(139,92,246,0.05); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.empty {
  padding: 32px 24px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-card);
}
.empty .empty-icon { font-size: 36px; margin-bottom: 8px; }

/* =========================================================
   Дашборд плана
   ========================================================= */

.plan-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  margin-bottom: 24px;
}
.plan-card {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  transition: transform var(--transition);
}
.plan-card:hover { transform: translateY(-2px); }
.plan-cat { font-size: 13px; color: var(--text-label); font-weight: 600; }
.plan-vals { display: flex; align-items: baseline; gap: 6px; margin-top: 6px; }
.plan-sold { font-size: 24px; font-weight: 700; }
.plan-target { font-size: 13px; color: var(--text-muted); }

.plan-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 12px;
  position: relative;
}
.plan-bar-fill {
  height: 100%;
  background: var(--grad-bar);
  transition: width 0.4s ease;
  width: 0%;
  border-radius: 4px;
}
.plan-bar-fill.done { background: var(--success); }
.plan-bar-fill.low  { background: var(--accent); }
.plan-bar-fill.mid  { background: var(--warning); }
.plan-bar-fill.high { background: var(--success); }
.plan-percent { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* =========================================================
   Сканер
   ========================================================= */

.scanner-stage {
  background: #000;
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  box-shadow: var(--shadow-card);
}
#reader { width: 100%; height: 100%; }
#reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
.scanner-frame {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.scanner-frame::before {
  content: "";
  width: 70%; max-width: 320px; aspect-ratio: 1.4 / 1;
  border: 3px solid rgba(255,255,255,0.85);
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.35);
}
.scanner-frame.scanning::after {
  content: "";
  position: absolute; left: 15%; right: 15%;
  height: 2px; background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  animation: scanLine 2.4s linear infinite;
  border-radius: 2px;
}
.scanner-actions {
  margin-top: 18px;
  display: flex; gap: 10px; justify-content: center;
}
.scanner-actions .btn { min-width: 200px; }

.scan-log { margin-top: 18px; max-height: 320px; overflow-y: auto; }
.scan-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 13px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px;
  animation: fadeIn 0.25s ease-out;
}
.scan-item code {
  background: var(--surface-3);
  padding: 3px 8px; border-radius: 6px;
  font-size: 12px; color: var(--primary-soft);
  font-family: ui-monospace, monospace;
}

/* =========================================================
   Модальные окна
   ========================================================= */

.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  animation: fadeIn 0.2s ease-out;
}
.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 24px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-pop);
  animation: scaleIn 0.22s ease-out;
}
@media (max-width: 767px) {
  .modal { align-items: flex-end; padding: 0; }
  .modal-content {
    max-width: none;
    border-radius: 20px 20px 0 0;
    animation: slideUp 0.25s ease-out;
    padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
  }
}

/* =========================================================
   Спиннер
   ========================================================= */

.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

/* =========================================================
   Анимации
   ========================================================= */

@keyframes fadeIn   { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp  { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes scaleIn  { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes slideInRight { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes spin     { to { transform: rotate(360deg); } }
@keyframes scanLine { 0% { top: 20%; } 50% { top: 78%; } 100% { top: 20%; } }

.fade-in { animation: fadeIn 0.25s ease-out; }
.slide-up { animation: slideUp 0.3s ease-out; }

/* =========================================================
   Адаптивность: десктоп → планшет → мобильный
   ========================================================= */

/* Planshet — узкий desktop */
@media (max-width: 1100px) {
  .app-shell { padding-right: 24px; }
}

/* Mobile */
@media (max-width: 767px) {
  body { font-size: 16px; }
  h1 { font-size: 22px; }
  h2 { font-size: 17px; }

  .app-shell {
    max-width: none;
    padding: 16px 12px calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 16px);
  }
  .center-screen { padding: 16px; }
  .card { padding: 18px; }

  .sidebar { display: none; }
  .bottom-nav { display: block; }

  .app-header { margin-bottom: 16px; gap: 8px; }
  .app-header-greet { display: none; }
  .brand { font-size: 16px; }
  .brand-logo { width: 36px; height: 36px; font-size: 18px; }

  .row { gap: 16px; }
  .col { flex: 1 1 100%; }

  .stat-row, .balance-row, .plan-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .stat-row.cols-2, .balance-row.cols-2 {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Задания: на мобильном ставим кнопку под текст */
  .task { flex-direction: column; align-items: stretch; }
  .task button { width: 100%; }

  /* Таблицы превращаются в стопку карточек */
  table, thead, tbody, tr, th, td { display: block; }
  table {
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
  }
  thead { display: none; }
  tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    margin-bottom: 12px;
    padding: 14px;
    box-shadow: var(--shadow-card);
  }
  tr:hover td { background: transparent; }
  td {
    padding: 6px 0;
    border: none;
    font-size: 14px;
  }
  td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    margin-bottom: 2px;
  }
  td .actions { margin-top: 4px; }

  /* Сканер компактнее */
  .scanner-stage { aspect-ratio: 3 / 4; max-width: none; }
  .scanner-actions .btn { width: 100%; min-width: 0; }
}

/* Сценарий «без сайдбара» — для авторизационных и admin-страниц */
.no-sidebar .app-shell {
  padding-left: 32px;
  padding-right: 32px;
}
@media (max-width: 767px) {
  .no-sidebar .app-shell { padding-left: 12px; padding-right: 12px; padding-bottom: 16px; }
}
