:root {
  --blue: #006bff;
  --blue-700: #0057d9;
  --navy: #0b2e63;
  --ink: #17263a;
  --text: #26364a;
  --muted: #68788f;
  --line: #dbe5f0;
  --blue-50: #f0f7ff;
  --blue-100: #dcecff;
  --surface: #ffffff;
  --canvas: #f5f8fc;
  --success: #16a36a;
  --warning: #e49518;
  --danger: #d74343;
  --shadow: 0 16px 40px rgba(11, 46, 99, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 82px;
  display: grid;
  grid-template-columns: 260px 1fr auto;
  align-items: center;
  gap: 28px;
  padding: 0 30px;
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--line);
}

.brand {
  width: 175px;
  height: 66px;
  display: flex;
  overflow: hidden;
  align-items: center;
  text-decoration: none;
}

.brand img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.topbar-title { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-title span { color: var(--muted); font-size: .78rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.topbar-title strong { margin-top: 4px; color: var(--ink); font-size: 1.05rem; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }

.editable-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: #0b6d4a;
  background: #eaf9f2;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
}

.editable-badge span { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: var(--navy);
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.icon-button:hover { color: var(--blue); border-color: var(--blue); }
.icon-button svg, .button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app-shell { display: grid; grid-template-columns: 286px minmax(0, 1fr); min-height: calc(100vh - 82px); }

.sidebar {
  position: sticky;
  top: 82px;
  height: calc(100vh - 82px);
  display: flex;
  flex-direction: column;
  padding: 30px 20px 22px;
  color: white;
  background: var(--navy);
  overflow: auto;
}

.sidebar-heading { padding: 0 10px 18px; }
.sidebar-heading p { margin: 0 0 3px; color: #83b8ff; font-size: .75rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.sidebar-heading h2 { margin: 0; font-size: 1.18rem; }
.route-nav { display: grid; gap: 9px; }

.route-link {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 13px 12px;
  text-align: left;
  color: #dce9fb;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 14px;
}

.route-link:hover { background: rgba(255, 255, 255, .07); }
.route-link.active { color: white; background: var(--blue); border-color: var(--blue); box-shadow: 0 10px 24px rgba(0, 107, 255, .28); }
.route-number { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: rgba(255, 255, 255, .12); font-size: .76rem; font-weight: 800; }
.route-link.active .route-number { color: var(--blue); background: white; }
.route-name { display: flex; flex-direction: column; min-width: 0; }
.route-name strong { overflow: hidden; font-size: .88rem; text-overflow: ellipsis; white-space: nowrap; }
.route-name span { color: inherit; opacity: .7; font-size: .72rem; }
.route-arrow { font-size: 1.1rem; opacity: .75; }

.sidebar-note {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 24px;
  padding: 15px 16px;
  color: var(--navy);
  background: white;
  border-radius: 14px;
}

.sidebar-note span, .partner-brand span { font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; opacity: .6; }
.sidebar-note strong { color: var(--blue); font-size: .92rem; }
.partner-brand { margin-top: auto; padding: 24px 10px 0; }
.partner-brand img { width: 110px; margin-top: 8px; padding: 5px 8px; background: white; border-radius: 8px; }

.workspace { width: min(1440px, 100%); padding: 34px 38px 70px; }

.route-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.eyebrow { display: flex; align-items: center; gap: 8px; color: var(--blue); font-size: .75rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 5px var(--blue-100); }
.route-header h1 { margin: 8px 0 4px; color: var(--ink); font-size: clamp(2rem, 4vw, 3.2rem); line-height: 1.02; letter-spacing: -.045em; }
.route-header p { margin: 0; color: var(--muted); }
.toolbar { display: flex; gap: 10px; flex-shrink: 0; }
.button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 15px; border-radius: 12px; font-weight: 800; border: 1px solid transparent; }
.button-primary { color: white; background: var(--blue); }
.button-primary:hover { background: var(--blue-700); }
.button-secondary { color: var(--navy); background: white; border-color: var(--line); }
.button-secondary:hover { border-color: var(--blue); color: var(--blue); }

.edit-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0 0 18px;
  padding: 13px 16px;
  background: var(--blue-50);
  border: 1px solid #bad8ff;
  border-radius: 12px;
}

.edit-notice div { display: flex; align-items: baseline; gap: 10px; }
.edit-notice strong { color: var(--navy); }
.edit-notice span { color: var(--muted); font-size: .86rem; }
.text-button { padding: 5px; color: var(--blue); background: none; border: 0; font-size: .82rem; font-weight: 800; }

.summary-cards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.summary-card { min-height: 112px; padding: 17px 18px; background: white; border: 1px solid var(--line); border-radius: 16px; }
.summary-card.primary { color: white; background: var(--blue); border-color: var(--blue); }
.summary-card span { display: block; margin-bottom: 8px; color: var(--muted); font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.summary-card.primary span { color: rgba(255, 255, 255, .72); }
.summary-card strong { display: block; color: var(--ink); font-size: 1.05rem; line-height: 1.25; }
.summary-card.primary strong { color: white; }
.summary-card small { display: block; margin-top: 6px; color: var(--muted); font-size: .7rem; }
.summary-card.primary small { color: rgba(255, 255, 255, .72); }

.route-visual-card, .panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.route-visual-card { padding: 24px 26px 22px; }
.section-title-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; }
.section-index { color: var(--blue); font-size: .68rem; font-weight: 900; letter-spacing: .13em; }
.section-title-row h2, .panel-title h2 { margin: 3px 0 0; color: var(--ink); font-size: 1.15rem; }
.source-label { color: var(--muted); font-size: .74rem; }
.route-visual { display: flex; gap: 0; margin-top: 26px; padding: 5px 3px 14px; overflow-x: auto; scrollbar-width: thin; }
.visual-stop { position: relative; min-width: 132px; flex: 1 0 132px; padding-top: 22px; text-align: center; }
.visual-stop::before { content: ""; position: absolute; top: 7px; left: 0; right: 0; height: 3px; background: var(--blue-100); }
.visual-stop:first-child::before { left: 50%; }
.visual-stop:last-child::before { right: 50%; }
.visual-dot { position: absolute; top: 1px; left: 50%; z-index: 2; width: 15px; height: 15px; transform: translateX(-50%); border: 4px solid white; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 2px var(--blue); }
.visual-stop.endpoint .visual-dot { width: 19px; height: 19px; top: -1px; background: var(--navy); box-shadow: 0 0 0 2px var(--navy); }
.visual-stop strong { display: block; color: var(--ink); font-size: .78rem; line-height: 1.2; }
.visual-stop span { color: var(--muted); font-size: .66rem; }

.tabs-wrap { position: sticky; top: 81px; z-index: 20; margin-top: 20px; padding-top: 1px; background: var(--canvas); }
.tabs { display: flex; gap: 6px; padding: 5px; background: white; border: 1px solid var(--line); border-radius: 14px; overflow-x: auto; }
.tab { min-height: 40px; padding: 8px 15px; color: var(--muted); white-space: nowrap; background: transparent; border: 0; border-radius: 10px; font-size: .84rem; font-weight: 800; }
.tab:hover { color: var(--blue); background: var(--blue-50); }
.tab.active { color: white; background: var(--navy); }
.tab-content { margin-top: 14px; }
.panel { margin-bottom: 14px; padding: 22px 24px; box-shadow: none; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 17px; }
.panel-title p { margin: 3px 0 0; color: var(--muted); font-size: .78rem; }
.badge { display: inline-flex; align-items: center; padding: 5px 9px; color: var(--blue); background: var(--blue-50); border-radius: 999px; font-size: .68rem; font-weight: 800; }

.path-card { position: relative; margin-bottom: 12px; padding: 17px 18px 17px 50px; border: 1px solid var(--line); border-radius: 14px; }
.path-card:last-child { margin-bottom: 0; }
.path-icon { position: absolute; left: 17px; top: 16px; width: 22px; height: 22px; display: grid; place-items: center; color: white; background: var(--blue); border-radius: 7px; font-size: .72rem; font-weight: 900; }
.path-card.alternate .path-icon { background: var(--warning); }
.path-card.blocked .path-icon { background: var(--danger); }
.path-card span { display: block; color: var(--muted); font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.path-card p { margin: 5px 0 0; color: var(--ink); font-size: .9rem; }

.metric-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.metric { padding: 16px; background: var(--blue-50); border-radius: 14px; }
.metric span { display: block; color: var(--muted); font-size: .72rem; }
.metric strong { display: block; margin-top: 3px; color: var(--navy); font-size: 1.45rem; }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; }
table { width: 100%; border-collapse: collapse; font-size: .79rem; }
thead th { padding: 11px 12px; color: #4f6380; background: #f4f8fd; border-bottom: 1px solid var(--line); text-align: left; font-size: .68rem; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
tbody td { padding: 11px 12px; color: var(--text); border-bottom: 1px solid #eaf0f6; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcff; }
.km-cell { color: var(--blue); font-weight: 900; white-space: nowrap; }
.risk-pill { display: inline-flex; padding: 3px 7px; border-radius: 999px; font-size: .66rem; font-weight: 900; text-transform: uppercase; }
.risk-alto { color: #aa2525; background: #ffebeb; }
.risk-medio-alto { color: #9c6000; background: #fff2d7; }
.risk-medio { color: #755000; background: #fff8d8; }
.risk-bajo { color: #0b6d4a; background: #eaf9f2; }
.status-approved { color: #0b6d4a; font-weight: 800; }
.delete-row { width: 28px; height: 28px; display: grid; place-items: center; color: var(--danger); background: #fff2f2; border: 0; border-radius: 8px; }
.add-row { margin-top: 12px; padding: 8px 12px; color: var(--blue); background: var(--blue-50); border: 1px dashed #9fc8ff; border-radius: 10px; font-size: .76rem; font-weight: 800; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.three-col { display: grid; grid-template-columns: 1.15fr .85fr; gap: 14px; }
.recommendation-list { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; }
.recommendation-list li { display: flex; gap: 10px; padding: 11px 12px; color: var(--text); background: #f8fafc; border-radius: 10px; font-size: .84rem; }
.recommendation-list li::before { content: "✓"; color: var(--success); font-weight: 900; }
.emergency-list { display: grid; gap: 9px; }
.emergency-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; }
.emergency-item span { color: var(--muted); font-size: .76rem; }
.emergency-item strong { color: var(--navy); font-size: .82rem; }

.edit-field { width: 100%; min-width: 90px; padding: 8px 9px; color: var(--ink); background: white; border: 1px solid #8abfff; border-radius: 8px; outline: none; }
.edit-field:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,107,255,.12); }
textarea.edit-field { min-height: 82px; resize: vertical; line-height: 1.45; }
.summary-card .edit-field { font-weight: 700; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; max-width: 340px; padding: 12px 16px; color: white; background: var(--navy); border-radius: 12px; box-shadow: 0 14px 35px rgba(11,46,99,.22); opacity: 0; transform: translateY(16px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1120px) {
  .summary-cards { grid-template-columns: repeat(3, 1fr); }
  .app-shell { grid-template-columns: 250px minmax(0, 1fr); }
  .topbar { grid-template-columns: 220px 1fr auto; padding-inline: 22px; }
  .workspace { padding-inline: 26px; }
}

@media (max-width: 820px) {
  .topbar { position: static; height: 72px; grid-template-columns: 145px 1fr; padding: 0 16px; }
  .brand { width: 140px; height: 58px; }
  .topbar-title { display: none; }
  .topbar-actions { justify-content: flex-end; }
  .editable-badge { display: none; }
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; padding: 18px 16px; }
  .sidebar-heading { padding: 0 0 12px; }
  .route-nav { display: flex; overflow-x: auto; padding-bottom: 4px; }
  .route-link { min-width: 220px; }
  .sidebar-note, .partner-brand { display: none; }
  .workspace { padding: 24px 16px 50px; }
  .route-header { align-items: flex-start; flex-direction: column; }
  .toolbar { width: 100%; }
  .button { flex: 1; }
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .summary-card { min-height: 96px; }
  .tabs-wrap { top: 0; }
  .two-col, .three-col { grid-template-columns: 1fr; }
  .edit-notice, .edit-notice div { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 520px) {
  .route-header h1 { font-size: 2.15rem; }
  .toolbar { flex-direction: column-reverse; }
  .summary-cards { grid-template-columns: 1fr 1fr; }
  .summary-card:last-child { grid-column: 1 / -1; }
  .route-visual-card, .panel { padding: 19px 16px; }
  .section-title-row { align-items: flex-start; flex-direction: column; }
  .source-label { display: none; }
  .metric-row { grid-template-columns: 1fr; }
}

@media print {
  body { background: white; }
  .topbar { position: static; }
  .app-shell { display: block; }
  .sidebar, .toolbar, .tabs-wrap, .edit-notice, .add-row, .delete-row, .editable-badge, .icon-button { display: none !important; }
  .workspace { width: 100%; padding: 20px; }
  .route-visual-card, .panel { box-shadow: none; break-inside: avoid; }
  .tab-content { display: block; }
}
