/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: #f4f6f8;
  color: #1a1a1a;
  min-height: 100vh;
}

/* ── Navigation ── */
header { background: #1e3a5f; color: #fff; }

.top-nav {
  display: flex;
  gap: 2px;
  padding: 0 16px;
}

.top-nav a {
  display: inline-block;
  padding: 14px 20px;
  color: #c5d8f0;
  text-decoration: none;
  font-weight: 500;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
}

.top-nav a:hover  { color: #fff; border-bottom-color: #5599cc; }
.top-nav a.active { color: #fff; border-bottom-color: #4fc3f7; }

/* ── Main layout ── */
main { padding: 20px 24px; max-width: 1400px; margin: 0 auto; }

/* ── Toolbar ── */
.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-toolbar h1 { font-size: 1.3rem; font-weight: 600; color: #1e3a5f; }

/* ── Buttons ── */
button {
  padding: 7px 16px;
  border: none;
  border-radius: 5px;
  background: #1e3a5f;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s;
}
button:hover { background: #2d5485; }
button.secondary { background: #5a7fa6; }
button.secondary:hover { background: #3f6185; }
button.danger { background: #c0392b; }
button.danger:hover { background: #962d22; }
button:disabled { background: #aaa; cursor: not-allowed; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}
thead { background: #1e3a5f; color: #fff; }
thead th { padding: 10px 14px; text-align: left; font-weight: 600; font-size: 13px; white-space: nowrap; }
tbody tr:nth-child(even) { background: #f9fbfd; }
tbody tr:hover { background: #eaf2fc; }
tbody td { padding: 9px 14px; border-bottom: 1px solid #e8edf2; }
tbody td.dash { color: #9aa8b5; text-align: center; }
tbody td a { color: #1565c0; text-decoration: none; font-weight: 500; }
tbody td a:hover { text-decoration: underline; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-overlay[hidden] { display: none; }

.modal-box {
  background: #fff;
  border-radius: 10px;
  padding: 28px 32px;
  min-width: 340px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal-box h2 { font-size: 1.1rem; margin-bottom: 18px; color: #1e3a5f; }

.modal-box label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
  font-size: 13px;
  color: #444;
  font-weight: 500;
}
.modal-box input, .modal-box select {
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 14px;
  width: 100%;
}
.modal-box input:focus, .modal-box select:focus {
  outline: 2px solid #4fc3f7;
  border-color: transparent;
}

.modal-footer { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; }

.error-msg { color: #c0392b; font-size: 13px; margin-top: 6px; min-height: 18px; }

/* ── Graph layout ── */
.graph-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  height: calc(100vh - 110px);
}

.graph-canvas-wrap {
  flex: 1;
  position: relative;
  background: #eef1f5;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
  overflow: hidden;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#graph-canvas {
  display: block;
  width: 100%;
  flex: 1;
  cursor: default;
}

.canvas-hint {
  font-size: 11px;
  color: #8a9ab0;
  padding: 4px 10px;
  text-align: center;
  background: #f8f9fa;
  border-top: 1px solid #e8edf2;
}

.graph-sidebar {
  width: 280px;
  flex-shrink: 0;
  overflow-y: auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.graph-sidebar section {
  background: #fff;
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.graph-sidebar h3 {
  font-size: 13px;
  font-weight: 600;
  color: #1e3a5f;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.graph-sidebar label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 8px;
  font-size: 12px;
  color: #555;
  font-weight: 500;
}

.graph-sidebar input,
.graph-sidebar select {
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  width: 100%;
}

.graph-sidebar input:focus,
.graph-sidebar select:focus { outline: 2px solid #4fc3f7; border-color: transparent; }

.item-list { display: flex; flex-direction: column; gap: 4px; }

.item-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 4px;
  background: #f4f6f8;
  font-size: 12px;
}
.item-row:hover { background: #e4edf6; }
.item-row span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row button {
  padding: 2px 7px;
  font-size: 11px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ── Settings ── */
.settings-wrap {
  max-width: 440px;
  background: #fff;
  border-radius: 10px;
  padding: 28px 32px;
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}
.settings-wrap h1 { font-size: 1.3rem; margin-bottom: 20px; color: #1e3a5f; }

.settings-wrap label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 500;
  color: #444;
}
.settings-wrap input, .settings-wrap select {
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 14px;
}
.settings-wrap button { margin-top: 8px; }
#s-msg { margin-top: 12px; color: #2e7d32; font-size: 13px; }

/* ── Waybill detail ── */
#waybill-detail h1 { font-size: 1.25rem; margin-bottom: 4px; color: #1e3a5f; }
#waybill-detail .wb-meta { color: #666; font-size: 13px; margin-bottom: 20px; }

.wb-section { margin-bottom: 24px; }
.wb-section h2 { font-size: 1rem; font-weight: 600; margin-bottom: 10px; color: #1e3a5f; }

#waybill-detail table {
  max-width: 900px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #1565c0;
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 16px;
}
.back-link:hover { text-decoration: underline; }

.wb-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ── Spinner ── */
.spinner {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.spinner[hidden] { display: none; }
.spinner::after {
  content: '';
  width: 44px; height: 44px;
  border: 4px solid #fff;
  border-top-color: #4fc3f7;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Misc ── */
.tag-city        { color: #1565c0; font-weight: 600; }
.tag-countryside { color: #2e7d32; font-weight: 600; }
