:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-main: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;

  --status-green: #10b981;
  --status-green-bg: #ecfdf5;
  --status-yellow: #f59e0b;
  --status-yellow-bg: #fffbeb;
  --status-orange: #f97316;
  --status-orange-bg: #fff7ed;
  --status-red: #ef4444;
  --status-red-bg: #fef2f2;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg-main); color: var(--text-main); min-height: 100vh; display: flex; flex-direction: column; }

.app-header { background: #0f172a; color: #fff; padding: 0.85rem 1.75rem; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; }
.brand-wrapper { display: flex; align-items: center; gap: 12px; }
.brand-icon { background: linear-gradient(135deg, #f59e0b, #ef4444); color: #fff; width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 1.25rem; }
.brand-text h1 { font-size: 1.2rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand-badge { font-size: 0.68rem; padding: 2px 6px; border-radius: 4px; font-weight: 500; }
.brand-sub { font-size: 0.76rem; color: #94a3b8; }

.header-actions { display: flex; align-items: center; gap: 12px; }
.user-profile-badge { display: flex; align-items: center; gap: 10px; background: rgba(255, 255, 255, 0.08); padding: 5px 12px; border-radius: 20px; border: 1px solid rgba(255, 255, 255, 0.15); cursor: pointer; transition: 0.2s; }
.user-profile-badge:hover { background: rgba(255, 255, 255, 0.15); }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: #3b82f6; color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; }
.company-tag { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.3); padding: 1px 7px; border-radius: 4px; font-weight: 600; font-size: 0.72rem; }
.btn-logout { background: rgba(239, 68, 68, 0.2); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); padding: 5px 10px; border-radius: 4px; font-size: 0.78rem; cursor: pointer; }

.nav-bar { background: var(--bg-surface); border-bottom: 1px solid var(--border-color); padding: 0 1.75rem; }
.nav-tabs { display: flex; gap: 4px; }
.nav-tab { padding: 1rem 1.25rem; font-size: 0.92rem; font-weight: 600; color: var(--text-muted); border: none; background: transparent; cursor: pointer; display: flex; align-items: center; gap: 8px; border-bottom: 3px solid transparent; }
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-badge { background: var(--bg-subtle); font-size: 0.72rem; padding: 2px 7px; border-radius: 12px; font-weight: 700; }
.nav-tab.active .tab-badge { background: #eff6ff; color: var(--primary); }

.app-container { max-width: 1540px; width: 100%; margin: 0 auto; padding: 1.5rem 1.75rem; flex: 1; }

/* Карточки дашборда */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 1.15rem 1.25rem; position: relative; cursor: pointer; transition: 0.15s; }
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
.stat-card.active-filter { box-shadow: 0 0 0 2px var(--primary); border-color: var(--primary) !important; background: #eff6ff; }
.stat-card::before { content: ""; position: absolute; top: 0; left: 0; bottom: 0; width: 4px; }
.stat-card.total::before { background: var(--primary); }
.stat-card.green::before { background: var(--status-green); }
.stat-card.yellow::before { background: var(--status-yellow); }
.stat-card.orange::before { background: var(--status-orange); }
.stat-card.red::before { background: var(--status-red); }
.stat-title { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-size: 1.85rem; font-weight: 800; line-height: 1; }
.stat-desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 6px; }

.toolbar { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 1rem; margin-bottom: 1.25rem; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.search-box { flex: 1; min-width: 280px; position: relative; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-input { width: 100%; padding: 0.65rem 1rem 0.65rem 2.4rem; border: 1px solid var(--border-color); border-radius: var(--radius-sm); font-size: 0.9rem; }
.filter-group { display: flex; gap: 6px; }
.filter-btn { padding: 0.55rem 0.9rem; border: 1px solid var(--border-color); background: var(--bg-surface); border-radius: var(--radius-sm); font-size: 0.84rem; cursor: pointer; }
.filter-btn.active { background: #0f172a; color: #fff; border-color: #0f172a; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0.62rem 1.15rem; font-size: 0.88rem; font-weight: 600; border-radius: var(--radius-sm); border: none; cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--bg-subtle); color: var(--text-main); border: 1px solid var(--border-color); }
.btn-sm { padding: 0.38rem 0.75rem; font-size: 0.8rem; }
.btn-danger { background: #fee2e2; color: #991b1b; }

.table-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); overflow: hidden; }
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; text-align: left; }
th { background: #f8fafc; color: var(--text-muted); font-weight: 700; padding: 0.85rem 1rem; border-bottom: 1px solid var(--border-color); font-size: 0.78rem; text-transform: uppercase; white-space: nowrap; }
th.sortable-th { cursor: pointer; user-select: none; }
th.sortable-th:hover { color: var(--primary); }
td { padding: 0.95rem 1rem; border-bottom: 1px solid var(--border-color); vertical-align: middle; }

/* Кликабельные строки таблиц */
.clickable-row {
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.clickable-row:hover {
  background-color: #f1f5f9 !important;
}

/* Ссылки между сущностями (Авто <-> СР <-> Маршрут) */
.entity-link {
  color: var(--primary);
  text-decoration: underline;
  font-weight: 700;
  cursor: pointer;
  display: inline-block;
}
.entity-link:hover {
  color: var(--primary-hover);
}

.status-badge { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 20px; font-size: 0.78rem; font-weight: 700; white-space: nowrap; }
.status-badge.active-green { background: var(--status-green-bg); color: #065f46; border: 1px solid #a7f3d0; }
.status-badge.warning-yellow { background: var(--status-yellow-bg); color: #92400e; border: 1px solid #fde68a; }
.status-badge.critical-orange { background: var(--status-orange-bg); color: #9a3412; border: 1px solid #fed7aa; }
.status-badge.danger-red { background: var(--status-red-bg); color: #991b1b; border: 1px solid #fecaca; }

.un-pill { display: inline-block; background: #f1f5f9; border: 1px solid #cbd5e1; color: #1e293b; font-weight: 700; font-size: 0.75rem; padding: 2px 7px; border-radius: 4px; margin: 1px; }
.un-pill.hcdg { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }

.route-badge { display: inline-flex; font-size: 0.74rem; font-weight: 700; padding: 1px 7px; border-radius: 4px; margin: 1px; }
.route-badge.badge-load { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.route-badge.badge-unload { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.route-copy-btn { background: transparent; border: 1px solid #cbd5e1; border-radius: 4px; padding: 2px 6px; font-size: 0.72rem; color: var(--text-muted); cursor: pointer; margin-top: 4px; }
.file-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--bg-subtle); border: 1px solid var(--border-color); padding: 3px 8px; border-radius: 4px; font-size: 0.78rem; color: var(--primary); text-decoration: none; margin: 2px; }

/* 1C Дата и Datepicker */
.date-1c-wrapper { position: relative; }
.date-input-group { display: flex; align-items: center; gap: 6px; position: relative; }
.date-input-group .form-input { flex: 1; }
.native-datepicker { width: 38px; height: 38px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); cursor: pointer; padding: 4px; background: #fff; }

.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; padding: 1.5rem; z-index: 1000; opacity: 0; visibility: hidden; transition: 0.2s; }
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal-card { background: var(--bg-surface); border-radius: var(--radius-lg); max-width: 650px; width: 100%; max-height: 90vh; overflow-y: auto; display: flex; flex-direction: column; }
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-close-btn { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 10px; background: #f8fafc; }

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-label { font-size: 0.84rem; font-weight: 600; color: #334155; }
.form-input, .form-select, .form-textarea { width: 100%; padding: 0.65rem; border: 1px solid var(--border-color); border-radius: var(--radius-sm); font-size: 0.9rem; font-family: inherit; }
.form-hint { font-size: 0.74rem; color: var(--text-muted); }

.tags-input-container { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); min-height: 42px; align-items: center; }
.tag-badge { background: #e0f2fe; border: 1px solid #bae6fd; color: #0369a1; padding: 2px 8px; border-radius: 4px; font-size: 0.8rem; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.tag-remove { cursor: pointer; font-weight: bold; }
.tags-raw-input { border: none; outline: none; flex: 1; min-width: 140px; font-size: 0.88rem; }

.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.calc-panel { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 1.5rem; }
.verdict-box { padding: 1.25rem; border-radius: var(--radius-md); margin-top: 1rem; }
.verdict-box.danger { background: var(--status-red-bg); border: 2px solid #fecaca; color: #7f1d1d; }
.verdict-box.success { background: var(--status-green-bg); border: 2px solid #a7f3d0; color: #064e3b; }
.verdict-box.warning { background: var(--status-yellow-bg); border: 2px solid #fde68a; color: #78350f; }

.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #0f172a; color: #fff; padding: 12px 18px; border-radius: var(--radius-sm); font-size: 0.88rem; display: flex; align-items: center; gap: 10px; }
.empty-state { text-align: center; padding: 3rem; color: var(--text-muted); }
.empty-icon { font-size: 2.5rem; margin-bottom: 8px; }

.autocomplete-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--border-color); border-radius: var(--radius-sm); max-height: 200px; overflow-y: auto; z-index: 50; }
.autocomplete-item { padding: 8px 12px; font-size: 0.84rem; cursor: pointer; border-bottom: 1px solid #f1f5f9; display: flex; justify-content: space-between; }
.autocomplete-item:hover { background: #eff6ff; }