:root {
  --mag-red: #E30613;
  --mag-red-hover: #c70511;
  --nav-blue: #1B2A4A;
  --nav-blue-light: #243656;
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --text: #1A202C;
  --text-muted: #64748B;
  --green: #16A34A;
  --green-bg: #DCFCE7;
  --amber: #D97706;
  --amber-bg: #FEF3C7;
  --red-bg: #FEE2E2;
  --sidebar-w: 260px;
  --topbar-h: 60px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 16px rgba(15, 23, 42, 0.04);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--nav-blue);
  color: #fff;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand .logo-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -.02em;
}

.logo-icon {
  width: 32px; height: 32px;
  background: var(--mag-red);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 16px;
}

.sidebar-brand small {
  display: block;
  margin-top: 6px;
  color: rgba(255,255,255,.55);
  font-size: 11px;
  font-weight: 400;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }

.nav-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.4);
  padding: 12px 12px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,.85);
  font-size: 13px;
  margin-bottom: 2px;
  transition: background .15s;
}

.nav-link:hover { background: var(--nav-blue-light); color: #fff; }

.nav-link.active {
  background: rgba(227, 6, 19, .18);
  color: #fff;
  font-weight: 600;
}

.nav-link.active::before {
  content: "";
  width: 3px;
  height: 18px;
  background: var(--mag-red);
  border-radius: 2px;
  margin-left: -4px;
  margin-right: 4px;
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
  color: rgba(255,255,255,.5);
}

.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -.02em;
  min-width: 180px;
}

.topbar-search {
  flex: 1;
  max-width: 360px;
}

.topbar-search input {
  width: 100%;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--bg);
}

.topbar-filters {
  display: flex;
  gap: 8px;
  align-items: center;
}

.topbar-filters select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
}

.partner-toggle {
  display: flex;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
  border: 1px solid var(--border);
}

.partner-toggle a {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.partner-toggle a.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.partner-toggle a.ers.active { border-left: 3px solid var(--mag-red); }
.partner-toggle a.intime.active { border-left: 3px solid var(--nav-blue); }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.logout-form {
  display: inline;
  margin: 0;
}

.logout-form button {
  cursor: pointer;
}

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--nav-blue);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
}

.content { padding: 24px; flex: 1; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.kpi-card .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.kpi-card .value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1.1;
}

.kpi-card .sub {
  font-size: 12px;
  margin-top: 6px;
  color: var(--text-muted);
}

.kpi-card.positive .value { color: var(--green); }
.kpi-card.accent .value { color: var(--mag-red); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-header h2 {
  font-size: 14px;
  font-weight: 600;
}

.panel-body { padding: 16px 18px; }
.panel-body.flush { padding: 0; }

.chart-wrap { height: 240px; position: relative; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:hover td { background: #FAFBFC; }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: var(--green-bg); color: var(--green); }
.badge-warning { background: var(--amber-bg); color: var(--amber); }
.badge-danger { background: var(--red-bg); color: var(--mag-red); }
.badge-neutral { background: var(--bg); color: var(--text-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  transition: all .15s;
}

.btn:hover { border-color: #CBD5E1; background: var(--bg); }

.btn-primary {
  background: var(--mag-red);
  border-color: var(--mag-red);
  color: #fff;
}

.btn-primary:hover {
  background: var(--mag-red-hover);
  border-color: var(--mag-red-hover);
}

.btn-sm { padding: 5px 10px; font-size: 12px; }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.filter-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-form input, .filter-form select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--nav-blue) 0%, #2D4A7A 100%);
}

.login-card {
  background: #fff;
  padding: 40px;
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

.login-card h1 {
  font-size: 22px;
  margin-bottom: 8px;
}

.login-card p { color: var(--text-muted); margin-bottom: 24px; font-size: 13px; }

.login-card label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.login-card input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}

.login-card button {
  width: 100%;
  padding: 12px;
  background: var(--mag-red);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.login-card button:hover { background: var(--mag-red-hover); }

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.delta-pos { color: var(--green); font-weight: 600; }
.delta-neg { color: var(--mag-red); font-weight: 600; }

.export-links { display: flex; gap: 8px; flex-wrap: wrap; }

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.compare-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.compare-card h3 {
  font-size: 16px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 3px solid var(--mag-red);
}

.compare-card.intime h3 { border-color: var(--nav-blue); }

.compare-card .metric-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.compare-card .metric-row:last-child { border: none; }

.compare-card .metric-row strong { font-size: 15px; }

/* Формы и карточка курьера */
.messages { margin-bottom: 16px; }
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 8px;
}
.alert-success { background: var(--green-bg); color: #166534; border: 1px solid #86EFAC; }
.alert-error, .alert-danger { background: var(--red-bg); color: #991B1B; border: 1px solid #FCA5A5; }
.alert-warning { background: var(--amber-bg); color: #92400E; border: 1px solid #FCD34D; }
.alert-info { background: #DBEAFE; color: #1E40AF; border: 1px solid #93C5FD; }

.inline-form { display: inline; margin: 0; }

.row-link { cursor: pointer; }
.row-link:hover td { background: #F8FAFC; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.detail-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 20px;
}

.detail-field dt {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-field dd {
  font-size: 14px;
  margin: 0;
}

.field-error-text { color: var(--mag-red); }

.courier-form .form-section {
  border: none;
  margin: 0 0 24px;
  padding: 0;
}

.courier-form legend {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  padding: 0;
  color: var(--nav-blue);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control, .courier-form select, .courier-form input[type="text"],
.courier-form input[type="tel"], .courier-form input[type="date"],
.courier-form textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}

.form-control:focus, .courier-form select:focus, .courier-form input:focus,
.courier-form textarea:focus {
  outline: none;
  border-color: var(--mag-red);
  box-shadow: 0 0 0 3px rgba(227, 6, 19, 0.1);
}

.field-error, .form-errors {
  color: var(--mag-red);
  font-size: 12px;
}

.form-errors {
  background: var(--red-bg);
  border: 1px solid #FCA5A5;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

.form-errors p { margin: 4px 0; }

.partner-radio ul, .radio-inline ul {
  list-style: none;
  display: flex;
  gap: 16px;
  padding: 0;
  margin: 0;
}

.partner-radio li, .radio-inline li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-actions {
  display: flex;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .detail-fields { grid-template-columns: 1fr; }
}
