:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1d2521;
  --muted: #69736e;
  --line: #d9dfd6;
  --green: #2e6f57;
  --blue: #315f9f;
  --amber: #b57a20;
  --red: #a64242;
  --teal: #16817a;
  --shadow: 0 18px 42px rgba(29, 37, 33, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  padding: 0 14px;
  color: #fff;
  background: var(--green);
  cursor: pointer;
}

button svg {
  width: 17px;
  height: 17px;
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

button.active {
  outline: 3px solid rgba(181, 122, 32, 0.3);
  background: var(--amber);
}

.secondary-button {
  background: var(--blue);
}

.icon-button {
  width: 38px;
  padding: 0;
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 20px;
  background: #22302b;
  color: #fff;
  border-bottom: 1px solid #18221e;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 720;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: #c6d0c9;
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.api-key {
  display: grid;
  gap: 4px;
  color: #dfe7e2;
  font-size: 12px;
}

.api-key input {
  width: 170px;
  color: #fff;
  background: #2e3e38;
  border: 1px solid #4b5f56;
}

.app-shell {
  display: grid;
  grid-template-rows: minmax(430px, 1fr) minmax(320px, 38vh);
  gap: 12px;
  padding: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(292px, 340px) minmax(420px, 1fr) minmax(292px, 360px);
  gap: 12px;
  min-height: 0;
}

.search-panel,
.profile-panel,
.timeline-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.search-panel,
.profile-panel {
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

.panel-heading,
.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.demo-box {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
}

.demo-box label {
  margin-bottom: 0;
}

.demo-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.demo-box p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.pin-planner {
  display: grid;
  gap: 10px;
  margin: 12px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.pin-planner label {
  margin-bottom: 0;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 12px;
}

.checkbox-line input {
  width: 17px;
  min-height: 17px;
}

.pin-list {
  display: grid;
  gap: 7px;
}

.pin-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.pin-item strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
}

.pin-item button {
  width: 30px;
  min-height: 30px;
  padding: 0;
  background: #eef3ef;
  color: var(--ink);
}

.optimized-route-result {
  display: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.optimized-route-result.show {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.optimized-route-result.possible {
  border-color: rgba(46, 111, 87, 0.42);
  background: #f2f8f5;
}

.optimized-route-result.blocked {
  border-color: rgba(166, 66, 66, 0.36);
  background: #fff7f6;
}

.slot-results {
  display: grid;
  gap: 10px;
}

.feasibility-result {
  display: none;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.feasibility-result.show {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.feasibility-result.possible {
  border-color: rgba(46, 111, 87, 0.42);
  background: #f2f8f5;
}

.feasibility-result.blocked {
  border-color: rgba(166, 66, 66, 0.36);
  background: #fff7f6;
}

.feasibility-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 760;
}

.feasibility-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.feasibility-checks {
  display: grid;
  gap: 6px;
}

.feasibility-check {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.feasibility-check b {
  color: var(--ink);
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--red);
}

.status-dot.ok {
  background: var(--green);
}

.feasibility-actions {
  display: grid;
  grid-template-columns: 1fr;
}

.slot-card,
.profile-card,
.audit-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.slot-card {
  display: grid;
  gap: 8px;
}

.slot-card strong,
.profile-card strong {
  display: block;
  font-size: 14px;
}

.slot-meta,
.profile-meta,
.audit-item {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.slot-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.slot-actions button:last-child {
  background: var(--blue);
}

.map-zone {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #dde5dd;
  box-shadow: var(--shadow);
}

#map {
  position: absolute;
  inset: 0;
}

.map-controls {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 4;
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 24px rgba(29, 37, 33, 0.12);
}

.map-controls label {
  margin: 0;
}

.map-controls input[type="time"] {
  width: 112px;
}

.map-controls select {
  min-width: 132px;
}

.map-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 4;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  max-width: 340px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 24px rgba(29, 37, 33, 0.12);
  font-size: 11px;
}

.legend-line {
  display: inline-block;
  width: 28px;
  height: 4px;
  margin-right: 5px;
  border-radius: 99px;
  vertical-align: middle;
}

.legend-line.active-route {
  background: var(--green);
}

.legend-line.compare-route {
  background: var(--blue);
  opacity: 0.62;
}

.legend-dot.pending {
  background: #7d4ea2;
}

.legend-dot.custom {
  background: var(--red);
}

.legend-dot.booked {
  background: var(--amber);
}

.route-summary {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 4;
  max-width: min(420px, calc(100% - 24px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 24px rgba(29, 37, 33, 0.12);
}

.route-summary strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.route-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.28);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.marker.property {
  background: var(--amber);
}

.marker.pending {
  width: 18px;
  height: 18px;
  background: #7d4ea2;
}

.marker.custom {
  width: 20px;
  height: 20px;
  background: #a64242;
}

.marker.home {
  background: #1f6173;
}

.marker.hold {
  background: var(--blue);
}

.marker.inspector {
  background: var(--teal);
}

.marker-popup,
.map-click-menu {
  display: grid;
  gap: 7px;
  min-width: 190px;
  color: var(--ink);
  font-size: 12px;
}

.marker-popup span,
.map-click-menu span {
  color: var(--muted);
  line-height: 1.35;
}

.marker-popup button,
.map-click-menu button {
  min-height: 32px;
  width: 100%;
}

.inspector-profiles {
  display: grid;
  gap: 10px;
}

.profile-card {
  display: grid;
  gap: 8px;
}

.profile-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.meter {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #e8ece7;
}

.meter span {
  display: block;
  height: 100%;
  background: var(--green);
}

.audit-box {
  margin-top: 16px;
}

#auditLog {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.timeline-section {
  min-width: 0;
  overflow: hidden;
  padding: 12px;
}

.timeline-header {
  margin-bottom: 10px;
}

.timeline-context {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  border-radius: 50%;
}

.legend-dot.appt {
  background: var(--green);
}

.legend-dot.hold {
  background: var(--blue);
}

.legend-dot.drive {
  background: var(--amber);
}

.legend-dot.gap {
  background: #c8d0ca;
}

.timeline {
  height: calc(100% - 54px);
  overflow: auto;
}

.time-scale {
  display: grid;
  grid-template-columns: 176px minmax(860px, 1fr);
  gap: 12px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
}

.time-scale-track {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 0 4px;
}

.timeline-row {
  display: grid;
  grid-template-columns: 176px minmax(860px, 1fr);
  gap: 12px;
  min-height: 78px;
  padding: 8px 0;
  border-top: 1px solid #edf0ec;
}

.timeline-name {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  font-size: 13px;
  font-weight: 720;
}

.timeline-name button {
  align-self: flex-start;
  min-height: 28px;
  margin-top: 7px;
  padding: 0 9px;
  color: var(--ink);
  background: #e8efeb;
}

.timeline-name span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 550;
}

.timeline-track {
  position: relative;
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background:
    repeating-linear-gradient(
      to right,
      #fff 0,
      #fff calc(10% - 1px),
      #eef2ee calc(10% - 1px),
      #eef2ee 10%
    );
}

.timeline-block {
  position: absolute;
  top: 10px;
  height: 42px;
  overflow: hidden;
  border-radius: 6px;
  padding: 7px 8px;
  color: #fff;
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.timeline-block.appointment {
  background: var(--green);
  cursor: grab;
}

.timeline-block.hold {
  background: var(--blue);
}

.timeline-block.drive {
  top: 18px;
  height: 24px;
  background: var(--amber);
}

.timeline-block.buffer {
  top: 22px;
  height: 16px;
  background: #9aa59e;
}

.timeline-block.gap {
  top: 20px;
  height: 22px;
  color: #49534e;
  background: #dce2dc;
  cursor: pointer;
}

.timeline-block.gap:hover {
  outline: 2px solid rgba(46, 111, 87, 0.35);
  background: #cddbd1;
}

.timeline-block small {
  display: block;
  overflow: hidden;
  opacity: 0.85;
  text-overflow: ellipsis;
}

.empty-timeline {
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
}

.week-agenda {
  display: grid;
  gap: 12px;
  padding-right: 4px;
}

.agenda-day {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.agenda-day-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
}

.agenda-day-header strong {
  display: block;
  font-size: 14px;
}

.agenda-day-header span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.agenda-day-header button {
  min-height: 32px;
  padding: 0 10px;
  color: var(--ink);
  background: #e8efeb;
}

.agenda-items {
  display: grid;
  gap: 6px;
  padding: 10px 12px 12px;
}

.agenda-item {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 10px;
  align-items: stretch;
}

.agenda-time {
  padding-top: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.agenda-card {
  min-height: 42px;
  padding: 8px 10px;
  border-left: 4px solid #c8d0ca;
  border-radius: 7px;
  background: #fff;
}

.agenda-card strong {
  display: block;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agenda-card span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.agenda-item.appointment .agenda-card {
  border-left-color: var(--green);
}

.agenda-item.hold .agenda-card {
  border-left-color: var(--blue);
}

.agenda-item.drive .agenda-card {
  border-left-color: var(--amber);
}

.agenda-item.buffer .agenda-card {
  border-left-color: #9aa59e;
}

.agenda-item.gap .agenda-card {
  border-left-color: #c8d0ca;
  background: #f1f5f1;
}

.agenda-item.gap[data-clickable-gap="true"] {
  cursor: pointer;
}

.agenda-item.gap[data-clickable-gap="true"]:hover .agenda-card {
  outline: 2px solid rgba(46, 111, 87, 0.25);
  background: #e6f0e8;
}

.agenda-empty {
  padding: 10px;
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: 360px;
  transform: translateY(20px);
  opacity: 0;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #22302b;
  box-shadow: var(--shadow);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.booking-dialog {
  width: min(560px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  box-shadow: var(--shadow);
}

.booking-dialog::backdrop {
  background: rgba(29, 37, 33, 0.38);
}

.booking-dialog form {
  padding: 16px;
}

.dialog-heading,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.dialog-heading {
  margin-bottom: 14px;
}

.dialog-heading p,
.dialog-meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.dialog-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.dialog-actions {
  margin-top: 14px;
  justify-content: flex-end;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-rows: auto auto;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .map-zone {
    min-height: 520px;
  }

  .map-legend {
    max-width: calc(100% - 24px);
    bottom: 86px;
  }

  .topbar {
    height: auto;
    align-items: start;
    flex-direction: column;
    padding: 14px;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .api-key {
    flex: 1;
  }

  .api-key input {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .field-grid,
  .demo-actions,
  .dialog-grid,
  .slot-actions {
    grid-template-columns: 1fr;
  }

  .timeline-row {
    grid-template-columns: 132px minmax(660px, 1fr);
  }

  .time-scale {
    grid-template-columns: 132px minmax(660px, 1fr);
  }

  .map-controls {
    right: 12px;
  }

  .route-summary,
  .map-legend {
    left: 12px;
    right: 12px;
    max-width: none;
  }

  .agenda-day-header,
  .agenda-item {
    grid-template-columns: 1fr;
  }

  .agenda-item {
    gap: 4px;
  }
}
