:root {
  --kit-blue: #1a4a8e;
  --kit-blue-2: #2b63b8;
  --kit-red: #c8282a;
  --kit-green: #1d8f49;
  --kit-yellow: #f5d400;
  --bg: #eef1f5;
  --surface: #ffffff;
  --border: rgba(26, 74, 142, 0.14);
  --text: #101d33;
  --muted: rgba(16, 29, 51, 0.56);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Tahoma, Arial, sans-serif;
  background: linear-gradient(140deg, #eef1f5, #f7f3ea);
  color: var(--text);
  overflow: hidden;
}
button, input, select, textarea { font: inherit; }
button {
  border: 0;
  background: var(--kit-blue);
  color: white;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(26,74,142,.18);
}
button:hover { background: var(--kit-blue-2); }
button:disabled {
  opacity: .48;
  cursor: not-allowed;
  box-shadow: none;
}
button.ghost {
  background: #fff;
  color: var(--kit-blue);
  border: 1px solid var(--border);
  box-shadow: none;
}
button.danger { background: var(--kit-red); }
button.success { background: var(--kit-green); }
button.danger-outline {
  background: #fff;
  color: var(--kit-red);
  border: 1px solid rgba(200,40,42,.35);
  box-shadow: none;
}
button.small-btn { padding: 7px 10px; border-radius: 8px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 10px;
  outline: none;
  background: #fff;
}
textarea { resize: vertical; min-height: 74px; }
input:focus, select:focus, textarea:focus { box-shadow: 0 0 0 3px rgba(26,74,142,.12); }

.app {
  width: 100vw;
  max-width: none;
  min-height: 100vh;
  margin: 0;
  padding: 8px 10px;
}
.card {
  background: rgba(255,255,255,.96);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 12px 36px rgba(26,74,142,.1);
}
.hidden { display: none !important; }
.login-card { max-width: 440px; margin: 12vh auto 0; padding: 28px; }
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.brand.small { margin: 0; }
.logo {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  overflow: hidden;
  flex: 0 0 54px;
  background: var(--kit-blue);
  box-shadow: 0 6px 16px rgba(26, 74, 142, 0.18);
}

.logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
h1, h2, h3, p { margin: 0; }
h1 { color: var(--kit-blue); font-size: 22px; letter-spacing: .06em; }
h2 { color: var(--kit-blue); font-size: 18px; margin-bottom: 14px; }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--kit-blue); }
p { color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.45; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.form.compact { gap: 8px; margin: 10px 0 18px; }
.error { color: var(--kit-red); min-height: 18px; }
.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  height: calc(100vh - 16px);
  min-width: 0;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 12px;
  min-width: 0;
}
.stats { display: flex; gap: 12px; margin-left: auto; }
.stat {
  min-width: 90px; text-align: center; padding: 8px 10px;
  border-radius: 14px; border: 1px solid var(--border); background: #f9fbff;
}

.workspace-nav {
  display: flex;
  gap: 8px;
  align-items: center;
}

.workspace-nav button.active {
  background: var(--kit-blue);
  color: #fff;
  border-color: var(--kit-blue);
}

@media (max-width: 900px) {
  .workspace-nav {
    width: 100%;
    flex-wrap: wrap;
  }
}

.stat b { display: block; font-size: 20px; color: var(--kit-blue); }
.stat span { font-size: 10px; color: var(--muted); text-transform: uppercase; }
.grid {
  display: grid;
  grid-template-columns: 320px minmax(520px, 1fr) 430px;
  gap: 8px;
  align-items: start;
  min-width: 0;
  height: 100%;
}
.panel {
  padding: 10px;
  min-height: 220px;
}
.ers-panel,
.detail-panel {
  min-height: calc(100vh - 88px);
  max-height: calc(100vh - 88px);
  overflow-y: auto;
  overflow-x: hidden;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
  min-width: 0;
}

.ers-panel .panel-head h2 {
  display: none;
}

.ers-panel .panel-head {
  display: block;
}

.filters {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) 74px max-content;
  gap: 5px;
  align-items: center;
  min-width: 0;
}

.filters input,
.filters select {
  min-width: 0;
  height: 40px;
  padding-left: 9px;
  padding-right: 8px;
  font-size: 13px;
}

.filters select {
  padding-left: 10px;
  padding-right: 4px;
}

.check {
  white-space: nowrap;
  font-size: 10px;
  color: var(--muted);
  display: flex;
  gap: 4px;
  align-items: center;
}
.check input { width: auto; }
.list { display: grid; gap: 8px; margin-top: 12px; }
.item {
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 12px;
  background: #fff;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  color: var(--text);
  box-shadow: none;
}
button.item { width: 100%; }
.item.stop { background: rgba(200,40,42,.055); border-color: rgba(200,40,42,.24); }
.item.actual { background: rgba(29,143,73,.055); border-color: rgba(29,143,73,.24); }
.item.selected { outline: 3px solid rgba(26,74,142,.18); }
.item.blink { animation: blinkBorder 1s linear infinite; }
.item-title { font-weight: 800; color: var(--kit-blue); }
.item-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.badge { padding: 5px 9px; border-radius: 99px; color: #fff; font-size: 11px; font-weight: 800; white-space: nowrap; }
.badge.stop { background: var(--kit-red); }
.badge.actual { background: var(--kit-green); }
.small-list .item { grid-template-columns: 1fr; padding: 9px; }
summary { cursor: pointer; color: var(--kit-blue); font-weight: 800; }
.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 10;
  background: #101d33; color: #fff; padding: 12px 16px; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
  max-width: 520px;
}
.item-file {
  display: inline-flex;
  margin-top: 7px;
  padding: 4px 8px;
  border-radius: 99px;
  background: rgba(26,74,142,.08);
  color: var(--kit-blue);
  font-size: 11px;
  font-weight: 700;
}
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}
.detail-section {
  border-top: 1px solid rgba(26,74,142,.1);
  padding-top: 4px;
  margin-top: 14px;
}
.dopp-status-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-radius: 14px;
  margin: 12px 0;
}
.dopp-status-card.stop {
  background: rgba(200,40,42,.08);
  border: 1px solid rgba(200,40,42,.25);
  color: var(--kit-red);
}
.dopp-status-card.actual {
  background: rgba(29,143,73,.08);
  border: 1px solid rgba(29,143,73,.25);
  color: var(--kit-green);
}
.dopp-status-card span { color: var(--muted); font-size: 12px; }
.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.button-row.four { grid-template-columns: repeat(4, 1fr); }
.file-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: #f9fbff;
  margin-bottom: 10px;
}
.warning {
  color: var(--kit-red);
  background: rgba(200,40,42,.06);
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid rgba(200,40,42,.2);
}
.history-list { display: grid; gap: 8px; }
.history-item {
  border: 1px solid rgba(26,74,142,.1);
  border-radius: 12px;
  padding: 9px 10px;
  background: #fff;
}
.history-item b { color: var(--kit-blue); font-size: 12px; }
.history-item p { word-break: break-word; }
@keyframes blinkBorder {
  0%, 100% { box-shadow: 0 0 0 0 rgba(200,40,42,.2); }
  50% { box-shadow: 0 0 0 5px rgba(200,40,42,.16); }
}
@media (max-width: 1200px) {
  .grid { grid-template-columns: 1fr; }
  .ers-panel, .detail-panel { min-height: auto; max-height: none; }
}
@media (max-width: 900px) {
  .filters { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .stats { width: 100%; margin-left: 0; flex-wrap: wrap; }
  .button-row, .button-row.four { grid-template-columns: 1fr; }
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 30, 56, 0.45);
  backdrop-filter: blur(8px);
}

.modal-box {
  width: min(520px, 100%);
  background: #ffffff;
  border: 1px solid rgba(26, 74, 142, 0.14);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(15, 30, 56, 0.25);
  overflow: hidden;
  animation: modalIn 0.18s ease-out;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  background: linear-gradient(90deg, #f4f6fb, #f8f9fc);
  border-bottom: 1px solid rgba(26, 74, 142, 0.1);
}

.modal-head h3 {
  margin: 0 0 4px;
  color: #1a4a8e;
  font-size: 18px;
}

.modal-head p {
  margin: 0;
  color: rgba(15, 30, 56, 0.58);
  font-size: 12px;
  line-height: 1.45;
}

.modal-close {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border: 1px solid rgba(26, 74, 142, 0.12);
  border-radius: 10px;
  background: #ffffff;
  color: rgba(15, 30, 56, 0.58);
  cursor: pointer;
}

.modal-body {
  padding: 18px 20px;
}

.modal-body label {
  display: grid;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #0f1e38;
}

.modal-body textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
}

.modal-error {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: 10px;
  background: rgba(200, 40, 42, 0.09);
  border: 1px solid rgba(200, 40, 42, 0.22);
  color: #c8282a;
  font-size: 12px;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid rgba(26, 74, 142, 0.08);
  background: #fafbfc;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.kit-sync-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #f9fbff;
}

.kit-sync-card.ok {
  border-color: rgba(29, 143, 73, 0.25);
  background: rgba(29, 143, 73, 0.055);
}

.kit-sync-card.bad {
  border-color: rgba(200, 40, 42, 0.25);
  background: rgba(200, 40, 42, 0.055);
}

.kit-sync-card b {
  color: var(--kit-blue);
}

.kit-sync-error {
  color: var(--kit-red);
  word-break: break-word;
}

.kit-data-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.kit-data-grid div {
  border: 1px solid rgba(26, 74, 142, 0.1);
  border-radius: 12px;
  background: #fff;
  padding: 9px 10px;
}

.kit-data-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
}

.kit-data-grid b {
  color: var(--text);
  font-size: 12px;
  word-break: break-word;
}

@media (max-width: 900px) {
  .kit-sync-card {
    grid-template-columns: 1fr;
  }

  .kit-data-grid {
    grid-template-columns: 1fr;
  }
}
.button-row.three {
  grid-template-columns: repeat(3, 1fr);
}

.history-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.preview-modal-box {
  width: min(980px, calc(100vw - 32px));
  max-height: min(900px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
}

.preview-frame {
  width: 100%;
  height: min(68vh, 720px);
  border: 0;
  background: #f9fbff;
}

.preview-body.image {
  display: grid;
  place-items: center;
  min-height: 320px;
  max-height: min(68vh, 720px);
  overflow: auto;
  background: #f9fbff;
  padding: 14px;
}

.preview-body.image img {
  max-width: 100%;
  max-height: 68vh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(16, 29, 51, 0.12);
}

.preview-empty {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 320px;
  padding: 24px;
  text-align: center;
  background: #f9fbff;
}

.preview-empty b {
  color: var(--kit-blue);
}

.preview-empty p {
  max-width: 420px;
}
.logistics-workspace {
  padding: 16px;
  min-height: calc(100vh - 132px);
  max-height: calc(100vh - 132px);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 12px;
}

.logistics-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.logistics-head h2 {
  margin-bottom: 4px;
}

.logistics-toolbar {
  display: grid;
  grid-template-columns: 180px 160px minmax(220px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.logistics-create {
  border: 1px solid rgba(26, 74, 142, 0.12);
  border-radius: 14px;
  padding: 10px 12px;
  background: #f9fbff;
}

.logistics-create-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.logistics-create-form textarea {
  min-height: 42px;
}

.logistics-create-form button {
  min-height: 42px;
}

.logistics-table-wrap {
  overflow: auto;
  border: 1px solid rgba(26, 74, 142, 0.12);
  border-radius: 14px;
  background: #fff;
}

.logistics-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}

.logistics-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f4f6fb;
  color: var(--kit-blue);
  text-align: left;
  padding: 9px 8px;
  border-bottom: 1px solid rgba(26, 74, 142, 0.14);
  white-space: nowrap;
}

.logistics-table td {
  padding: 6px;
  border-bottom: 1px solid rgba(26, 74, 142, 0.08);
  vertical-align: top;
  min-width: 140px;
}

.logistics-table td:nth-child(10),
.logistics-table td:nth-child(11),
.logistics-table td:nth-child(15) {
  min-width: 220px;
}

.logistics-table input,
.logistics-table select,
.logistics-table textarea {
  min-width: 120px;
  font-size: 12px;
  padding: 7px 8px;
}

.logistics-table textarea {
  min-height: 46px;
}

.readonly-cell {
  padding: 8px;
  border-radius: 9px;
  background: #f6f8fc;
  color: var(--muted);
  min-height: 34px;
  white-space: nowrap;
}

.logistics-actions {
  display: grid;
  gap: 6px;
  min-width: 120px;
}

.empty-table {
  text-align: center;
  color: var(--muted);
  padding: 28px !important;
}

@media (max-width: 1200px) {
  .logistics-workspace {
    min-height: auto;
    max-height: none;
  }

  .logistics-toolbar {
    grid-template-columns: 1fr;
  }

  .logistics-create-form {
    grid-template-columns: 1fr;
  }
}
.logistics-workspace {
  width: 100%;
  min-height: calc(100vh - 88px);
  max-height: calc(100vh - 88px);
  padding: 10px;
  border-radius: 14px;
}

.logistics-table-wrap {
  min-height: 0;
  height: 100%;
}

.logistics-table {
  font-size: 11px;
}

.logistics-table th {
  padding: 7px 6px;
}

.logistics-table td {
  padding: 5px;
}

.logistics-toolbar {
  grid-template-columns: 150px 140px minmax(240px, 1fr) auto;
}

.logistics-create-form {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
}

@media (min-width: 1600px) {
  .grid {
    grid-template-columns: 330px minmax(640px, 1fr) 460px;
  }
}
.date-hint {
  position: relative;
  display: block;
  min-width: 0;
}

.date-hint input {
  height: 42px;
  padding-right: 132px;
}

.date-hint span {
  position: absolute;
  left: 112px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100% - 142px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.date-hint:focus-within span,
.date-hint.has-value span {
  display: none;
}

.logistics-table .date-hint input {
  height: 34px;
  min-width: 180px;
  padding-right: 98px;
}

.logistics-table .date-hint span {
  left: 104px;
  font-size: 10px;
  max-width: calc(100% - 112px);
}

.logistics-create-form .date-hint {
  min-width: 0;
}
.logistics-picker {
  display: grid;
  gap: 10px;
  padding: 11px;
  margin: 8px 0 12px;
  border: 1px solid rgba(26, 74, 142, 0.14);
  border-radius: 14px;
  background: #f9fbff;
}

.logistics-picker.empty {
  background: rgba(26, 74, 142, 0.035);
}

.logistics-picker b {
  color: var(--kit-blue);
  font-size: 13px;
}

.logistics-picker-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.logistics-picker-grid {
  display: grid;
  grid-template-columns: 1fr 1.8fr;
  gap: 8px;
  align-items: end;
}
.logistics-picker-grid-four {
  grid-template-columns: 1fr 1.2fr 1.8fr;
}
.logistics-picker-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.logistics-picker-grid button {
  min-height: 39px;
}

@media (max-width: 900px) {
  .logistics-picker-grid {
    grid-template-columns: 1fr;
  }
}
#driverDataForm input,
#driverDataForm textarea {
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
}

#driverDataForm textarea {
  line-height: 1.45;
}

#driverDataForm label {
  font-size: 12px;
}

.logistics-picker-grid select {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.linked-ers-btn {
  min-width: 140px;
  white-space: nowrap;
}

.linked-ers-modal-box {
  width: min(720px, calc(100vw - 32px));
}

.linked-ers-summary {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid rgba(26, 74, 142, 0.1);
  border-radius: 12px;
  background: #f9fbff;
}

.linked-ers-summary b {
  color: var(--kit-blue);
}

.linked-ers-list {
  min-height: 180px;
  max-height: 360px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid rgba(26, 74, 142, 0.14);
  border-radius: 12px;
  background: #ffffff;
  color: var(--text);
  font-family: Tahoma, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.logistics-table td:first-child,
.logistics-table th:first-child {
  min-width: 130px;
}

.logistics-table td:first-child select {
  min-width: 130px;
}
select[data-carrier-select] {
  min-width: 150px;
}
.button-row.single {
  grid-template-columns: 1fr;
}

.logistics-table .readonly-cell {
  min-width: 120px;
  text-align: center;
  font-weight: 700;
}

.logistics-table td:nth-child(3) .readonly-cell {
  color: var(--kit-blue);
  background: #f6f8fc;
}
.linked-ers-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 900px) {
  .linked-ers-columns {
    grid-template-columns: 1fr;
  }
}
[data-required-logistics="true"] {
  border-left: 3px solid rgba(26, 74, 142, 0.42);
}

.field-error input,
.field-error select,
.field-error textarea,
input.field-error,
select.field-error,
textarea.field-error {
  border-color: rgba(200, 40, 42, 0.85) !important;
  background: rgba(200, 40, 42, 0.055) !important;
  box-shadow: 0 0 0 3px rgba(200, 40, 42, 0.12) !important;
}

.date-hint.field-error span {
  color: var(--kit-red);
  font-weight: 700;
}

.logistics-create-form [data-required-logistics="true"]::placeholder,
.logistics-table [data-required-logistics="true"]::placeholder {
  color: rgba(16, 29, 51, 0.72);
}
.linked-ers-columns-four {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.linked-ers-columns-four .linked-ers-list {
  min-height: 220px;
  max-height: 420px;
}

@media (max-width: 1300px) {
  .linked-ers-columns-four {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}

@media (max-width: 900px) {
  .linked-ers-columns-four {
    grid-template-columns: 1fr;
  }
}

.api-workspace {
  padding: 16px;
  min-height: calc(100vh - 88px);
  max-height: calc(100vh - 88px);
  overflow: auto;
}

.api-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 14px;
}

.api-key-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.api-key-result {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(29, 143, 73, 0.25);
  border-radius: 14px;
  background: rgba(29, 143, 73, 0.055);
  margin-bottom: 14px;
}

.api-key-result b {
  color: var(--kit-green);
}

.api-key-result textarea {
  min-height: 82px;
  font-family: Consolas, monospace;
  font-size: 13px;
}

.api-keys-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.api-key-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
}

@media (max-width: 900px) {
  .api-key-form,
  .api-key-item {
    grid-template-columns: 1fr;
  }
}