/* FL Aggregator — тема */
:root, [data-theme="dark"] {
  --background: #09090b;
  --foreground: #fafafa;
  --card: #0f0f11;
  --sidebar-background: #111113;
  --sidebar-foreground: #a1a1aa;
  --sidebar-accent: #1c1c1f;
  --sidebar-border: #1e1e21;
  --sidebar-width: 260px;
  --sidebar-compact-width: 180px;
  --sidebar-collapsed-width: 56px;
  --primary: #fafafa;
  --accent: #27272a;
  --muted: #18181b;
  --muted-foreground: #a1a1aa;
  --border: #27272a;
  --ring: #d4d4d8;
  --success: #22c55e;
  --error: #ef4444;
  --highlight-border: #ffffff;
  --radius: 8px;
  --card-scale: 1;
  --ui-scale: 1;
}

[data-theme="light"] {
  --background: #ffffff;
  --foreground: #09090b;
  --card: #f4f4f5;
  --sidebar-background: #fafafa;
  --sidebar-foreground: #71717a;
  --sidebar-accent: #f0f0f1;
  --sidebar-border: #e4e4e7;
  --primary: #09090b;
  --accent: #f4f4f5;
  --muted: #f4f4f5;
  --muted-foreground: #71717a;
  --border: #e4e4e7;
  --ring: #a1a1aa;
  --highlight-border: #09090b;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--background);
  color: var(--foreground);
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-background);
  border: 1px solid var(--sidebar-border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 16px);
  overflow: hidden;
  position: relative;
  z-index: 20;
  margin: 8px 0 8px 8px;
}

.sidebar.animate { transition: width 0.2s ease, min-width 0.2s ease; }

.sidebar-resize {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 25;
}
.sidebar-resize:hover { background: rgba(255,255,255,0.05); }

/* Brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.brand-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
}

.burger-btn {
  background: none;
  border: none;
  color: var(--sidebar-foreground);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.burger-btn:hover { background: var(--sidebar-accent); color: var(--foreground); }
.burger-btn svg { width: 20px; height: 20px; }

.burger-float {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 30;
  background: var(--sidebar-background);
  border: 1px solid var(--sidebar-border);
  border-radius: 8px;
  padding: 6px;
  display: none;
}

/* Sidebar scroll */
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-foreground);
  margin-bottom: 4px;
  white-space: nowrap;
}

.sidebar-label { white-space: nowrap; overflow: hidden; }

/* ── Compact sidebar (180px) ─────────────────── */
.sidebar.compact {
  width: var(--sidebar-compact-width);
  min-width: var(--sidebar-compact-width);
}
.sidebar.compact .brand-text { display: none; }
/* Компактный режим: текстовые лейблы видны */
.sidebar.compact .list-item { padding: 8px; }
.sidebar.compact .view-toggle { flex-direction: column; }
.sidebar.compact .view-toggle button { font-size: 11px; padding: 4px 6px; }
.sidebar.compact .chips { flex-direction: column; }
.sidebar.compact .chip { font-size: 11px; padding: 3px 6px; text-align: center; }
.sidebar.compact .stats-row { flex-direction: column; }
.sidebar.compact .stat-chip { font-size: 11px; }
.sidebar.compact .sidebar-footer-text { display: none; }
.sidebar.compact .scale-label { display: none; }
.sidebar.compact .aggregated-section { display: none; }
.sidebar.compact .footer-icon-btn { width: 32px; height: 32px; }

/* ── Collapsed sidebar (56px) ────────────────── */
.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
  min-width: var(--sidebar-collapsed-width);
}
.sidebar.collapsed .brand-text { display: none; }
.sidebar.collapsed .sidebar-label,
.sidebar.collapsed .sidebar-section-title { display: none; }
.sidebar.collapsed .sidebar-scroll .sidebar-section:not(.sidebar-section-nav) { display: none; }
.sidebar.collapsed .list-name,
.sidebar.collapsed .list-count { display: none; }
.sidebar.collapsed .list-item { justify-content: center; padding: 8px; }
.sidebar.collapsed .burger-btn { margin: 0 auto; }
.sidebar.collapsed .sidebar-footer-text { display: none; }
.sidebar.collapsed .view-toggle,
.sidebar.collapsed .chips,
.sidebar.collapsed .checkbox-row,
.sidebar.collapsed .stats-row,
.sidebar.collapsed .scale-control,
.sidebar.collapsed .aggregated-section { display: none; }
.sidebar.collapsed .footer-icons-row { flex-direction: column; }

/* ── Hidden sidebar ──────────────────────────── */
.sidebar.hidden {
  width: 0;
  min-width: 0;
  border: none;
  overflow: hidden;
  margin: 0;
  padding: 0;
}
body.sidebar-hidden .burger-float { display: flex; }

/* Sidebar footer */
.sidebar-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

/* Footer icon buttons row */
.footer-icons-row {
  display: flex;
  gap: 4px;
}

.footer-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.footer-icon-btn:hover { background: var(--sidebar-accent); color: var(--foreground); }
.footer-icon-btn svg { width: 16px; height: 16px; }
.footer-icon-btn.active { background: var(--accent); color: var(--foreground); }

.footer-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--muted-foreground);
  text-decoration: none;
  font-size: 13px;
  transition: background 0.15s;
  background: none;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  white-space: nowrap;
}
.footer-btn:hover { background: var(--sidebar-accent); color: var(--foreground); }
.footer-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ── View toggle ─────────────────────────────── */
.view-toggle {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--accent);
  border-radius: var(--radius);
  padding: 3px;
}

.view-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted-foreground);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.view-toggle-btn:hover { background: var(--sidebar-accent); color: var(--foreground); }

.view-toggle button {
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 13px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
}

.view-toggle button.active {
  background: var(--sidebar-background);
  color: var(--foreground);
}

/* ── List items ──────────────────────────────── */
.list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 13px;
}

.list-item:hover { background: var(--sidebar-accent); }
.list-item.active { background: var(--sidebar-accent); }

.list-dot {
  display: none;
}

.list-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.list-count {
  font-size: 11px;
  color: var(--muted-foreground);
  background: var(--muted);
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
  margin-left: auto;
}

.list-count-edit {
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.list-count-edit:hover {
  background: var(--accent);
  color: var(--foreground);
}

/* Chips */
.chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.chip {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted-foreground);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.chip.active {
  background: var(--foreground);
  color: var(--background);
  border-color: var(--foreground);
}

/* Checkbox */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted-foreground);
  cursor: pointer;
  white-space: nowrap;
}

.checkbox-row input[type="checkbox"] {
  accent-color: var(--foreground);
}

/* Stats */
.stats-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.stat-chip {
  font-size: 12px;
  color: var(--muted-foreground);
  background: var(--muted);
  padding: 3px 8px;
  border-radius: 6px;
}

.stat-chip span {
  color: var(--foreground);
  font-weight: 600;
}

/* ── Scale controls ──────────────────────────── */
.scale-control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.scale-label {
  font-size: 11px;
  color: var(--muted-foreground);
  white-space: nowrap;
  min-width: 36px;
}

.scale-control input[type="range"] {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--accent);
  border-radius: 2px;
  outline: none;
}

.scale-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--foreground);
  cursor: pointer;
}

.scale-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted-foreground);
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  transition: background 0.15s;
}
.scale-btn:hover { background: var(--accent); color: var(--foreground); }

/* ── Main Content ────────────────────────────── */
.main {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  min-width: 0;
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.main-title {
  font-size: 14px;
  color: var(--muted-foreground);
}

/* Cards grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(300px * var(--card-scale)), 1fr));
  gap: 16px;
}

/* Columns */
.cards-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  align-items: start;
}

.column {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.column-header {
  font-size: 14px;
  font-weight: 600;
  padding: 8px 0;
  border-bottom: 2px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--background);
  z-index: 1;
}

.column-count {
  font-size: 12px;
  color: var(--muted-foreground);
  background: var(--muted);
  padding: 1px 6px;
  border-radius: 10px;
}

/* ── Order card ──────────────────────────────── */
.order-card {
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.2s, opacity 0.3s;
  position: relative;
}

.order-card.highlighted {
  border: 2px solid var(--highlight-border);
}

.order-card.dismissed {
  opacity: 0.4;
}

/* Dismiss (X) button */
.card-dismiss {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  z-index: 2;
}
.order-card:hover .card-dismiss { opacity: 1; }
.card-dismiss:hover { background: var(--accent); color: var(--error); }
.card-dismiss svg { width: 14px; height: 14px; }

.order-card .badges {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  overflow: hidden;
}

.order-card .badges .badge {
  white-space: nowrap;
  flex-shrink: 0;
}

.order-card .badges .badge:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.badge-type {
  background: var(--accent);
  color: var(--muted-foreground);
}

.badge-free, .badge-paid {
  background: rgba(161, 161, 170, 0.15);
  color: var(--muted-foreground);
}

.badge-sent {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.badge-error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

.order-card .title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.4;
}

.order-card .description {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--muted-foreground);
  font-size: 13px;
  line-height: 1.5;
}

.order-card .meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  color: var(--muted-foreground);
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.order-card .meta span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.order-card .actions {
  display: flex;
  gap: 6px;
  padding-top: 4px;
  flex-wrap: wrap;
}

.order-card .actions .btn {
  flex: 1;
  min-width: 0;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn {
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

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

.btn-primary {
  background: var(--foreground);
  color: var(--background);
  font-weight: 500;
}
.btn-primary:hover { opacity: 0.9; }

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Compact card (columns) */
.order-card.compact .description { display: none; }
.order-card.compact .title { -webkit-line-clamp: 1; font-size: 14px; }
.order-card.compact { padding: 12px; gap: 6px; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted-foreground);
}

/* ── Modal ───────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--sidebar-background);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal h3 { font-size: 16px; font-weight: 600; }

.modal .form-group { margin-bottom: 12px; }
.modal .form-group label {
  display: block;
  font-size: 12px;
  color: var(--muted-foreground);
  margin-bottom: 4px;
}

.modal input, .modal textarea, .modal select {
  width: 100%;
  padding: 8px 12px;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--foreground);
  font-size: 14px;
}

.modal textarea { resize: vertical; min-height: 80px; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.modal-section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.modal-section h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--success);
  color: #000;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 300;
}
.toast.show { opacity: 1; }

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--muted-foreground);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 3px; }

/* ── Mobile ──────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    z-index: 100;
    height: 100vh;
    width: 280px;
    min-width: 280px;
    margin: 0;
    border-radius: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .burger-float { display: flex !important; }
  .sidebar.mobile-open ~ .burger-float { display: none !important; }
  .sidebar-resize { display: none; }
}

/* Backdrop */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.sidebar-backdrop.visible { opacity: 1; pointer-events: all; }

/* (edit btn убран — редактирование через клик по цифре) */

/* ── Панель ответов (мессенджер) ───────────────── */
.responses-panel {
  position: fixed;
  top: 0; right: 0;
  width: 400px;
  height: 100vh;
  background: var(--sidebar-background);
  border-left: 1px solid var(--border);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.responses-panel.open { transform: translateX(0); }

.responses-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.responses-panel-header h3 { font-size: 15px; font-weight: 600; }

.responses-panel-body {
  flex: 1;
  overflow-y: auto;
}

.response-item { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.response-bubble {
  background: var(--accent);
  border-radius: 12px 12px 4px 12px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--foreground);
  max-height: 200px;
  overflow-y: auto;
}
.response-meta { font-size: 11px; color: var(--muted-foreground); margin-top: 6px; display: flex; gap: 8px; align-items: center; }
.response-link { font-size: 12px; color: var(--muted-foreground); text-decoration: underline; display: block; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.response-status { padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 600; }
.response-status.ok { background: rgba(34,197,94,0.15); color: var(--success); }
.response-status.error { background: rgba(239,68,68,0.15); color: var(--error); }
