/* Стили AdminCRM */

:root {
  --bg: #0f172a; --surface: #1e293b; --surface-2: #334155; --border: #475569;
  --text: #f8fafc; --muted: #94a3b8; --primary: #3b82f6; --primary-hover: #2563eb;
  --success: #22c55e; --danger: #ef4444; --radius: 6px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; min-height: 100vh; }
.d-none { display: none !important; }

/* Формы, инпуты и кнопки */
.dark-input, .dark-select {
  width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 8px 12px; font-size: 13px; outline: none; font-family: inherit;
}
.dark-input:focus, .dark-select:focus { border-color: var(--primary); }
.form-group { margin-bottom: 12px; }
.form-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.btn-primary, .btn-secondary, .btn-header, .btn-action {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: var(--radius); border: 1px solid transparent; font-size: 13px;
  cursor: pointer; padding: 8px 14px; font-family: inherit; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-header { background: var(--surface-2); border-color: var(--border); color: var(--muted); padding: 5px 10px; font-size: 12px; }
.btn-header:hover { color: var(--text); }
.btn-header.btn-danger-subtle:hover { color: var(--danger); border-color: var(--danger); }

/* Экран логина */
#login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; }
.login-title { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.login-subtitle { font-size: 13px; color: var(--muted); margin-bottom: 20px; }
.login-error-msg {
  background: rgba(239, 68, 68, 0.15); border: 1px solid var(--danger); color: var(--danger);
  padding: 8px 12px; border-radius: var(--radius); font-size: 12px; margin-bottom: 12px; display: flex; align-items: center; gap: 6px;
}

/* Сайдбар и макет */
#app-screen { min-height: 100vh; display: flex; }
.app-sidebar {
  width: 230px; min-width: 230px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 100;
}
.sidebar-header {
  height: 52px; padding: 0 16px; display: flex; align-items: center;
  border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13px;
}
.sidebar-content { flex: 1; padding: 10px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.tree-group { display: flex; flex-direction: column; gap: 2px; }
.tree-group-header {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: var(--radius);
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text); user-select: none;
}
.tree-group-header:hover { background: var(--surface-2); }
.group-icon { color: var(--primary); font-size: 14px; }
.group-chevron { margin-left: auto; font-size: 11px; color: var(--muted); transition: transform 0.15s; }
.tree-group:not(.open) .group-chevron { transform: rotate(-90deg); }
.tree-group:not(.open) .tree-children { display: none; }
.tree-children { display: flex; flex-direction: column; gap: 2px; padding-left: 14px; }
.nav-tree-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius);
  border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 13px;
  font-family: inherit; cursor: pointer; text-align: left; width: 100%;
}
.nav-tree-item:hover { background: var(--surface-2); color: var(--text); }
.nav-tree-item.active { background: var(--surface-2); border-color: var(--border); color: #fff; font-weight: 600; }
.app-main-layout { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }
.app-header {
  height: 52px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
}
.header-left, .header-right { display: flex; align-items: center; gap: 10px; }
.header-title { font-weight: 600; font-size: 15px; }
.header-breadcrumb { font-size: 12px; color: var(--muted); }
.app-container { max-width: 1200px; width: 100%; margin: 0 auto; padding: 16px 20px; flex: 1; }

/* Сводка, тулбар и фильтры */
.summary-bar { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.summary-stats { display: flex; gap: 16px; }
.summary-item strong { color: var(--text); }
.toolbar-card, .table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.table-card { padding: 0; overflow: hidden; }
.toolbar-row, .toolbar-actions, .toolbar-selectors { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-row { justify-content: space-between; gap: 10px; }
.selector-group { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.search-box-wrap { position: relative; flex: 1; min-width: 220px; max-width: 380px; }
.search-box-wrap i.bi-search { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 13px; padding: 7px 28px 7px 32px; outline: none; font-family: inherit;
}
.search-input:focus { border-color: var(--primary); }
.search-clear-btn { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--muted); cursor: pointer; display: none; }
.search-box-wrap.has-value .search-clear-btn { display: block; }
.filter-tabs { display: flex; gap: 4px; }
.filter-tab-btn {
  background: transparent; border: 1px solid transparent; color: var(--muted); padding: 5px 10px;
  border-radius: var(--radius); font-size: 12px; cursor: pointer; display: flex; align-items: center; gap: 6px; font-family: inherit;
}
.filter-tab-btn:hover { background: var(--surface-2); color: var(--text); }
.filter-tab-btn.active { background: var(--surface-2); border-color: var(--border); color: var(--text); font-weight: 600; }
.tab-badge { background: var(--surface); padding: 1px 6px; border-radius: 4px; font-size: 11px; }

/* Таблица данных */
.table-responsive { width: 100%; overflow-x: auto; }
.crm-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
.crm-table th { background: var(--surface-2); color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.crm-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.crm-table tbody tr:last-child td { border-bottom: none; }
.crm-table tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
.crm-table tr.row-deleted { opacity: 0.65; background: rgba(239, 68, 68, 0.04); }
.id-badge { font-family: monospace; color: var(--muted); font-size: 12px; }
.partner-name-cell { display: flex; flex-direction: column; gap: 2px; }
.partner-name { font-weight: 500; color: var(--text); }
.partner-deleted-note, .partner-meta { font-size: 11px; color: var(--danger); }
.status-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; white-space: nowrap; }
.status-tag.active { color: var(--success); }
.status-tag.deleted { color: var(--danger); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.date-text { color: var(--muted); font-size: 12px; white-space: nowrap; }
.date-sub { font-size: 11px; color: var(--muted); opacity: 0.8; display: block; }
.actions-cell { display: flex; gap: 4px; justify-content: flex-end; }
.btn-action { width: 28px; height: 28px; padding: 0; background: var(--surface-2); border-color: var(--border); color: var(--muted); }
.btn-action:hover { color: var(--text); background: var(--border); }
.btn-action.btn-action-delete:hover { color: var(--danger); border-color: var(--danger); }
.btn-action.btn-action-restore:hover { color: var(--success); border-color: var(--success); }
.table-state-box { padding: 40px 20px; text-align: center; color: var(--muted); }
.table-state-icon { font-size: 32px; margin-bottom: 8px; display: block; }
.table-state-title { font-size: 14px; color: var(--text); margin-bottom: 6px; font-weight: 500; }

/* Модальные окна */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  opacity: 0; pointer-events: none; transition: opacity 0.15s;
}
.modal-backdrop.show { opacity: 1; pointer-events: auto; }
.modal-dialog { width: 100%; max-width: 460px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.modal-header, .modal-footer { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-footer { border-bottom: none; border-top: 1px solid var(--border); justify-content: flex-end; gap: 8px; }
.modal-title { font-size: 14px; font-weight: 600; }
.modal-close-btn { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; }
.modal-close-btn:hover { color: var(--text); }
.modal-body { padding: 16px; }
.detail-grid { display: grid; gap: 8px; }
.detail-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; }
.detail-label { color: var(--muted); }
.detail-value { font-weight: 500; }
.json-viewer {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; font-family: monospace; font-size: 11px; color: var(--muted);
  max-height: 160px; overflow-y: auto; white-space: pre-wrap; word-break: break-all;
}

/* Тосты, спиннеры и адаптивность */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; font-size: 13px; display: flex; align-items: center; gap: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5); transition: opacity 0.2s, transform 0.2s;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-danger { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--primary); }
.toast-hiding { opacity: 0; transform: translateY(10px); }
.spinner {
  width: 14px; height: 14px; border: 2px solid rgba(255, 255, 255, 0.2); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 768px) {
  .app-container { padding: 12px; }
  .toolbar-row { flex-direction: column; align-items: stretch; }
  .search-box-wrap { max-width: 100%; }
  .toolbar-selectors { justify-content: space-between; }
}
